fix stuck loading state after an electric must-refetch#532
Conversation
🦋 Changeset detectedLatest commit: f67d98a The changes in this PR will be included in the next version bump. This PR includes changesets to release 8 packages
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 |
| // Always notify dependents when markReady is called, after status is set | ||
| // This ensures live queries get notified when their dependencies become ready | ||
| if (this.changeListeners.size > 0) { | ||
| this.emitEmptyReadyEvent() | ||
| } |
There was a problem hiding this comment.
This is the fix for the stuck loading state
| // 3) Clear currentVisibleState for truncated keys to ensure subsequent operations | ||
| // are compared against the post-truncate state (undefined) rather than pre-truncate state | ||
| // This ensures that re-inserted keys are emitted as INSERT events, not UPDATE events | ||
| for (const key of changedKeys) { | ||
| currentVisibleState.delete(key) | ||
| } |
There was a problem hiding this comment.
This is the fix for the inconsistent state
More templates
@tanstack/db
@tanstack/db-ivm
@tanstack/electric-db-collection
@tanstack/query-db-collection
@tanstack/react-db
@tanstack/solid-db
@tanstack/svelte-db
@tanstack/trailbase-db-collection
@tanstack/vue-db
commit: |
| electricCollection = createElectricUsersCollection() | ||
| }) | ||
|
|
||
| it(`should handle basic must-refetch with filtered live query`, () => { |
There was a problem hiding this comment.
this test failed before the fix, it showed an inconstant state
| expect(liveQuery.size).toBe(1) | ||
| }) | ||
|
|
||
| it(`should handle live query becoming ready after must-refetch during initial sync`, () => { |
There was a problem hiding this comment.
this reproduced the stuck loading state
|
Size Change: 0 B Total Size: 66.6 kB ℹ️ View Unchanged
|
|
Size Change: 0 B Total Size: 1.18 kB ℹ️ View Unchanged
|
kevin-dp
left a comment
There was a problem hiding this comment.
Great find! Love it when the fixes are simple.
packages/electric-db-collection/tests/electric-live-query.test.ts
Outdated
Show resolved
Hide resolved
fa49a6b to
ed9686a
Compare
KyleAMathews
left a comment
There was a problem hiding this comment.
Nice! Very intricate little web we've spun now haha — fine details matter
also fixes an inconstant state bug.