Skip to content
Source
Sign inSign up
TanStack/router

fix(router-utils): cache a descriptor instead of the initializer AST node #8296

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

🎯 Changes

Alternative to #8215, which stops the same leak by cloning the node instead.

@babel/traverse keys its NodePath and Scope caches on node identity, and the Start compiler keeps the initializer node in its module cache for the life of the dev server, so the file's traversal graph is never collected.

Rather than cloning the node, store only what the resolvers actually read. They follow callee, object, an identifier property, and name, never call arguments or source positions, so the cached shape can be a small descriptor:

export type ExpressionSummary =
  | { type: 'identifier'; name: string }
  | { type: 'member'; object: ExpressionSummary; property: string }
  | { type: 'call'; callee: ExpressionSummary }

✅ Checklist

  • I have followed the steps in the Contributing guide (https://github.com/TanStack/router/blob/main/CONTRIBUTING.md).
  • I have tested code changes locally with the relevant test commands, or tests do not apply to this pull request.
  • I fully understand the code in this pull request, including any code generated with AI assistance.

🚀 Release Impact

Summary by CodeRabbit

  • Bug Fixes
    • Improved compiler cache behavior by preventing cached module information from retaining source-file parsing data.
    • Preserved compiler handling for variable bindings, member access, function calls, wrapped expressions, and computed properties.
  • Tests
    • Expanded coverage for expression summarization and updated compiler snapshots to reflect the revised representation.
  • Chores
    • Published patch release updates for the affected Router and Start compiler packages.
    1. Review Change StackReview Change Stack

      No actionable comments were generated in the recent review. 🎉

      ℹ️ Recent review info
      ⚙️ Run configuration

      Configuration used: Path: .coderabbit.yaml

      Review profile: CHILL

      Plan: Advanced

      Run ID: e136ec96-71e0-4356-b05d-0c2dfe0d7484

      📥 Commits

      Reviewing files that changed from the base of the PR and between 9871c0625806001d6bf373524821a00303438a91 and eb9628e6405df83ad5e3b9b6194e262c7f7487f1.

      📒 Files selected for processing (5)
      • .changeset/start-compiler-module-info-ast-retention.md
      • packages/router-utils/src/compiler-helpers.ts
      • packages/router-utils/src/index.ts
      • packages/router-utils/tests/compiler-helpers.test.ts
      • packages/start-plugin-core/src/start-compiler/compiler.ts

      Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


      📝 Walkthrough

      Walkthrough

      The compiler now stores compact expression summaries instead of Babel expression nodes. Router utilities expose the summary type and helper. Start compiler kind resolution consumes summarized identifiers, members, and calls.

      Changes

      Expression summary retention

      Layer / File(s)Summary
      Expression summary contract and storage
      packages/router-utils/src/compiler-helpers.ts, packages/router-utils/src/index.ts, packages/router-utils/tests/compiler-helpers.test.ts, .changeset/start-compiler-module-info-ast-retention.md
      Adds ExpressionSummary and summarizeExpression. Variable and default-export bindings store summarized expressions. Exports and tests cover supported expression shapes and omitted fields.
      Compiler kind resolution integration
      packages/start-plugin-core/src/start-compiler/compiler.ts
      Updates expression and callee resolution to use ExpressionSummary, including namespace-import handling and direct-call checks.

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

      Merge Risk: ⚪ Minimal · up to f37c2

      This change replaces retained initializer ASTs with compact summaries while preserving supported compiler kind resolution, reducing development-server memory retention without an identified current-head merge risk.

      Suggested reviewers: schiller-manuel

      🚥 Pre-merge checks | ✅ 4 | ❌ 1

      ❌ Failed checks (1 warning)

      Check nameStatusExplanationResolution
      Docstring Coverage⚠️ WarningDocstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 4 files. (1 skipped: 1…Write docstrings for the functions missing them to satisfy the coverage threshold.
      ✅ Passed checks (4 passed)
      Check nameStatusExplanation
      Linked Issues check✅ PassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes check✅ PassedCheck skipped because no linked issues were found for this pull request.
      Title check✅ PassedThe title clearly and concisely describes the primary change: caching a descriptor instead of retaining the initializer AST node.
      Description check✅ PassedThe description explains the motivation, implementation, testing checklist, and release impact. It includes the required sections and a generated changeset.
      Full details: Docstring Coverage

      Explanation

      Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 4 files. (1 skipped: 1 unsupported.)

      • Fix all pre-merge checks with AI
      ✨ 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.

Sign in to join this conversation.