Skip to content

Fix useTable isReady stuck on false due to stale snapshot cache#4499

Merged
clockwork-labs-bot merged 1 commit intomasterfrom
bot/fix-use-table-is-ready
Mar 2, 2026
Merged

Fix useTable isReady stuck on false due to stale snapshot cache#4499
clockwork-labs-bot merged 1 commit intomasterfrom
bot/fix-use-table-is-ready

Conversation

@clockwork-labs-bot
Copy link
Collaborator

Problem

useTable returns [rows, isReady] where isReady is always false, even when data is present in rows.

Root Cause

When subscription data arrives, onInsert events fire and call computeSnapshot() while subscribeApplied is still false. This caches [rows, false] in lastSnapshotRef.current.

When onApplied later fires and sets subscribeApplied = true, computeSnapshot is recreated (it has subscribeApplied in its dependency array), which recreates getSnapshot. However, getSnapshot() checks lastSnapshotRef.current first -- 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 onApplied fires, isReady stays false forever.

Fix

Clear lastSnapshotRef.current whenever computeSnapshot changes, so the next getSnapshot() call recomputes and returns [rows, true].

Reported by a user in Discord.

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].
Copy link
Contributor

@cloutiertyler cloutiertyler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM

@clockwork-labs-bot clockwork-labs-bot added this pull request to the merge queue Mar 1, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 1, 2026
@clockwork-labs-bot clockwork-labs-bot added this pull request to the merge queue Mar 1, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 1, 2026
@clockwork-labs-bot clockwork-labs-bot added this pull request to the merge queue Mar 2, 2026
Merged via the queue into master with commit 0e0834a Mar 2, 2026
72 of 78 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants