fix(solid-db): set key option to $key when calling reconcile #1598
main fromrefs/pull/1598/head·opened Fixes #1524.
🎯 Changes#
Add key option when calling reconcile which is set to $key, which makes it so items are matched correctly even when the id property doesn't exist.
✅ Checklist#
- I have tested this code locally with
pnpm test.
🚀 Release Impact#
- This change affects published code, and I have generated a changeset.
- This change is docs/CI/dev-only (no release).
Summary by CodeRabbit#
Bug Fixes
- Fixed live query reconciliation to match list items using the correct key field, preventing incorrect item reuse during updates and reordering.
Tests
- Added coverage for custom item keys, confirming that sorted results update to the expected order after an item changes.
- 1
Leonabcd123(GitHub profile, opens in a new tab) changed the title
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. Inline comments: In @.changeset/solid-id-rendering.md: - Line 5: The release note in the changeset file contains two typos that need correction on line 5: the phrase "that that" appears as a duplicate word and should be simplified to "that", and the word "reconcilation" is misspelled and should be corrected to "reconciliation". Update the text to fix both instances so the release note reads clearly and professionally.🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID:
e433e653-ee95-4104-8db2-eb84d69e6a44📥 Commits
Reviewing files that changed from the base of the PR and between 00389a47b258ad58fc3a03c5cc6f66957b9bd2d1 and 31933e0c4d0a37b89bb291acf6127fbd83b21fd5.
📒 Files selected for processing (3)
.changeset/solid-id-rendering.mdpackages/solid-db/src/useLiveQuery.tspackages/solid-db/tests/useLiveQuery.test.tsx
@@ -0,0 +1,5 @@1+---2+'@tanstack/solid-db': patch3+---4+5+Fix reconcile usage in useLiveQuery by setting the key field to "$key" so that that items are matched correctly during reconcilation. Fixes #1524.⚠️ Potential issue | 🟡 Minor | ⚡ Quick win
Fix typo and duplicate word in release note.
Line 5 has
that thatandreconcilation; this should be corrected for publish quality.Suggested edit
-Fix reconcile usage in useLiveQuery by setting the key field to "$key" so that that items are matched correctly during reconcilation. Fixes `#1524`. +Fix reconcile usage in useLiveQuery by setting the key field to "$key" so that items are matched correctly during reconciliation. Fixes `#1524`.📝 Committable suggestion
‼️ IMPORTANT Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
Fix reconcile usage in useLiveQuery by setting the key field to "$key" so that items are matched correctly during reconciliation. Fixes `#1524`.🧰 Tools
🪛 LanguageTool
[grammar] ~5-~5: Ensure spelling is correct Context: ...that items are matched correctly during reconcilation. Fixes
#1524.(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In @.changeset/solid-id-rendering.md at line 5, The release note in the changeset file contains two typos that need correction on line 5: the phrase "that that" appears as a duplicate word and should be simplified to "that", and the word "reconcilation" is misspelled and should be corrected to "reconciliation". Update the text to fix both instances so the release note reads clearly and professionally.Source: Linters/SAST tools
✅ Confirmed as addressed by @Leonabcd123
Fixed in 5721c019bbc64309380e6ef50d1c27ac8a78debd and b547dda348ffe9f707b06f889a34be7b588dc9ad.
@Leonabcd123, thanks for fixing the typos! The changeset description now reads correctly. 🐇
If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!
Fixed in 5721c019bbc64309380e6ef50d1c27ac8a78debd and b547dda348ffe9f707b06f889a34be7b588dc9ad.
coderabbitai[bot](GitHub profile, opens in a new tab)replied on
.changeset/solid-id-rendering.mdline 5@Leonabcd123, thanks for fixing the typos! The changeset description now reads correctly. 🐇
If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/solid-db/tests/useLiveQuery.test.tsx (1)
2609-2639: ⚠️ Potential issue | 🟠 MajorWrap
useLiveQueryin a managed reactive root to avoid leaked subscriptions.This test directly instantiates
useLiveQuerywithout a reactive owner context. In Solid.js, effects and signals created byuseLiveQuerymust be disposed properly to prevent subscription leakage between tests. UserenderHook(the established pattern throughout this file) orcreateRootwith cleanup to ensure proper lifecycle management.Suggested fix
- const query = useLiveQuery((q) => - q - .from({ items: collection }) - .orderBy(({ items }) => items.name, `asc`), - ) + const rendered = renderHook(() => + useLiveQuery((q) => + q + .from({ items: collection }) + .orderBy(({ items }) => items.name, `asc`), + ), + ) await waitFor(() => { - expect(query.isReady).toBe(true) + expect(rendered.result.isReady).toBe(true) }) expect( - Array.from(query()).map((item) => item.name), + Array.from(rendered.result()).map((item) => item.name), ).toEqual([`Bob`, `Kevin`, `Stuart`]) collection.utils.begin() collection.utils.write({ type: `update`, value: { _id: `stuart1`, name: `Alvin`, }, }) collection.utils.commit() await waitFor(() => { expect( - Array.from(query()).map((item) => item.name), + Array.from(rendered.result()).map((item) => item.name), ).toEqual([`Alvin`, `Bob`, `Kevin`]) })🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/solid-db/tests/useLiveQuery.test.tsx` around lines 2609 - 2639, The test is directly calling useLiveQuery without a managed reactive root context, which can leak subscriptions between tests in Solid.js. Wrap the useLiveQuery call and all subsequent query operations in either renderHook (the established pattern used elsewhere in this test file) or createRoot with proper cleanup to ensure effects and signals are disposed correctly. This ensures the reactive context is properly initialized and cleaned up after the test completes, preventing subscription leakage.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. Outside diff comments: In `@packages/solid-db/tests/useLiveQuery.test.tsx`: - Around line 2609-2639: The test is directly calling useLiveQuery without a managed reactive root context, which can leak subscriptions between tests in Solid.js. Wrap the useLiveQuery call and all subsequent query operations in either renderHook (the established pattern used elsewhere in this test file) or createRoot with proper cleanup to ensure effects and signals are disposed correctly. This ensures the reactive context is properly initialized and cleaned up after the test completes, preventing subscription leakage.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID:
c00179c5-f4e2-4a12-8731-4007dfcd934c📥 Commits
Reviewing files that changed from the base of the PR and between bc32c8d3e6bafc8bb7e661d4c41191cd5bb01294 and 21f021b814805097b8cf26c437fa15f457dec270.
📒 Files selected for processing (1)
packages/solid-db/tests/useLiveQuery.test.tsx
✅ Action performed
Reviews resumed.
Superseded by #1825
Leonabcd123(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID:
5ee98229-f10f-4426-a8b3-96745f1054fc📥 Commits
Reviewing files that changed from the base of the PR and between bc32c8d3e6bafc8bb7e661d4c41191cd5bb01294 and a04b71aeeba295cf69d74560345a68599ea9a85a.
📒 Files selected for processing (3)
.changeset/solid-id-rendering.mdpackages/solid-db/src/useLiveQuery.tspackages/solid-db/tests/useLiveQuery.test.tsx💤 Files with no reviewable changes (1)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 Walkthrough
Walkthrough#
syncDataFromCollectionnow passes{ key: "$key" }toreconcile. A regression test verifies item preservation and reordering for a collection keyed by_id. A patch changeset records the fix.Changes#
useLiveQuery reconciliation key fix
packages/solid-db/src/useLiveQuery.ts,packages/solid-db/tests/useLiveQuery.test.tsx,.changeset/solid-id-rendering.mdsyncDataFromCollectionnow passes{ key: "$key" }toreconcile. The test verifies that an_id-keyed collection preserves existing items and reorders results after an item name changes. The changeset records a patch release.Estimated code review effort: 2 (Simple) | ~8 minutes
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)#
✅ Passed checks (4 passed)
#1524by reconciling items with custom keys such as _id.#1524and the stated pull request objectives.✨ Finishing Touches
🧪 Generate unit tests (beta)
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.
❤️ Share