Skip to content

fix(solid-db): set key option to $key when calling reconcile - #1598

Open
Leonabcd123 wants to merge 9 commits into
TanStack:mainfrom
Leonabcd123:fix/solid-db-id-rendering
Open

fix(solid-db): set key option to $key when calling reconcile#1598
Leonabcd123 wants to merge 9 commits into
TanStack:mainfrom
Leonabcd123:fix/solid-db-id-rendering

Conversation

@Leonabcd123

@Leonabcd123 Leonabcd123 commented Jun 18, 2026

Copy link
Copy Markdown

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.

@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

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 bc32c8d and a04b71a.

📒 Files selected for processing (3)
  • .changeset/solid-id-rendering.md
  • packages/solid-db/src/useLiveQuery.ts
  • packages/solid-db/tests/useLiveQuery.test.tsx
💤 Files with no reviewable changes (1)
  • .changeset/solid-id-rendering.md
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/solid-db/src/useLiveQuery.ts
  • packages/solid-db/tests/useLiveQuery.test.tsx

📝 Walkthrough

Walkthrough

syncDataFromCollection now passes { key: "$key" } to reconcile. 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

Layer / File(s) Summary
Reconciliation key and regression coverage
packages/solid-db/src/useLiveQuery.ts, packages/solid-db/tests/useLiveQuery.test.tsx, .changeset/solid-id-rendering.md
syncDataFromCollection now passes { key: "$key" } to reconcile. 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)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the Solid DB fix and the specific reconcile key option change.
Description check ✅ Passed The description explains the fix, records local testing, and confirms the required changeset for published code.
Linked Issues check ✅ Passed The implementation and regression test address issue #1524 by reconciling items with custom keys such as _id.
Out of Scope Changes check ✅ Passed The source fix, regression test, and changeset are directly related to issue #1524 and the stated pull request objectives.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands.

@Leonabcd123 Leonabcd123 changed the title fix(solid-db): set key property for reconciliation fix(solid-db): set key option to $key when calling reconcile Jun 18, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 00389a4 and 31933e0.

📒 Files selected for processing (3)
  • .changeset/solid-id-rendering.md
  • packages/solid-db/src/useLiveQuery.ts
  • packages/solid-db/tests/useLiveQuery.test.tsx

Comment thread .changeset/solid-id-rendering.md Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 | 🟠 Major

Wrap useLiveQuery in a managed reactive root to avoid leaked subscriptions.

This test directly instantiates useLiveQuery without a reactive owner context. In Solid.js, effects and signals created by useLiveQuery must be disposed properly to prevent subscription leakage between tests. Use renderHook (the established pattern throughout this file) or createRoot with 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 bc32c8d and 21f021b.

📒 Files selected for processing (1)
  • packages/solid-db/tests/useLiveQuery.test.tsx

@coderabbitai

coderabbitai Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Reviews resumed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

solid-db rendering issues when not using key named id

1 participant