Repository navigation
fix: resolve stylesheets' relative urls next to their real file - #8010
benedikt-bartscher wants to merge 34 commits into
Conversation
…cs route check passes
…cs route check passes
[Medium impact] The PR appears safe to merge; both numbered findings from the previous review are fixed. SummaryStylesheets now link to their real files so Vite can resolve nearby fonts and images. Page stylesheets also work in embedded apps.
Reviews (5) · Last reviewed commit: "Merge commit '64d81aba7f' into styleshee..." · Reviewed by Greptile |
Merging this PR will degrade performance by 6.19%2 warnings
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|
# Conflicts: # reflex/compiler/compiler.py
There was a problem hiding this comment.
All reported issues were addressed across 21 files
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
Stacked on #8007: this branch contains #8007's commits, the change itself is the last non-merge commit ("fix: resolve stylesheets' relative urls next to their real file").
Stylesheets from the assets directory are copied into
.web/stylesbefore the bundler sees them, so their relativeurl()s resolve against the copy:Vite looks for
.web/styles/external/site_package/fonts/x.woff2, finds nothing and leavesurl(../fonts/x.woff2)in the bundle, which the browser requests as/fonts/x.woff2and gets a 404. A shared asset links only the stylesheet, so its fonts and images never reach the assets directory. Plain stylesheets inassets/are affected the same way: their relative URLs survive the build unresolved and only happen to work when the stylesheet's depth inassets/matches the bundle's.With this PR the styles directory links each stylesheet to its real file (the target of a shared asset's link) instead of copying it. Vite resolves the link, so relative URLs resolve next to the real file and the build bundles and fingerprints what they name:
This covers
App(stylesheets=...)andadd_page(stylesheets=...), since both go through_compile_stylesheet_files. The link is made with the atomic replacerx.asset(shared=True)already uses; where symlinks are unavailable (Windows without the privilege) the stylesheet is copied as before, after removing a link an earlier compile left there so the copy cannot write through it into the source. Sass and SCSS are still compiled into the styles directory.In dev, Vite serves files outside its root (
.web) only fromserver.fs.allow, so a linked stylesheet's fonts were refused with a 403. The generatedvite.config.jsnow allows the app root next to Vite's default, which matches what Vite allows for an ordinary project (its workspace root);server.fs.denystill refuses.envand key files. A shared stylesheet from an installed package outside the app root still builds correctly, but the dev server will not serve its relative assets.Tests: unit tests for the link and the copy fallback, the
fs.allowline, and a production build (tests/integration/test_prod_build_pipeline.py) of a shared stylesheet pair whose font and image end up as fingerprinted/assets/files.One thing I noticed but left alone: with
TailwindV4Plugin,@tailwindcss/postcssinlines the stylesheets imported into the global stylesheet and rewrites their URLs relative to itsbase(.web), not to the importing stylesheet, so relative URLs in app stylesheets stay broken there. Page stylesheets are not affected.