Repository navigation
fix(react-db): release Suspense binding when compile() ends in terminal status - #2511
saudademjj wants to merge 2 commits into
Conversation
…al status Check collection.status immediately after registering the status:change listener in SuspenseBinding.resolve() so collections that synchronously transition to cleaned-up, error, or crashed during compile() release their retry-cache entry instead of staying pinned indefinitely. Fixes TanStack#2504
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
🦋 Changeset detectedLatest commit: 217576e The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
🎯 Changes
Fixes #2504.
In
SuspenseBinding.resolve()(packages/react-db/src/useLiveSuspenseQuery.ts),compile(owned, windowOwner)can return aCollectionwhose status has already synchronously transitioned toerror,crashed, orcleaned-upbeforecollection.on('status:change', ...)is attached (for example, whenstartSync: truecompiles a derived query over an already-failed/crashed source, or when a pre-cleaned-up collection is compiled). Because thestatus:changeevent had already fired,release()was never called or scheduled, leaving the terminal entry pinned insuspenseCollectionsByClientindefinitely and preventing ErrorBoundary retries from starting a fresh attempt.This PR extracts
scheduleRelease(status)(tracking a singlereleaseTimercleared inrelease()) and invokesscheduleRelease(collection.status)immediately after registering thestatus:changelistener:cleaned-up-> callsrelease()immediately (removes the cache entry and detaches the status listener).errororcrashed-> schedules a singlesetTimeout(release, 0)(preserving failures through React's immediate same-turn retry, then releasing the cache entry for subsequent ErrorBoundary resets/remounts).🔬 Oracle Coverage
packages/react-db/tests/suspense-lifecycle-oracle.test.tsx(react.suspense-retry-history, documented under React Suspense initial-view lifecycle indocs/contributing/oracle-coverage.md).react.suspense-retry-historylaw: "The current initial attempt determines fallback, rows and boundary errors; cleanup and retry retire stale failures and successful peers own independent outputs.").retryArbitrary,retryExamples,retryStates, and constructed cases insuspense-lifecycle-oracle.test.tsxwithsync-fail(params.fail(cause)before mount socompile()synchronously producesstatus === 'error') andsync-crash(synchronous throw insync()before mount socompile()synchronously producesstatus === 'crashed'), using defaultgcTime(withoutgcTime: 0) and source-onlysource.cleanup()(without{ dependents: true }) across allnone/provider/explicitclient scopes andderived/keyedmodes, for both ErrorBoundary reset and root remount, withError,record, andundefinedcauses.packages/react-db/tests/useLiveSuspenseQuery-recovery.test.tsxwith directSuspenseBinding.resolve()tests covering synchronouscleaned-up(immediate release without pinning), synchronouserror/crashedsame-turn retry preservation, and next-turn release.initial sync compile failure/initial sync compile crash(data-phase="error"+ boundary cause),new attempt pending(data-phase="pending"+run === 2),retired source rejects during new attempt,settled load makes retry progress(data-phase="ready"+ exact rows),successful peer(exclusive output), andsource stops after readiness.mainc54b6f30, before the fix):vitest run tests/suspense-lifecycle-oracle.test.tsx -t "provider/derived retry"failed 8/30 cases (includingfixed history: retry 2/retry 3, constructedsync-failed boundary reset&sync-crashed root remount, and generated histories) at checkpointnew attempt pending(expected 'error' to be 'pending'), confirming the failed entry stayed pinned insuspenseCollectionsByClient.suspense-lifecycle-oracle.test.tsx,useLiveSuspenseQuery-recovery.test.tsx, anduseLiveSuspenseQuery.test.tsxall pass (325/325 passed, 0 type errors,useLiveSuspenseQuery.ts97.54% line / 100% function coverage).fail/sync-fail/sync-crash/crash/abandon); synchronouscleaned-upduringcompile()is verified via supplementalSuspenseBinding.resolve()tests becauseCollection.cleanup()is observably asynchronous on live source sync runs.✅ Checklist
@tanstack/react-dbbuild,vitest --run(325 passed acrosssuspense-lifecycle-oracle.test.tsx,useLiveSuspenseQuery-recovery.test.tsx,useLiveSuspenseQuery.test.tsx),pnpm lint:changed,pnpm lint:run-budgets,eslint,test:build(publint + attw), andprettier --check.🚀 Release Impact
Summary by CodeRabbit