Skip to content

fix(memo): preserve runtime typing for unannotated params#6659

Open
harsh21234i wants to merge 7 commits into
reflex-dev:mainfrom
harsh21234i:fix/memo-untyped-var-regression-6631
Open

fix(memo): preserve runtime typing for unannotated params#6659
harsh21234i wants to merge 7 commits into
reflex-dev:mainfrom
harsh21234i:fix/memo-untyped-var-regression-6631

Conversation

@harsh21234i

Copy link
Copy Markdown

Summary

Fixes #6631.

@rx.memo component bodies with unannotated parameters were regressing to Var[Any] in 0.9.4, which caused downstream UntypedVarError failures when the memo body
tried to access object fields or call var methods.

This change preserves the legacy behavior for missing annotations by seeding the memo body with the first call’s runtime value type before the component is
materialized. That keeps the deprecation warning in place, but avoids the confusing compile-time failure for existing call sites.

Testing

  • uv run pytest -o addopts='' tests/units/components/test_memo.py -q

@harsh21234i harsh21234i requested a review from a team as a code owner June 12, 2026 08:52
@greptile-apps

greptile-apps Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a regression introduced in 0.9.4 where @rx.memo component bodies with unannotated parameters produced Var[Any] placeholders, causing downstream UntypedVarError failures when the body accessed object fields. The fix seeds a shared _runtime_param_values dict with the first call's explicit values before the _LazyBody thunk executes, so unannotated params receive a correctly-typed placeholder on initial materialization.

  • _var_placeholder now accepts an optional runtime_value and infers _var_type from type(runtime_value) (plain Python) or runtime_value._var_type (Var), gated on _annotation_inner_type(annotation) is Any — so only truly-untyped params are affected.
  • MemoComponentDefinition gains a _runtime_param_values mutable dict field (with repr=False, compare=False) that _MemoComponentWrapper.__call__ populates and clears around the first definition.component access.
  • Two tests cover the new branches: one for a plain Python dict value, another asserting _var_type propagation from a passed Var.

Confidence Score: 5/5

Safe to merge; the change is narrowly scoped to the first lazy materialization of unannotated memo params and leaves annotated params, function memos, and passthrough/snapshot memos unaffected.

The runtime-values dict is correctly gated (_annotation_inner_type is Any), isolated to MemoParamKind.VALUE params, and always cleaned up via a finally block. The _LazyBody caching ensures the one-time type seed is used exactly once, and both new test paths (plain Python value and Var) verify the fix end-to-end.

No files require special attention.

Important Files Changed

Filename Overview
packages/reflex-base/src/reflex_base/components/memo.py Adds runtime type inference for unannotated memo params by seeding a shared _runtime_param_values dict before lazy body evaluation; logic is correct and well-scoped to VALUE-kind params only.
tests/units/components/test_memo.py Adds two new tests covering the dict (plain Python value) and Var runtime inference branches; the dict test implicitly validates type inference by exercising subscript access that would raise UntypedVarError on Var[Any].

Reviews (7): Last reviewed commit: "Merge branch 'reflex-dev:main' into fix/..." | Re-trigger Greptile

Comment thread tests/units/components/test_memo.py
Comment thread tests/units/components/test_memo.py
@codspeed-hq

codspeed-hq Bot commented Jun 12, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 26 untouched benchmarks
⏩ 8 skipped benchmarks1


Comparing harsh21234i:fix/memo-untyped-var-regression-6631 (4690ee5) with main (7562344)

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.

@harsh21234i harsh21234i requested a review from masenf June 13, 2026 03:41
@harsh21234i

Copy link
Copy Markdown
Author

any update? @masenf

harsh21234i and others added 2 commits June 16, 2026 19:51
…r-regression-6631

# Conflicts:
#	packages/reflex-base/src/reflex_base/components/memo.py
@greptile-apps

greptile-apps Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Want your agent to iterate on Greptile's feedback? Try greploops.

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.

@rx.memo with unannotated params silently degrades to Var[Any] in 0.9.4 → UntypedVarError at compile (regression from 0.9.3)

2 participants