Pass boot-time client storage through get_delta overrides

Merged
MA
24d ago
+154-6

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)

Changes To Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes locally?

What

_apply_client_storage_vars now returns the (state, var_name) pairs it set, and hydrate_and_load marks exactly those vars dirty again after the guarded (is_hydrated: false) snapshot has been emitted. The event's own delta, which chain_updates builds through get_delta exactly as it does for update_vars_internal, then carries them, and the browser may persist that delta.

Fixes #7469.

Why

Since #7064 the single hydrate_and_load boot event applied the browser's client-storage values and _clean()ed them before building the delta, so no get_delta override ever saw them. On 0.9.12 the separate update_vars_internal delta went through get_delta. reflex-enterprise's OIDCAuthState.get_delta reconciles the latest_access_token_hash_ls LocalStorage var only when that key is in a delta, so on 0.10 a tab that boots with a stale token hash was never corrected: logging out in one tab left other tabs fully signed in (race-free form: log out in tab 2, press Back in tab 1). Found and independently confirmed by the 0.10.0a2 pre-release QA (prerelease_testing/2026-10-07/ent_auth/verification/NOTES.md on claude/reflex-prerelease-testing-t0sd90).

The #7460 invariants hold: the snapshot is unchanged and still carries is_hydrated: false; reset defaults stay clean, so nothing the browser did not send is written back; computed-var writes made during the snapshot still reach the browser in a delta it can persist; _diff_against_initial_state is untouched. The alternative of not cleaning the applied vars before the snapshot was rejected: the values would pass through get_delta twice (the enterprise override would queue two cookie syncs), an override's rewrite would only land in the non-persisted snapshot, and a key the override withholds would still be sent by the dict() snapshot. Trade-off: the boot delta now echoes the client-storage values the browser holds and recomputes the computed vars that depend on them, as 0.9.x did on every boot and 0.10 still does on every client-side navigation.

Test plan

  • Unit: tests/units/reflex_base/event/processor/test_base_state_processor.py::test_hydrate_passes_client_storage_through_get_delta (8 cases: memory and redis managers, with and without hashes and on_load) asserts the override sees the boot value exactly once, its rewrite reaches a storage-writable delta, and an unset cookie's default never does; all failed before (assert [] == ['stale']). test_hydrate_and_load_single_lock_cycle updated for the intended extra delta.
  • Integration: tests/integration/tests_playwright/test_hydration_storage.py gains a ReconcileState whose get_delta override rewrites a stale LocalStorage value to fresh and test_hydration_reconciles_storage_in_get_delta (dev and prod, with and without on_load); all four failed before. -k "storage or hydrat" 8/8 after.
  • End to end on the QA verifier's fixtures with the patched tree: the core-only get_delta override sees both the boot value and the navigation value in dev and prod (before: navigation only); with the offline reflex-enterprise 0.9.7a4 wheel, Redis and a mock OIDC provider, the Back-button logout case goes from 0/3 to 3/3 signed out in dev and in prod (1 worker), the stale-hash probes from 0/3/0/3 to 3/3/3/3, boot events now hydrate_and_load + reconcile_tokens_after_sync.
  • ruff check / ruff format clean, pyright reflex tests 0 errors, pre-commit passes; tests/units excluding reflex_cli 11841 passed (the 232 reflex_cli failures are the shallow-checkout version check and fail identically on main).
  • Not run here: the Selenium tests/integration/test_client_storage.py (no matching Chrome in the sandbox). Since the boot now echoes stored values back (cookies re-set, as on 0.9.x), CI's run of it is the one to watch.

🤖 Generated with Claude Code

https://claude.ai/code/session_01SjCrbdguMkfe4bhbaREiwo


Generated by Claude Code