Skip to content
Source
Sign inSign up
TanStack/db

Fix #1685 #1686

ClosedJaime02(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/1686/headopened

🎯 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.
    1. 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

      • TanStack/db#1495 — Both issues modify nested include flush behavior in collection-config-builder.ts.

      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 nameStatusExplanationResolution
      Docstring Coverage⚠️ WarningDocstring 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 nameStatusExplanation
      Title check✅ PassedThe title is concise and directly references the issue being fixed, though it does not describe the specific behavior change.
      Description check✅ PassedThe PR follows the template and includes the required sections, though the change summary is brief.
      Linked Issues check✅ PassedThe 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✅ PassedThe 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.
    2. 🧹 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 7f0fa36ff6d48b0494ed5f6a1223fd18c317e41f and a633baaaf584dd5705bfbf548155b4114b9697c2.

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

Sign in to join this conversation.