Document how to destructure in Svelte#733
Merged
KyleAMathews merged 3 commits intomainfrom Oct 31, 2025
Merged
Conversation
…#414) ## Summary This commit addresses issue #414 where users reported that destructuring the return value from useLiveQuery() breaks reactivity in Svelte 5. ## Root Cause This is a fundamental limitation of Svelte 5's reactivity system, not a bug in the library. When objects with getters are destructured, the destructuring evaluates getters once and captures the values at that moment, losing the reactive connection. ## Solution Added comprehensive documentation explaining: - Why direct destructuring breaks reactivity - Two correct usage patterns: 1. Use dot notation (recommended): `query.data`, `query.isLoading` 2. Wrap with $derived: `const { data } = $derived(query)` ## Changes - Updated JSDoc comments in useLiveQuery.svelte.ts with detailed explanation and examples - Updated README.md with clear usage guidelines - Added test case demonstrating the correct $derived pattern - All 23 existing tests continue to pass ## References - Issue: #414 - Svelte documentation: sveltejs/svelte#11002 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
|
The README is intentionally kept small, so reverting the detailed documentation. The comprehensive documentation remains in the JSDoc comments in useLiveQuery.svelte.ts. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
More templates
@tanstack/angular-db
@tanstack/db
@tanstack/db-ivm
@tanstack/electric-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: 84.3 kB ℹ️ View Unchanged
|
Contributor
|
Size Change: 0 B Total Size: 2.89 kB ℹ️ View Unchanged
|
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
samwillis
approved these changes
Oct 31, 2025
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 #414
Summary
This commit addresses issue #414 where users reported that destructuring the return value from useLiveQuery() breaks reactivity in Svelte 5.
Root Cause
This is a fundamental limitation of Svelte 5's reactivity system, not a bug in the library. When objects with getters are destructured, the destructuring evaluates getters once and captures the values at that moment, losing the reactive connection.
Solution
Added comprehensive documentation explaining:
query.data,query.isLoadingconst { data } = $derived(query)Changes
References
🤖 Generated with Claude Code
🎯 Changes
✅ Checklist
pnpm test:pr.🚀 Release Impact