-
Notifications
You must be signed in to change notification settings - Fork 160
Remove flushSync from svelte-db to avoid breaking async compiler mode
#745
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove flushSync from svelte-db to avoid breaking async compiler mode
#745
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 |
|
@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: |
|
Size Change: 0 B Total Size: 79.1 kB ℹ️ View Unchanged
|
|
Size Change: 0 B Total Size: 3.34 kB ℹ️ View Unchanged
|
samwillis
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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>
|
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>
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