Skip to content

fix: resolve stylesheets' relative urls next to their real file - #8010

Open
benedikt-bartscher wants to merge 34 commits into
reflex-dev:mainfrom
benedikt-bartscher:stylesheet-source-urls
Open

benedikt-bartscher wants to merge 34 commits into
reflex-dev:mainfrom
benedikt-bartscher:stylesheet-source-urls

Conversation

@benedikt-bartscher

@benedikt-bartscher benedikt-bartscher commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

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/styles before the bundler sees them, so their relative url()s resolve against the copy:

/* site_package/css/site.css, linked to assets/external/site_package/css/site.css by rx.asset(shared=True) */
@font-face { font-family: Site; src: url(../fonts/x.woff2); }

Vite looks for .web/styles/external/site_package/fonts/x.woff2, finds nothing and leaves url(../fonts/x.woff2) in the bundle, which the browser requests as /fonts/x.woff2 and gets a 404. A shared asset links only the stylesheet, so its fonts and images never reach the assets directory. Plain stylesheets in assets/ are affected the same way: their relative URLs survive the build unresolved and only happen to work when the stylesheet's depth in assets/ 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:

@font-face{font-family:Site;src:url(/assets/x-Bl2irfN_.woff2)}

This covers App(stylesheets=...) and add_page(stylesheets=...), since both go through _compile_stylesheet_files. The link is made with the atomic replace rx.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 from server.fs.allow, so a linked stylesheet's fonts were refused with a 403. The generated vite.config.js now allows the app root next to Vite's default, which matches what Vite allows for an ordinary project (its workspace root); server.fs.deny still refuses .env and 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.allow line, 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/postcss inlines the stylesheets imported into the global stylesheet and rewrites their URLs relative to its base (.web), not to the importing stylesheet, so relative URLs in app stylesheets stay broken there. Page stylesheets are not affected.

View guided diff

@FarhanAliRaza FarhanAliRaza added the bug Something isn't working label Nov 25, 2026 — with ChatGPT Codex Connector
@greptile-apps

greptile-apps Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The PR appears safe to merge; both numbered findings from the previous review are fixed.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; both numbered findings from the previous review are fixed.

Summary

Stylesheets now link to their real files so Vite can resolve nearby fonts and images. Page stylesheets also work in embedded apps.

  • CSS stylesheets resolve relative assets beside their real files.
  • Each page can load its own stylesheets while it is shown.
  • Same-named Sass and CSS files keep separate compiled outputs.

Reviews (5) · Last reviewed commit: "Merge commit '64d81aba7f' into styleshee..." · Reviewed by Greptile

Comment thread reflex/compiler/compiler.py Resolved
Comment thread reflex/app.py Resolved
Comment thread tests/units/test_prerequisites.py Resolved
Comment thread tests/units/test_prerequisites.py Resolved
@codspeed

codspeed Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Merging this PR will degrade performance by 6.19%

2 warnings

⚠️ 14 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

⚠️ 3 benchmarks with a significant change ran on different hardware

Their base and head results were measured on machines with a different CPU, core count or memory, so the changes might not come from the code. Run base and head on the same runner type.

Learn more about Macro Runners

See affected benchmarks

❌ 3 regressed benchmarks
✅ 143 untouched benchmarks
⏩ 8 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ test_route_matching[1000] 90 ms 96.4 ms -6.64%
❌ test_route_matching[100] 9.4 ms 10 ms -6.4%
❌ test_route_matching[10] 1.2 ms 1.3 ms -5.54%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing benedikt-bartscher:stylesheet-source-urls (9a0709e) with main (6f5c39c)

Open in CodSpeed

Footnotes

  1. 8 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@benedikt-bartscher
benedikt-bartscher marked this pull request as ready for review November 26, 2026 08:49
@benedikt-bartscher
benedikt-bartscher requested a review from a team as a code owner November 26, 2026 08:49

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 21 files

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

Comment thread reflex/app.py Resolved
Comment thread reflex/compiler/compiler.py Resolved
Comment thread reflex/compiler/compiler.py Resolved

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants