Fix TypeScript React provider reconnect#5185
Open
gugahoa wants to merge 1 commit into
Open
Conversation
792f83b to
0245d51
Compare
Mark DbConnection inactive before disconnect/connectError callbacks so consumers see a closed connection. Teach ConnectionManager to clear closed retained provider connections and rebuild them after a short delay while a provider remains mounted. Cancel pending reconnects during release to preserve StrictMode cleanup behavior. Add lifecycle/reconnect regression tests and document that this recovery is provider-level only.
0245d51 to
bbe490e
Compare
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.
Description of Changes
Fix TypeScript SDK React provider recovery when the underlying WebSocket closes or reports an error while a
SpacetimeDBProvideris still mounted.DbConnectioninactive before emittingdisconnect/connectError, so lifecycle callbacks observe the closed state.ConnectionManagerto clear closed retained provider connections and rebuild them after a short delay.DbConnectionusers still own reconnection.API and ABI breaking changes
None. This does not remove or change public APIs. It changes React provider lifecycle behavior so retained provider connections recover after close/error.
Expected complexity level and risk
3/5.
The change is localized to the TypeScript SDK, but it touches async connection lifecycle behavior, timer cancellation, React provider reference counting, and callback-visible connection state. Main risks are duplicate reconnects, stale connection callbacks updating state, using an outdated retained builder for replacement connections, or StrictMode release/remount regressions. The implementation guards against stale callbacks, detaches manager callbacks from closed connections, and cancels reconnect timers during release.
Testing
pnpm --dir crates/bindings-typescript exec vitest run tests/db_connection.test.ts tests/connection_manager.test.ts tests/connection_manager_reconnect.test.tspnpm --dir crates/bindings-typescript lintpnpm --dir crates/bindings-typescript buildpnpm --dir crates/bindings-typescript test