Skip to content

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

Open
harsh21234i wants to merge 5 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 5 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

Fixes a regression introduced in 0.9.4 where @rx.memo component bodies with unannotated parameters would receive Var[Any] placeholders, causing UntypedVarError when the body accessed fields or called var methods. The fix seeds body evaluation with the first call's runtime value types, preserving the deprecation warning without breaking existing call sites.

  • Adds _runtime_param_values: dict[str, Any] to MemoComponentDefinition and populates it from explicit_values inside _MemoComponentWrapper.__call__ before triggering lazy-body materialization, then clears it in a finally block.
  • _var_placeholder now accepts an optional runtime_value; when the annotation resolves to Any and a non-None value is supplied, the placeholder's _var_type is taken from type(runtime_value) (or runtime_value._var_type for Var inputs).
  • Two new tests cover both the plain-Python and Var branches of the type-inference path.

Confidence Score: 5/5

Safe to merge; the change is narrowly scoped to unannotated-parameter handling and only affects the first lazy-body materialization.

The mutation of _runtime_param_values is guarded by a try/finally and only influences the one-time lazy evaluation; subsequent calls read the cached body. The dataclasses.replace path shares the same dict object through the lambda closure, so it remains consistent. No correctness issues were found beyond a None-value sentinel edge case and two missing docstring entries.

No files require special attention; both changed files are straightforward.

Important Files Changed

Filename Overview
packages/reflex-base/src/reflex_base/components/memo.py Adds _runtime_param_values to MemoComponentDefinition and seeds it from the first wrapper call; _var_placeholder uses the runtime value's type when the annotation resolves to Any. Core logic is sound for the common case; minor docstring and None-sentinel edge-case nits only.
tests/units/components/test_memo.py Adds two new tests: plain-dict runtime type inference and Var-based runtime type inference. Both branches of _var_placeholder's new code path are now covered.

Reviews (5): Last reviewed commit: "Merge branch 'main' into fix/memo-untype..." | 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

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