Repository navigation
Description
Problem
The compiled frontend bundle and the backend can come from different builds:
- A backend deploy changes the state, and a browser keeps the old bundle.
- Two backend versions run behind one load balancer during a rolling deploy.
api_urlpoints at a backend that did not serve the bundle.
#7435 makes the frontend skip delta substates it does not know (#7247). The page stays usable, but the skew stays hidden:
- A renamed or moved state keeps its old frontend substate, and that substate stops updating without a visible error.
- An event sent to an old handler name fails on the backend.
- A changed var inside a known state is not detected at all.
Only the developer sees a signal: one console warning and one backend log line.
This issue is the concrete design for #6250.
What exists
BaseState._to_schema()(reflex/state.py) hashes the base var names and types of one state class. The state manager uses it to discard stored state that does not match the code. It does not include computed vars, event handler names, or the state tree.FrontendEventExceptionState.auto_reload_on_errors(reflex/state.py) reloads the page after some frontend errors. AsessionStoragecooldown (LAST_RELOADED_KEY,auto_reload_cooldown()) stops reload loops.- The frontend sends the hydrate event in the socket.io CONNECT packet (
socket.current.auth,bootAuthinstate.js). It sends it again on each reconnect. The backend reads it inEventNamespace.on_connect(..., auth).
Proposal
-
Schema hash. Compute one hash of everything the compiled frontend depends on, for each state in the tree:
- the full name
- the frontend var names, base and computed
- the event handler names
Use one function for the compiler and the backend, so the two values cannot drift.
-
Frontend. Compile the hash into the bundle next to
SUBSTATES(in thecontext_templateoutput). The hash then changes exactly when the compiled state tree changes. -
Handshake. Send the hash in the CONNECT
authpayload next to the hydrate event. Every reconnect sends it again. A backend can only get new state code through a process restart, and a restart drops the socket. So checking on each connect is enough. -
Backend. Compute the hash once at startup. On a mismatch in
on_connect, send a mismatch event to that client. Also log it once. -
Client.
- In prod: show a visible "A new version is available" banner with a reload button, or reload once. Use the existing auto-reload cooldown to stop reload loops when two backend versions are behind one load balancer.
- In dev: only warn. A backend hot reload can reconnect before Vite has the new bundle, which gives a short false mismatch.
-
Keep the fix(state): recover from unknown frontend substates #7435 fallback. Deltas that arrive between connect and the reload still skip unknown substates.
Compatibility
- An old frontend sends no hash. The backend must ignore a missing hash.
- An old backend ignores the new
authkey.
Out of scope
- Load balancer skew needs sticky sessions or pinning each client to one deployment, like Vercel Skew Protection. Document this; the framework cannot fix it.
Acceptance
- A frontend bundle compiled without a state, connected to a backend with that state, shows the banner in prod. Only a console warning appears in dev.
- A changed var in a known state is detected. Today nothing detects it.
- No banner or warning appears when the bundle and the backend match.
- A reconnect to a different backend version runs the check again.
- Two backend versions behind a non-sticky proxy cause at most one reload per cooldown window.
Prior art
- Next.js
deploymentId: a mismatch causes a hard navigation. - Inertia asset versioning:
409plusX-Inertia-Location. - Phoenix LiveView
phx-track-static/static_changed?: the app shows a reload prompt. - SvelteKit
updatedwithversion.pollInterval.
Activity
linear-code commentedon Oct 13, 2026
ENG-13282
Detect a frontend/backend state schema mismatch at connect and prompt…