Add server-managed stale client handling with build IDs#1222
Draft
justinvdm wants to merge 13 commits into
Draft
Add server-managed stale client handling with build IDs#1222justinvdm wants to merge 13 commits into
justinvdm wants to merge 13 commits into
Conversation
Deploying redwood-sdk-docs with
|
| Latest commit: |
a031f70
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://cf4d2cdd.redwood-sdk-docs.pages.dev |
| Branch Preview URL: | https://stale-build-ids.redwood-sdk-docs.pages.dev |
… check Replace handleStaleResponse (check + act) with pure isStaleReloadResponse. Remove triggerStaleReload, clearStaleReloadGuard, and sessionStorage state. A stale reload is a full page load that always fetches fresh HTML and assets. The new client bundle has no stale state, so a guard is unnecessary.
Lift await fetchPromise before handleResponse branch so stale check runs once. Remove stale check from navigation.ts handleResponse; stale is handled upstream.
- Rename getStaleEvent → isStaleRequest (boolean predicate) - Add buildStaleEvent for custom policies that need event data - Rename withClientVersionQuery → addClientVersionToUrl - Remove dead withClientVersionQueryString wrapper - Extract createClientVersionHeaders for DRY header building - Add docs/architecture/staleClientHandling.md
Detect stale clients on every RPC message in SyncedStateProxy, not just at WebSocket handshake time. A stale client sending getState/setState/subscribe/unsubscribe over an already-open WebSocket now receives StaleClientError, and client-core reloads the page. - Add StaleClientError and message-based isStaleClientError - Store client build version in SyncedStateProxy and assert before each forwarded RPC call - Wrap all use-synced-state RPC promises to reload on stale errors - Add playground debug route and deploy-only E2E test - Add unit tests for stale error detection and proxy behavior - Update architecture doc
The __rwsdk_client_version query parameter on use-synced-state WebSocket URLs was not leading to recovery. A stale client whose upgrade was rejected just reconnected with the same stale URL. The only meaningful stale case for use-synced-state is an established WebSocket session that outlives a deployment. That is already handled by the per-message StaleClientError check in SyncedStateProxy. - Remove build version query parameter from WebSocket URL in client-core - Remove isStaleRequest handshake check from syncedStateRoutes - Store session creation build ID in SyncedStateProxy instead of reading it from the request - Delete stale-session.e2e.test.mts and update client-core test - Update architecture doc
Remove outdated references to a WebSocket handshake stale check that no longer exists. Clarify that use-synced-state relies on per-message detection in SyncedStateProxy.
- Add createDeployment().redeploy() for programmatic rebuild/redeploy - Use dynamic ports in runPreviewServer so concurrent testSDK.deploy tests do not collide - Fix reconnect to clear baseClientPromiseByEndpoint and create a fresh capnweb session - Restore client build-version query parameter for use-synced-state WebSocket URLs - Add VITE_RWSDK_SYNCED_STATE_TEST_FAST_RECONNECT env var for test reconnect speed - Add deploy-twice E2E test verifying build A -> build B redeploy - Add stale-message E2E test using a debug route to simulate a build-ID change - Add unit tests for StaleClientError and proxy behavior - Update architecture doc
- Remove stray -- separator so vite preview actually receives --port 0 - Relax deploy-twice assertion because preview mode assigns a new port per preview server - Clear stale build-id override after reload to avoid a reload loop in concurrent runs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Stale RedwoodSDK tabs keep talking to a newer deployment without any framework-managed version check. Core RSC requests continue to succeed when they should tell the client to reload, and synced state websocket sessions continue to open against a newer build.
Solution
We generate a RedwoodSDK build ID through the Vite plugin, expose it to the worker and client runtime, and use it as the shared stale version signal. Core requests now send their client build ID, synced state websocket URLs carry the same version, asset URLs include the build ID, and the server returns a reload response when an older client talks to a newer build. We also added permanent deploy-only playground coverage for the core stale request path and the synced state stale session path.