Fix useTable isReady stuck on false due to stale snapshot cache#4499
Merged
clockwork-labs-bot merged 1 commit intomasterfrom Mar 2, 2026
Merged
Fix useTable isReady stuck on false due to stale snapshot cache#4499clockwork-labs-bot merged 1 commit intomasterfrom
useTable isReady stuck on false due to stale snapshot cache#4499clockwork-labs-bot merged 1 commit intomasterfrom
Conversation
When subscription data arrives, onInsert events fire and cache a snapshot in lastSnapshotRef with subscribeApplied=false. When onApplied later fires and sets subscribeApplied=true, computeSnapshot is recreated but the cached snapshot is never invalidated. getSnapshot() returns the stale [rows, false] tuple because lastSnapshotRef.current is non-null. Fix: clear lastSnapshotRef.current whenever computeSnapshot changes, so the next getSnapshot() call recomputes and returns [rows, true].
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
useTablereturns[rows, isReady]whereisReadyis alwaysfalse, even when data is present inrows.Root Cause
When subscription data arrives,
onInsertevents fire and callcomputeSnapshot()whilesubscribeAppliedis stillfalse. This caches[rows, false]inlastSnapshotRef.current.When
onAppliedlater fires and setssubscribeApplied = true,computeSnapshotis recreated (it hassubscribeAppliedin its dependency array), which recreatesgetSnapshot. However,getSnapshot()checkslastSnapshotRef.currentfirst -- since it is non-null (cached from the earlier insert events), it returns the stale[rows, false]tuple without recomputing.If no further row changes happen after
onAppliedfires,isReadystaysfalseforever.Fix
Clear
lastSnapshotRef.currentwhenevercomputeSnapshotchanges, so the nextgetSnapshot()call recomputes and returns[rows, true].Reported by a user in Discord.