Skip to content

Fix #1685#1686

Open
Jaime02 wants to merge 1 commit into
TanStack:mainfrom
Jaime02:repro
Open

Fix #1685#1686
Jaime02 wants to merge 1 commit into
TanStack:mainfrom
Jaime02:repro

Conversation

@Jaime02

@Jaime02 Jaime02 commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

🎯 Changes

Fix #1685 issue report

✅ 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 nested include results being inconsistently displayed when multiple parent records share related records.
    • Deeply nested related data now remains available for every applicable parent record.
    • Improved reliability when resolving multi-level relationships and shared nested records.

@coderabbitai

coderabbitai Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The change shares INCLUDES_ROUTING cleanup across recursive include flushes and defers stamp deletion until the outermost pass. A regression test covers two roots reaching shared nested rows and verifies that the deepest materialized leaf remains available for both.

Changes

Nested include flush

Layer / File(s) Summary
Shared recursive routing cleanup
packages/db/src/query/live/collection-config-builder.ts
flushIncludesState propagates a shared cleanup set through recursive calls and removes INCLUDES_ROUTING stamps after the outermost flush completes.
Shared nested include regression
packages/db/tests/query/includes.test.ts
Adds coverage for roots that resolve through distinct middle rows to shared rows, asserting that each root retains the deepest leaf materialization.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related issues

Possibly related PRs

  • TanStack/db#1600 — Updates the same live-query includes reconciliation path to avoid duplicate-key child inserts.
  • TanStack/db#1607 — Modifies nested include routing for shared correlation keys.
  • TanStack/db#1684 — Changes include materialization and parent-change handling in the same flow.

Suggested reviewers: kevin-dp, kyleamathews, samwillis

🚥 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 is concise and directly references the issue being fixed, though it does not describe the specific behavior change.
Description check ✅ Passed The PR follows the template and includes the required sections, though the change summary is brief.
Linked Issues check ✅ Passed The code change and regression test address #1685 by preserving nested routing state so shared middle rows keep their leaf materialization.
Out of Scope Changes check ✅ Passed The changes are limited to the bug fix and targeted regression test, with no unrelated edits apparent.
✨ 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.

@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.

🧹 Nitpick comments (1)
packages/db/src/query/live/collection-config-builder.ts (1)

1877-1882: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Avoid using any types; use unknown instead.

As per coding guidelines, avoid using any types and use unknown instead when the type is truly unknown. Consider updating the generic type of the Set to use unknown for improved type strictness.

♻️ Proposed fix
-  routingCleanup?: Set<Record<PropertyKey, any>>,
+  routingCleanup?: Set<Record<PropertyKey, unknown>>,
 ): void {
   // The outermost call owns the cleanup set; nested calls inherit it so the
   // stamp survives until every parent group has been flushed.
   const isOutermostCall = routingCleanup === undefined
-  const cleanup = routingCleanup ?? new Set<Record<PropertyKey, any>>()
+  const cleanup = routingCleanup ?? new Set<Record<PropertyKey, unknown>>()
🤖 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/db/src/query/live/collection-config-builder.ts` around lines 1877 -
1882, Update the routingCleanup parameter and the local cleanup Set in the
surrounding function to use unknown instead of any for the Record value type,
preserving the existing cleanup ownership and inheritance behavior.

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.

Nitpick comments:
In `@packages/db/src/query/live/collection-config-builder.ts`:
- Around line 1877-1882: Update the routingCleanup parameter and the local
cleanup Set in the surrounding function to use unknown instead of any for the
Record value type, preserving the existing cleanup ownership and inheritance
behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8a781add-4e64-44ee-977e-7a2de9741f9e

📥 Commits

Reviewing files that changed from the base of the PR and between 7f0fa36 and a633baa.

📒 Files selected for processing (2)
  • packages/db/src/query/live/collection-config-builder.ts
  • packages/db/tests/query/includes.test.ts

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.

3-level nested materialize is dropped when the middle level is shared by more than one parent row

1 participant