Skip to content

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

Open
MilindChatrabhuji wants to merge 3 commits into
reflex-dev:mainfrom
MilindChatrabhuji:fix/memo-passthrough-imports-6429
Open

MilindChatrabhuji wants to merge 3 commits into
reflex-dev:mainfrom
MilindChatrabhuji:fix/memo-passthrough-imports-6429

Conversation

@MilindChatrabhuji

@MilindChatrabhuji MilindChatrabhuji commented Nov 26, 2026 •

Copy link
Copy Markdown

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

@MilindChatrabhuji
MilindChatrabhuji requested a review from a team as a code owner November 26, 2026 01:10
@FarhanAliRaza FarhanAliRaza added the bug Something isn't working label Nov 26, 2026 — with ChatGPT Codex Connector

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 4 files

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

Comment thread reflex/compiler/utils.py Resolved
@greptile-apps

greptile-apps Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The PR appears safe to merge; no new actionable issues were found.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no new actionable issues were found.

Summary

Passthrough memo modules now omit imports used only by their children while keeping imports needed by the root component.

  • Passthrough memo modules leave child-only imports in the page.

The earlier unnumbered finding is fixed: the page test now compares the complete normalized output.

Reviews (4) · Last reviewed commit: "fix(compiler): validate pre-swap passthr..." · Reviewed by Greptile

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 3 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

Comment thread reflex/compiler/utils.py Resolved

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Auto-memo passthrough modules pull in descendants' imports unnecessarily

2 participants