fix(compiler): use posix separators for nested stylesheet imports#6762
Open
anxkhn wants to merge 2 commits into
Open
fix(compiler): use posix separators for nested stylesheet imports#6762anxkhn wants to merge 2 commits into
anxkhn wants to merge 2 commits into
Conversation
The root stylesheet is compiled by interpolating each stylesheet's relative
path into a CSS `@import url('...')`. The path was rendered with
`str(target_path)`, which uses the OS separator, so on Windows a nested
stylesheet (e.g. `rx.App(stylesheets=["subdir/theme.css"])`, or a stylesheet
directory expanded via rglob) emitted `@import url('./subdir\theme.css');`.
In CSS a backslash inside url() is an escape introducer, not a path
separator, so the browser requested a mangled URL and the nested stylesheet
silently failed to load on Windows only. Top-level stylesheets have no
separator, which is why this went unnoticed.
Build the URL with `target_path.as_posix()` so the import always uses forward
slashes. On POSIX this is identical to the previous output; it only fixes
Windows. Add a regression test that forces a Windows-style relative path and
asserts the emitted import is POSIX-normalized, and make the existing
scss/sass assertions separator-independent.
Signed-off-by: Anas Khan <83116240+anxkhn@users.noreply.github.com>
Signed-off-by: Anas Khan <83116240+anxkhn@users.noreply.github.com>
Contributor
Greptile SummaryThis PR fixes nested stylesheet imports on Windows. The main changes are:
Confidence Score: 5/5This looks safe to merge.
Important Files Changed
Reviews (1): Last reviewed commit: "fix(compiler): add changelog fragment fo..." | Re-trigger Greptile |
Merging this PR will not alter performance
Comparing Footnotes
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
All Submissions
Type of change
Changes To Core Features
What and why
Nested/subfolder stylesheets silently fail to load on Windows.
_compile_root_stylesheet(reflex/compiler/compiler.py) builds the relativetarget as a
pathlib.Pathand then emits it into a CSS@import:For a nested stylesheet,
str(Path("subdir/theme.css"))is"subdir\\theme.css"on Windows, so the compiler writes:Per the CSS spec, a backslash inside
url()is an escape-sequence introducer,not a path separator (
\tbecomes a hex escape), so the browser requests amangled URL and the stylesheet never loads. This only happens on Windows;
POSIX already renders
/, which is why it went unnoticed. Nested stylesheetsare explicitly supported:
rx.App(stylesheets=["subdir/theme.css"]), and adirectory stylesheet is expanded via
rglobinto arbitrarily deep files, bothof which yield multi-segment relative paths.
The fix normalizes the import URL to forward slashes on every platform:
On POSIX the output is byte-for-byte identical to before, so only Windows
behavior changes. This mirrors the separator-normalization idiom already used
elsewhere in the compiler (e.g.
reflex/compiler/utils.py).Tests
test_compile_stylesheets_nested_import_uses_posix_separatorsintests/units/compiler/test_compiler.py. It simulates Windows by forcing therelative path to a
PureWindowsPathand asserts the emitted import is@import url('./subdir/theme.css');with no backslash. It fails before thefix (emitting
@import url('./subdir\theme.css');) and passes after.so they express the intended forward-slash output directly.
uv run pytest tests/units/compiler -q-> 180 passed.uv run ruff check ./uv run ruff format --check-> clean.uv run pyright reflex tests-> 0 errors.f7ec2402 fix(compiler): use posix separators for nested stylesheet imports
4f3b39fd fix(compiler): add changelog fragment for nested stylesheet posix fix