Skip to content

Fix test_memo_client_counter after the client-state rename - #7741

Merged
FarhanAliRaza merged 1 commit into
farhan/react-compiler-generation-revivefrom
claude/clever-ramanujan-9850zg
Nov 5, 2026
Merged

FarhanAliRaza merged 1 commit into
farhan/react-compiler-generation-revivefrom
claude/clever-ramanujan-9850zg

Conversation

@masenf

@masenf masenf commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes the integration-app-harness-playwright failures on #7694 after a7400b3 merged main in (failing run).

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)

Why the test failed

test_memo_client_counter hard-coded the JavaScript identifier a client state var binds its value to, e.g. "Δcounter + 1" for ClientStateVar.create("Δcounter", default=0, global_ref=False). Merging main brought in #6936, which changed two things:

  • The legacy wrapper now drops the name when global_ref=False is passed, so the var gets a generated store name (cs$0).
  • The emitted identifier carries the RxClientState suffix.

The hook became const [cs$0RxClientState, setCs$0] = useClientState(0, "cs$0") while the click handler still read Δcounter. That bare identifier is not a binding anywhere in the component, so the browser resolved it through named element access to the <button id="Δcounter">, and the counter rendered "[object HTMLButtonElement]1". The eval variants failed the same way. The previous commit on the branch passed this workflow (run 41491674721).

Changes

  • Build the increment expression from str(counter.value), with a {value} placeholder for the direct read and a {source} placeholder (the identifier as a JSON string literal) for the eval and nested-eval reads, so the test follows whatever identifier Reflex emits.
  • Use rx.client_state(0) and .set(...) instead of the deprecated ClientStateVar.create and set_value, which also removes the deprecation warnings from the run.
  • rx.client_state rejects non-ASCII names, so the Unicode case becomes a plain scoped counter named by its button ID. Unicode bindings in the Babel dependency prune are still covered by test_react_compiler_callback_dependencies, which writes Δvalue bindings directly.

Generated code after the change:

const [cs$0RxClientState, setCs$0] = useClientState(0, "cs$0")
(() => (setCs$0(cs$0RxClientState + 1)))
(() => (setCs$1(eval("cs$1RxClientState") + 1)))
(() => (setCs$2((() => eval("cs$2RxClientState"))() + 1)))

Testing

  • uv run pytest tests/integration/tests_playwright/test_memo.py -k test_memo_client_counter: 12 passed (dev and prod, compiler on and off, three counters each).
  • uv run ruff check, uv run ruff format --check, and uv run pyright on the test file: clean.
  • uv run reflex-release changelog-check: no packaged source changes, so no news fragment is required.

Generated by Claude Code

View guided diff Turn on auto-fix

test_memo_client_counter hard-coded the JavaScript name a client state
var binds its value to ("Δcounter + 1"). Merging main brought in #6936,
which drops the name of a legacy ClientStateVar created with
global_ref=False and suffixes the emitted identifier with RxClientState,
so the hook now reads `const [cs$0RxClientState, setCs$0] = ...` while
the click handler still read `Δcounter`. That bare identifier resolved
to the button carrying id="Δcounter" through the browser's named
element access, and the counter rendered "[object HTMLButtonElement]1".

Build the increment expression from str(counter.value) instead, with a
{value} placeholder for the direct read and a {source} placeholder for
the eval'd reads, so the test follows whatever identifier Reflex emits.
Use rx.client_state(0) and .set(...) in place of the deprecated
ClientStateVar.create / set_value entry points. rx.client_state rejects
non-ASCII names, so the Unicode case becomes a plain scoped counter;
test_react_compiler_callback_dependencies still covers Unicode bindings
in the Babel dependency prune.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ESN8Dfnc4fUrUVcPsqaLGk
@masenf
masenf requested a review from a team as a code owner November 5, 2026 00:33

@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.

No issues found across 1 file

View guided diff | Turn on auto-fix | Re-trigger cubic

@greptile-apps

greptile-apps Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] This test-only change appears safe to merge.

Summary

Updates test_memo_client_counter to read the generated client-state name instead of a hard-coded name.

  • The memo counter test follows each client state’s generated name.

No actionable issues found. Tests were not run during this review.

Reviews (1) · Last reviewed commit: "Derive the client counter test's JS from..." · Reviewed by Greptile

@codspeed

codspeed Bot commented Nov 5, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

1 warning

⚠️ 17 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 148 untouched benchmarks


Comparing claude/clever-ramanujan-9850zg (050060b) with farhan/react-compiler-generation-revive (a7400b3)

Open in CodSpeed

@FarhanAliRaza
FarhanAliRaza merged commit 5c8fb85 into farhan/react-compiler-generation-revive Nov 5, 2026
7 checks passed
@FarhanAliRaza
FarhanAliRaza deleted the claude/clever-ramanujan-9850zg branch November 5, 2026 17:54
FarhanAliRaza added a commit that referenced this pull request Nov 10, 2026
* Let React Compiler optimize generated components

