Skip to content

Commit 746134c

Browse files
committed
fix(compiler): strip self-imports in mirrored memo modules + windows path tests
1 parent 7aa0430 commit 746134c

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

reflex/compiler/compiler.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,10 @@ def _emit_legacy_function(render: dict, render_imports: dict) -> None:
501501
for segments, group in groups.items():
502502
merged_imports = utils.merge_imports(framework_imports, group.imports)
503503
_apply_common_imports(merged_imports)
504+
# Strip self-imports — when memos in this group reference each other,
505+
# their compiled imports point at this group's own mirrored specifier.
506+
# Importing from the same file would shadow the module's own exports.
507+
merged_imports.pop(memo_paths.mirrored_library_specifier(segments), None)
504508
code = templates.memo_components_template(
505509
imports=utils.compile_imports(merged_imports),
506510
components=group.components,

tests/units/experimental/test_memo.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from __future__ import annotations
44

5+
from pathlib import Path
56
from types import SimpleNamespace
67
from typing import Any
78

@@ -405,10 +406,12 @@ def grouped_second(title: rx.Var[str]) -> rx.Component:
405406
dict.fromkeys(CUSTOM_COMPONENTS.values()),
406407
tuple(EXPERIMENTAL_MEMOS.values()),
407408
)
408-
expected_path_fragment = "/" + "/".join(mirrored_segments) + ".jsx"
409+
expected_suffix = (Path(*mirrored_segments).with_suffix(".jsx")).as_posix()
409410

410411
grouped_files = [
411-
(path, code) for path, code in files if path.endswith(expected_path_fragment)
412+
(path, code)
413+
for path, code in files
414+
if Path(path).as_posix().endswith("/" + expected_suffix)
412415
]
413416
assert len(grouped_files) == 1
414417
code = grouped_files[0][1]
@@ -433,7 +436,7 @@ def test_compile_memo_components_falls_back_when_no_source_module():
433436
)
434437

435438
files, _ = compiler.compile_memo_components((), (legacy_definition,))
436-
paths = [path for path, _ in files]
439+
paths = [Path(path).as_posix() for path, _ in files]
437440
assert any(path.endswith("utils/components/LegacyMemo.jsx") for path in paths)
438441

439442

0 commit comments

Comments
 (0)