Skip to content

reregister memo in app harness#6799

Draft
benedikt-bartscher wants to merge 3 commits into
reflex-dev:mainfrom
benedikt-bartscher:fix-memo-harness
Draft

reregister memo in app harness#6799
benedikt-bartscher wants to merge 3 commits into
reflex-dev:mainfrom
benedikt-bartscher:fix-memo-harness

Conversation

@benedikt-bartscher

Copy link
Copy Markdown
Contributor

No description provided.

@greptile-apps

greptile-apps Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes two related bugs that caused flaky compile errors (Invalid path, unresolved $/app_components/... imports) when using AppHarness with a real pre-imported app: (1) reloading the top module on test start silently dropped every submodule page, rx.State subclass, and @rx.memo defined in submodules, and (2) nested var-memo dependencies registered lazily inside another memo's body were missed when the compiler snapshotted MEMOS before evaluating those bodies.

  • AppHarness._initialize_app is split into two clear paths: real apps (app_source is None) are imported once with reload=False and their MEMOS registrations are preserved; generated apps continue to clear MEMOS and reload as before. The _registry_token field defaults to None and cleanup already guards with if self._registry_token is not None, so the early-return path is safe.
  • _reregister_used_memo is called at every @rx.memo wrapper use-site (__call__, partial, __rx_var__, component_var), repopulating a cleared MEMOS from usage even in the belt-and-suspenders case.
  • materialize_registered_memo_bodies runs a fixed-point loop in compile_app before the MEMOS snapshot, evaluating lazy bodies until no new memos are registered, so deeply nested var-memo dependencies are always included in compilation.

Confidence Score: 5/5

The change is safe to merge. Real-app harness tests no longer reload the app module, preserving all submodule registrations; generated-app tests are unaffected.

Both code paths in _initialize_app are clearly scoped and well-tested. The new materialize_registered_memo_bodies pre-pass is idempotent (lazy bodies cache their result after the first evaluation), and the fixed-point loop is guaranteed to terminate. The _registry_token safety gap for real-app teardown is already handled by the existing None guard. No regressions are introduced on the generated-app path.

No files require special attention.

Important Files Changed

Filename Overview
packages/reflex-base/src/reflex_base/components/memo.py Adds _reregister_used_memo (called at every use-site on wrappers) and materialize_registered_memo_bodies (fixed-point pre-pass that evaluates lazy bodies until MEMOS stabilizes), both correctly scoped to non-passthrough memos; logic is sound.
reflex/testing.py Splits _initialize_app into two clearly separated paths: real apps get reload=False with MEMOS preserved (early return before RegistrationContext setup); generated apps clear MEMOS and reload as before. _registry_token defaults to None and cleanup checks for None, so the early return is safe.
reflex/compiler/compiler.py Inserts materialize_registered_memo_bodies() immediately before the MEMOS snapshot to settle nested lazy-body registrations before compilation; minimal, targeted change.
tests/units/components/test_memo.py Adds three targeted regression tests: re-registration on use after a clear, nested var-memo detection via materialize_registered_memo_bodies, and passthrough-auto-memo exclusion. All scenarios are well-covered.
tests/units/test_testing.py Updates the existing real-app harness test to assert reload=False and MEMOS preservation; correctly mocks initialize_frontend_dependencies for the new code path.
news/+harness-real-app-no-reload.bugfix.md Changelog entry describing the AppHarness real-app no-reload fix.
packages/reflex-base/news/+memo-harness-reregister.bugfix.md Changelog entry describing the memo re-registration fix.
pyi_hashes.json Hash update for reflex/experimental/memo.pyi reflecting the new materialize_registered_memo_bodies export.

Reviews (3): Last reviewed commit: "more memo harness fixes" | Re-trigger Greptile

@codspeed-hq

codspeed-hq Bot commented Jul 18, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 26 untouched benchmarks
⏩ 8 skipped benchmarks1


Comparing benedikt-bartscher:fix-memo-harness (384dec7) with main (f79d011)

Open in CodSpeed

Footnotes

  1. 8 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@benedikt-bartscher
benedikt-bartscher marked this pull request as ready for review July 18, 2026 11:17
@benedikt-bartscher
benedikt-bartscher requested a review from a team as a code owner July 18, 2026 11:17

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 40fed7de7d

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/reflex-base/src/reflex_base/components/memo.py
@benedikt-bartscher
benedikt-bartscher marked this pull request as draft July 18, 2026 11:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant