fix(svelte-db): disabled useLiveQuery no longer crashes#1637
Conversation
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughAdds a guard in Svelte's ChangesDisabled Query Handling Fix
Estimated code review effort: 1 (Trivial) | ~5 minutes Possibly related PRs
Suggested reviewers: ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning Tools execution failed with the following error: Failed to run tools: 13 INTERNAL: Received RST_STREAM with code 2 (Internal server error) Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
More templates
@tanstack/angular-db
@tanstack/browser-db-sqlite-persistence
@tanstack/capacitor-db-sqlite-persistence
@tanstack/cloudflare-durable-objects-db-sqlite-persistence
@tanstack/db
@tanstack/db-ivm
@tanstack/db-sqlite-persistence-core
@tanstack/electric-db-collection
@tanstack/electron-db-sqlite-persistence
@tanstack/expo-db-sqlite-persistence
@tanstack/node-db-sqlite-persistence
@tanstack/offline-transactions
@tanstack/powersync-db-collection
@tanstack/query-db-collection
@tanstack/react-db
@tanstack/react-native-db-sqlite-persistence
@tanstack/rxdb-db-collection
@tanstack/solid-db
@tanstack/svelte-db
@tanstack/tauri-db-sqlite-persistence
@tanstack/trailbase-db-collection
@tanstack/vue-db
commit: |
|
Size Change: 0 B Total Size: 125 kB ℹ️ View Unchanged
|
|
Size Change: 0 B Total Size: 4.26 kB ℹ️ View Unchanged
|
ac88882 to
f0afcae
Compare
A disabled query (callback returning null/undefined) crashed: the reactive-getter unwrapping (`toValue`) called the callback, and the resulting null was spread into createLiveQueryCollection → throw in getQueryIR. Now a null/undefined unwrapped value is treated as a disabled query, matching React/Vue/Solid/Angular. Clears the svelte-db conformance knownGaps (disabled-explicit, disabled-transition); both now pass as normal tests. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
f0afcae to
36ef0b0
Compare
Follow-up #1 of 3 to the conformance suite (#1636), fixing a
knownGapthat suite surfaced.Base: stacked on
test/live-query-conformance-suite(#1636) — it depends on the conformance drivers to clear the gap. Re-target tomainonce #1636 lands.The bug
A disabled
useLiveQuery— the query callback returningnull/undefined, which every other adapter treats as "disabled" — crashed in svelte-db:Root cause
svelte-db added
toValue()unwrapping to support the reactive() => collectioninput form. ButtoValuecalls any function, so it also calls the query callback. When that callback returnsnull/undefined(disabled), the unwrapped value becamenull, which fell through tocreateLiveQueryCollection({ ...null, startSync: true })→ crash ingetQueryIR. The existing disabled short-circuit sat behind atypeof === 'function'check thatnullnever reaches.It went unnoticed because svelte-db had no disabled-query tests — exactly the gap the conformance suite flagged.
Fix
Treat a
null/undefinedunwrapped value as a disabled query (return thedisabledstate), matching React/Vue/Solid/Angular. One guard in the non-function branch.Verification
Clears the
disabled-explicitanddisabled-transitionknownGapsin the svelte-db conformance driver — both now pass as normal tests. Full svelte-db suite green (54),svelte-checkclean. Patch changeset included.🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
useLiveQueryso queries that resolve tonullorundefinedare treated as disabled instead of causing runtime errors.Tests