Skip to content

Fix ClientStateVar late mount default sync - #6824

Open
harsh21234i wants to merge 4 commits into
reflex-dev:mainfrom
harsh21234i:fix/client-state-late-mount-default-sync
Open

Fix ClientStateVar late mount default sync#6824
harsh21234i wants to merge 4 commits into
reflex-dev:mainfrom
harsh21234i:fix/client-state-late-mount-default-sync

Conversation

@harsh21234i

@harsh21234i harsh21234i commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Fixes #6823

Summary

Fixes a global ClientStateVar rendering bug where a component that mounted while the shared value was non-default
could get stuck when the value was later pushed back to the default.

Changes

  • Initialize global ClientStateVar local state from the shared refs mirror when available.
  • Preserve the existing plain useState(default) behavior for non-global client state.
  • Add regression coverage for:
    • global client state reading from the shared ref
    • global client state without a default using undefined
    • local client state not reading from shared refs
  • Add a bugfix news fragment.

Testing

  • uv run pytest tests/units/test_client_state.py -q
  • uv run pytest tests/units/compiler/test_memoize_plugin.py -k client_state -q
  • uv run ruff check reflex/experimental/client_state.py tests/units/test_client_state.py
  • uv run ruff format --check reflex/experimental/client_state.py tests/units/test_client_state.py
  • uv run pyright reflex/experimental/client_state.py tests/units/test_client_state.py
  • uv run towncrier check --config pyproject.toml --dir . --compare-with origin/main

Review in cubic

@harsh21234i
harsh21234i requested a review from a team as a code owner July 31, 2026 15:17
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@harsh21234i

Copy link
Copy Markdown
Contributor Author

hey @adhami3310 can you go through this ?

@greptile-apps

greptile-apps Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR corrects late-mounted global ClientStateVar initialization while preserving local-state behavior.

  • Initializes global client state from the shared refs mirror whenever its value is defined.
  • Preserves explicit shared null values instead of replacing them with the configured default.
  • Adds unit and Playwright regression coverage for shared, defaultless, and local client state.
  • Adds a bugfix news fragment.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains; the explicit undefined check preserves a shared null during late mounting, resolving the previously reported issue.

Important Files Changed

Filename Overview
reflex/experimental/client_state.py Adds a lazy global-state initializer with an explicit undefined check, correctly preserving shared null values while leaving local initialization unchanged.
tests/units/test_client_state.py Verifies generated hooks for shared-ref initialization, explicit null preservation, undefined fallback, and local-state isolation.
tests/integration/tests_playwright/test_client_state.py Covers the late-mount synchronization flow and confirms both consumers update when shared state returns to its default.
news/6823.bugfix.md Accurately documents the corrected late-mounted global client-state behavior.

Reviews (4): Last reviewed commit: "Merge branch 'main' into fix/client-stat..." | Re-trigger Greptile

Comment thread reflex/experimental/client_state.py
@codspeed-hq

codspeed-hq Bot commented Jul 31, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 26 untouched benchmarks
⏩ 8 skipped benchmarks1


Comparing harsh21234i:fix/client-state-late-mount-default-sync (598c79e) with main (346177c)2

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.

  2. No successful run was found on main (d8a132b) during the generation of this report, so 346177c was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@adhami3310

adhami3310 commented Jul 31, 2026

Copy link
Copy Markdown
Member

can you add the repro as integration test

@harsh21234i

Copy link
Copy Markdown
Contributor Author

Added the repro as a Playwright integration test in 45c088e. It follows the issue scenario: push the global
ClientStateVar to a non-default value, mount a second consumer while it is non-default, then push back to the default
and assert both consumers update.

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.

ClientStateVar: a component that mounts while the value is non-default never re-renders on the push back to the default

2 participants