Remove flushSync from svelte-db to avoid breaking async compiler mode#745
Merged
KyleAMathews merged 8 commits intomainfrom Nov 5, 2025
Merged
Conversation
…r mode Fixes #744 The flushSync() call inside the onFirstReady callback was breaking Svelte 5's async compiler mode. The async compiler enforces a rule that flushSync cannot be called inside effects, as documented at svelte.dev/e/flush_sync_in_effect. The fix removes the flushSync call and updates status directly. Svelte's reactivity system handles the update automatically without needing synchronous flushing. This matches the pattern used in Vue's implementation. Changes: - Removed flushSync() wrapper from onFirstReady callback - Removed unused flushSync import - Updated comment to explain why flushSync cannot be used - All 23 existing tests pass, confirming no regression This fix is backward compatible: - For users WITHOUT async mode (current default): Works as before - For users WITH async mode: Now works instead of throwing error - Future-proof: async mode will be default in Svelte 6
🦋 Changeset detectedLatest commit: 6282d4e 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 |
Collaborator
Author
|
@wobsoriano does this seem reasonable? |
More templates
@tanstack/angular-db
@tanstack/db
@tanstack/db-ivm
@tanstack/electric-db-collection
@tanstack/offline-transactions
@tanstack/powersync-db-collection
@tanstack/query-db-collection
@tanstack/react-db
@tanstack/rxdb-db-collection
@tanstack/solid-db
@tanstack/svelte-db
@tanstack/trailbase-db-collection
@tanstack/vue-db
commit: |
Contributor
|
Size Change: 0 B Total Size: 79.1 kB ℹ️ View Unchanged
|
Contributor
|
Size Change: 0 B Total Size: 3.34 kB ℹ️ View Unchanged
|
samwillis
approved these changes
Nov 5, 2025
Collaborator
samwillis
left a comment
There was a problem hiding this comment.
Approving but with the question - do we have a test that validates this statement:
The fix removes the flushSync call and updates status directly. Svelte's reactivity system handles the update automatically without needing synchronous flushing.
Add test to verify that status changes in useLiveQuery properly trigger reactive re-execution in Svelte effects. This validates that accessing query.isReady/isLoading in component templates will automatically re-render when status changes from loading to ready. The test uses $effect() to track execution counts, confirming that Svelte's $state reactivity system works correctly with the status updates that occur via the onFirstReady callback (which doesn't use flushSync in async compiler mode). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Collaborator
Author
|
Ah good call — just added an actual test. |
afb711c to
521f838
Compare
Regenerate docs after adding reactive status change test. All files now use correct PascalCase naming to match main branch. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
521f838 to
36f8e45
Compare
…ix-bug-011CUk3w5CN4UmLKb7pLVzzT
Update React reference docs to include useLiveSuspenseQuery hook that was added in main. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Merged
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.
Fixes #744
The flushSync() call inside the onFirstReady callback was breaking Svelte 5's async compiler mode. The async compiler enforces a rule that flushSync cannot be called inside effects, as documented at svelte.dev/e/flush_sync_in_effect.
The fix removes the flushSync call and updates status directly. Svelte's reactivity system handles the update automatically without needing synchronous flushing. This matches the pattern used in Vue's implementation.
Changes:
This fix is backward compatible:
🎯 Changes
✅ Checklist
pnpm test:pr.🚀 Release Impact