fix(compiler): omit descendant imports in passthrough memo modules
MI
4h ago+516+516+012345678901234567890123456789-17-17-01234567890123456789
All Submissions:
- Have you followed the guidelines stated in CONTRIBUTING.md file?
- Have you checked to ensure there aren't any other open Pull Requests for the desired changed?
Type of change
- Bug fix (non-breaking change which fixes an issue)
Changes To Core Features:
- Have you added an explanation of what your changes do and why you'd like us to include them?
- Have you written new tests for your core changes, as applicable?
- Have you successfully ran tests with your changes locally?
Summary
Fixes passthrough memo modules pulling in descendant libraries, child memo wrappers, and descendant client-state imports when definition.component.children retains the user-authored subtree.
- Root cause: In
reflex/compiler/utils.py(compile_experimental_component_memo), the passthrough branch calledrender._get_all_imports()before replacingrender.children = [hole_child], walking all descendant children even though descendants render in the caller/page scope behind{children}. - Fix: Collect
_root_only_hooks,_root_only_added_imports,_root_only_custom_code, and_root_only_dynamic_importsfrom the root before swapping children (while preserving_form_control_source/_get_all_refsdelegation back todefinition.componentwhen not already set onrender), then setrender.children = [hole_child]before callingrender._get_all_imports(). Whenanalysis is None, validate pre-swapadd_importsand hookVarData.importsvia_check_prohibited_importsand merge them viamerge_parsed_importsso child-aware rootadd_importsandadd_hookskeep their imports without triggeringForm._get_vars(include_children=True)on descendants. - Regression tests: Added unit tests in
tests/units/reflex_base/components/test_memo.pyandtests/units/compiler/test_memoize_plugin.pycovering passthrough child exclusion + prop component retention,Formref imports, custom child-inspectingadd_imports/add_hooks, prohibited import validation for pre-swap root hooks/imports,is_instance_boundary(withClientStateScope) handling for root vs descendant client state,_memo_body_analysesisolation, and full-page auto-memo compilation.
Verification
uv run --frozen pytest tests/units/compiler tests/units/components/test_memo.py tests/units/components/test_memo_cross_module.py tests/units/components/forms tests/units/reflex_base/components tests/units/reflex_base/test_client_state.py tests/units/components/test_component.py -q—1017 passed, 9 skippeduv run --frozen pyright --pythonplatform Linux reflex tests/units/reflex_base/components/test_memo.py tests/units/compiler/test_memoize_plugin.py—0 errors, 0 warnings, 0 informationsuv run --frozen pyright --pythonversion 3.11 tests/type_checking&--pythonversion 3.14 tests/type_checking—0 errors, 0 warnings, 0 informationsuv run --frozen ty check --python-version 3.14 tests/type_checking—All checks passed!uv run --frozen ruff check .—All checks passed!uv run --frozen ruff format --check .&news/+memo-passthrough-descendant-imports.bugfix.md— clean (2089python files + fragment formatted)uv run --frozen codespellon changed files,uv run --frozen python scripts/make_pyi.py --check, anduv run --frozen --package reflex-release reflex-release sync --check/check-headings/changelog-check --base-ref upstream/main— clean (News fragments present for: reflex)
Closes #6429