Replays #7272 onto main. That PR auto-closed when its base branch was
deleted after #7234 merged; its own changes were the diff between the
base-branch head it last merged (07aa53c) and its head (4f3e5db),
covering commits c01f4d4, 755ddba and 4f3e5db.

Change the patterns Reflex emits that made React Compiler bail out:
register refs through a useRegisteredRef hook instead of writing to
refs during render, wrap generateUUID in an inline useMemo callback,
list only referenced bindings as useCallback dependencies, disable
function outlining, and describe Emotion's jsx() to the compiler as
JSX. Pin the experimental compiler, which accepts refs passed to jsx().

Add an auto_memoize config option (default True). False removes
MemoizeStatefulPlugin from page compilation so the compiler memoizes
whole pages; app-root memoization is unchanged.

Conflicts with main: #7586 removed hook positions, so the ref hook no
longer passes VarData(position=INTERNAL); #7435 removed
backend_state_mismatch from state.js, so it stays removed.

Claude-Session: https://claude.ai/code/session_01LwJUCTv3FVWzi1UoUpyMLT

* Tie the callback prune pattern to Python names, tidy tests and fragment

Export GENERATED_EVENT_CALLBACK from the React Compiler adapter and test it
against the names get_memoized_event_triggers produces, so a rename on either
side fails a test instead of silently restoring compiler bailouts.

Drop the Unicode stale-callback claim from the reflex-base fragment: main never
had that bug. Move inline test imports to module level.

* Run the auto_memoize compile_app test as a dry run

Without dry_run, REFLEX_SKIP_COMPILE or a leftover .web/nocompile file made
compile_app return before building the page plugins, and the test wrote into
the working directory's .web.

* Derive the client counter test's JS from the var's real identifier (#7741)

test_memo_client_counter hard-coded the JavaScript name a client state
var binds its value to ("Δcounter + 1"). Merging main brought in #6936,
which drops the name of a legacy ClientStateVar created with
global_ref=False and suffixes the emitted identifier with RxClientState,
so the hook now reads `const [cs$0RxClientState, setCs$0] = ...` while
the click handler still read `Δcounter`. That bare identifier resolved
to the button carrying id="Δcounter" through the browser's named
element access, and the counter rendered "[object HTMLButtonElement]1".

Build the increment expression from str(counter.value) instead, with a
{value} placeholder for the direct read and a {source} placeholder for
the eval'd reads, so the test follows whatever identifier Reflex emits.
Use rx.client_state(0) and .set(...) in place of the deprecated
ClientStateVar.create / set_value entry points. rx.client_state rejects
non-ASCII names, so the Unicode case becomes a plain scoped counter;
test_react_compiler_callback_dependencies still covers Unicode bindings
in the Babel dependency prune.


Claude-Session: https://claude.ai/code/session_01ESN8Dfnc4fUrUVcPsqaLGk

Co-authored-by: Claude <noreply@anthropic.com>

* Keep lifecycle events in their branch when auto_memoize is off

Without memo wrappers, on_mount and on_unmount hooks were hoisted to the
page function. A hidden rx.cond branch fired on_mount on page load, and an
rx.foreach item hook read the loop variable outside the loop.

Render the events as a MountEffect element beside the component instead.

* Warn once that react_compiler is experimental

* Render lifecycle events as elements in every compile mode

An on_mount inside rx.foreach was hoisted to the Foreach memo body, where
the loop variable does not exist, so the page crashed. Run
InlineLifecyclePlugin with auto-memoization on as well, and rewrite a
snapshot subtree before the memoize plugin seals it.

* Limit the lifecycle element plugin to the experimental options

Default apps keep the generated code they have on main. The plugin runs
with react_compiler=True or auto_memoize=False.

* Keep scope wrappers when auto_memoize is off; remove MountEffect

The MountEffect element kept one instance across an rx.cond branch switch,
so no lifecycle event fired, and its fragment hid the child from an
as_child parent.

With auto_memoize=False, still wrap a component that has a lifecycle event
or hooks of its own in a memo component. A wrapper has its own identity and
forwards props, and it keeps the hooks in their rx.cond branch.

* Test rx.foreach item lifecycle with auto_memoize off; complete the docstring

- An item's lifecycle hook compiles into a wrapper inside the loop body and
  receives the loop variable when auto_memoize is off.
- default_page_plugins names the snapshot boundary and ALWAYS exceptions.

Claude-Session: https://claude.ai/code/session_01LwJUCVweoEhh1JsZA7emsa

* Keep lifecycle of prop components in a wrapper when auto_memoize is off

With auto_memoize off, a lifecycle event of a component held in a prop moved
into the page function, so it fired on page load even inside a hidden
rx.cond branch. The scope-only rule now uses _has_instance_hooks, which also
checks components held in props.

Claude-Session: https://claude.ai/code/session_01LwJUCVweoEhh1JsZA7emsa

---------

Co-authored-by: Masen Furer <m_github@0x26.net>
Co-authored-by: Claude <noreply@anthropic.com>
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.

3 participants