Skip to content

Fix ClientStateVar late mount default sync - #6824

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

Fixes late-mounted global ClientStateVar synchronization by initializing local React state from the shared ref when available.

  • Preserves explicit null shared values while falling back to the configured default only for undefined.
  • Retains the original initializer behavior for non-global client state.
  • Adds unit and browser regression coverage plus a bugfix news fragment.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains; the previously reported explicit-null issue is resolved because the initializer now falls back only when the shared value is undefined.

Important Files Changed

Filename Overview
reflex/experimental/client_state.py Initializes global client state from the shared ref using an undefined-only fallback, while preserving the local-state path.
tests/units/test_client_state.py Covers shared-ref initialization, explicit null preservation, undefined fallback, and local-state isolation.
tests/integration/tests_playwright/test_client_state.py Exercises synchronization when a component mounts after a global value changes and the value later returns to its default.
news/6823.bugfix.md Documents the corrected late-mount synchronization behavior.

Reviews (3): Last reviewed commit: "Add ClientStateVar late mount integratio..." | 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 (45c088e) with main (a08a061)

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.

@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