fix(compiler): omit descendant imports in passthrough memo modules

MI
5h ago
+516-17

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 called render._get_all_imports() before replacing render.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_imports from the root before swapping children (while preserving _form_control_source / _get_all_refs delegation back to definition.component when not already set on render), then set render.children = [hole_child] before calling render._get_all_imports(). When analysis is None, validate pre-swap add_imports and hook VarData.imports via _check_prohibited_imports and merge them via merge_parsed_imports so child-aware root add_imports and add_hooks keep their imports without triggering Form._get_vars(include_children=True) on descendants.
  • Regression tests: Added unit tests in tests/units/reflex_base/components/test_memo.py and tests/units/compiler/test_memoize_plugin.py covering passthrough child exclusion + prop component retention, Form ref imports, custom child-inspecting add_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_analyses isolation, 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 skipped
  • uv 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 informations
  • uv run --frozen pyright --pythonversion 3.11 tests/type_checking & --pythonversion 3.14 tests/type_checking — 0 errors, 0 warnings, 0 informations
  • uv 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 (2089 python files + fragment formatted)
  • uv run --frozen codespell on changed files, uv run --frozen python scripts/make_pyi.py --check, and uv 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