Skip to content

Commit 5bff9c0

Browse files
committed
fix styles_template
1 parent 00d5f07 commit 5bff9c0

File tree

3 files changed

+11
-16
lines changed

3 files changed

+11
-16
lines changed

reflex/compiler/compiler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ def _compile_root_stylesheet(stylesheets: list[str], reset_style: bool = True) -
321321
'The `libsass` package is required to compile sass/scss stylesheet files. Run `pip install "libsass>=0.23.0"`.'
322322
)
323323

324-
return templates.STYLE.render(stylesheets=sheets)
324+
return templates.styles_template(stylesheets=sheets)
325325

326326

327327
def _compile_component(component: Component | StatefulComponent) -> str:

reflex/compiler/templates.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -756,20 +756,18 @@ def custom_component_template(
756756
{components_code}"""
757757

758758

759-
def _styles_template(**kwargs) -> str:
759+
def styles_template(stylesheets: list[str]) -> str:
760760
"""Template for styles.css.
761761
762762
Args:
763-
**kwargs: Template context variables including stylesheets.
763+
stylesheets: List of stylesheets to include.
764764
765765
Returns:
766766
Rendered styles.css content as string.
767767
"""
768-
stylesheets = kwargs.get("stylesheets", [])
769-
imports_code = "@layer __reflex_base;\n"
770-
for sheet_name in stylesheets:
771-
imports_code += f"@import url('{sheet_name}');\n"
772-
return imports_code
768+
return "@layer __reflex_base;\n" + "\n".join(
769+
[f"@import url('{sheet_name}');" for sheet_name in stylesheets]
770+
)
773771

774772

775773
def _render_hooks(hooks: dict, memo: list | None = None) -> str:
@@ -833,6 +831,3 @@ def render(self, **kwargs) -> str:
833831

834832
# Code to render StatefulComponent to an external file to be shared
835833
STATEFUL_COMPONENTS = TemplateFunction(_stateful_components_template)
836-
837-
# Code to render the root stylesheet.
838-
STYLE = TemplateFunction(_styles_template)

tests/units/compiler/test_compiler.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def test_compile_stylesheets(tmp_path: Path, mocker: MockerFixture):
164164
"@import url('https://fonts.googleapis.com/css?family=Sofia&effect=neon|outline|emboss|shadow-multiple');\n"
165165
"@import url('https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css');\n"
166166
"@import url('https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap-theme.min.css');\n"
167-
"@import url('./style.css');\n",
167+
"@import url('./style.css');",
168168
)
169169

170170
assert (project / constants.Dirs.WEB / "styles" / "style.css").read_text() == (
@@ -225,7 +225,7 @@ def test_compile_stylesheets_scss_sass(tmp_path: Path, mocker: MockerFixture):
225225
"@import url('@radix-ui/themes/styles.css');\n"
226226
"@import url('./style.css');\n"
227227
f"@import url('./{Path('preprocess') / Path('styles_a.css')!s}');\n"
228-
f"@import url('./{Path('preprocess') / Path('styles_b.css')!s}');\n",
228+
f"@import url('./{Path('preprocess') / Path('styles_b.css')!s}');",
229229
)
230230

231231
stylesheets = [
@@ -245,7 +245,7 @@ def test_compile_stylesheets_scss_sass(tmp_path: Path, mocker: MockerFixture):
245245
"@import url('@radix-ui/themes/styles.css');\n"
246246
"@import url('./style.css');\n"
247247
f"@import url('./{Path('preprocess') / Path('styles_a.css')!s}');\n"
248-
f"@import url('./{Path('preprocess') / Path('styles_b.css')!s}');\n",
248+
f"@import url('./{Path('preprocess') / Path('styles_b.css')!s}');",
249249
)
250250

251251
assert (project / constants.Dirs.WEB / "styles" / "style.css").read_text() == (
@@ -288,7 +288,7 @@ def test_compile_stylesheets_exclude_tailwind(tmp_path, mocker: MockerFixture):
288288

289289
assert compiler.compile_root_stylesheet(stylesheets) == (
290290
str(Path(".web") / "styles" / (PageNames.STYLESHEET_ROOT + ".css")),
291-
"@layer __reflex_base;\n@import url('./__reflex_style_reset.css');\n@import url('@radix-ui/themes/styles.css');\n@import url('./style.css');\n",
291+
"@layer __reflex_base;\n@import url('./__reflex_style_reset.css');\n@import url('@radix-ui/themes/styles.css');\n@import url('./style.css');",
292292
)
293293

294294

@@ -327,7 +327,7 @@ def test_compile_stylesheets_no_reset(tmp_path: Path, mocker: MockerFixture):
327327
/ "styles"
328328
/ (PageNames.STYLESHEET_ROOT + ".css")
329329
),
330-
"@layer __reflex_base;\n@import url('@radix-ui/themes/styles.css');\n@import url('./style.css');\n",
330+
"@layer __reflex_base;\n@import url('@radix-ui/themes/styles.css');\n@import url('./style.css');",
331331
)
332332

333333

0 commit comments

Comments
 (0)