Fix ClientStateVar late mount default sync

Closed
HA
3mo ago
+150-1

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