Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

fix(router-plugin): compute shared bindings when the reference module was not compiled in this process - #9023

Open
schiller-manuel wants to merge 3 commits into
mainfrom
fix/router-plugin-shared-bindings-memo
Open

schiller-manuel wants to merge 3 commits into
mainfrom
fix/router-plugin-shared-bindings-memo

Conversation

@schiller-manuel

@schiller-manuel schiller-manuel commented Nov 28, 2026 •

Copy link
Copy Markdown
Collaborator

🎯 Changes

A split route chunk could get its own copy of a binding it shares with the route module.

const visits = createStore(0)
export const Route = createFileRoute('/posts')({
  loader: () => { visits.set(visits.get() + 1) },
  component: () => <p>{visits.get()}</p>,
})

sharedBindingsMap was filled only by the reference transform. The tsr-split and tsr-shared transforms only read it. Vitest 5 restores a compiled module from its module cache (fsModuleCache, on by default) without running the transform, so in that process the map has no entry. A chunk compiled then (an earlier run imported the route file, a later one renders the route) came out as

import { createStore } from './store'
const visits = createStore(0) // second instance
const SplitComponent = () => <p>{visits.get()}</p>

instead of importing visits from posts.tsx?tsr-shared=1, and the tsr-shared transform returned null.

  • One function resolves the split groupings (in the file, else splitBehavior for the route id, else the default) and computes the shared bindings. The reference transform always calls it. The other two call it when the map has no entry for the file.
  • The map stores an empty set for a file without shared bindings, so its chunks do not recompute.
  • What a bundler build emits does not change: the existing snapshot and pipeline tests pass unchanged.

Tests in code-splitter-plugin-pipeline.test.ts run the tsr-split and tsr-shared transforms on a fresh splitter without the reference transform, for each source of groupings, and compare the result with what the same splitter emits after it. The cases with a shared binding fail without the fix.

Not tested against a real Vitest run with a warm cache; the tests drive the plugin's transform hooks. Found while reviewing #8965, which changes the same file, so the second of the two to merge needs a rebase.

Tested locally: test:unit, test:types and test:eslint of router-plugin, test:unit of start-plugin-core.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • 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

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Fixed an issue where split route chunks could not access bindings shared with a route module restored from the persistent transform cache.
    • Split and shared route modules can now resolve the bindings they need even when the reference module has not yet been compiled in the current process. Route grouping settings are applied consistently, so modules compiled in a different order produce compatible results.

schiller-manuel and others added 2 commits November 28, 2026 17:27
… was not compiled in this process

The split and shared transforms read a route file's shared bindings from a
map that only the reference transform filled. A tool with a persistent
transform cache (Vitest 5's fsModuleCache) can restore the compiled
reference module from disk without running that transform, so the map had
no entry: the split chunk declared its own copy of a shared binding instead
of importing it from `?tsr-shared=1`, and the shared transform returned
null.

The map is now a memo. One function resolves the split groupings (in the
file, else `splitBehavior` for the route id, else the default behavior),
computes the shared bindings and stores them, an empty set when there are
none. The reference transform always calls it; the split and shared
transforms call it when the map has no entry for the file.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ot compiled

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4c04102

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 7 packages
Name Type
@tanstack/router-plugin Patch
@tanstack/router-vite-plugin Patch
@tanstack/start-plugin-core Patch
@tanstack/react-start-rsc Patch
@tanstack/react-start Patch
@tanstack/solid-start Patch
@tanstack/vue-start Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
🔒 Security Review ✅ Completed 2026-11-28T16:32:53.336736Z 2cbcf09 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@nx-cloud

nx-cloud Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

View your CI Pipeline Execution ↗ for commit 4c04102

Command Status Duration Result
nx affected --targets=test:eslint,test:unit,tes... ✅ Succeeded 10m 19s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 28s View ↗

💡 With Ultracache enabled, Nx Cloud learns each task's file inputs in CI and uses them on later runs. Turn on Ultracache in workspace settings ↗ · Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-11-28 17:38:34 UTC

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Changeset Version Preview

1 package(s) bumped directly, 6 bumped as dependents.

🟩 Patch bumps

Package Version Reason
@tanstack/router-plugin 1.169.0 → 1.169.1 Changeset
@tanstack/react-start 1.169.7 → 1.169.8 Dependent
@tanstack/react-start-rsc 0.1.68 → 0.1.69 Dependent
@tanstack/router-vite-plugin 1.167.49 → 1.167.50 Dependent
@tanstack/solid-start 1.169.7 → 1.169.8 Dependent
@tanstack/start-plugin-core 1.172.0 → 1.172.1 Dependent
@tanstack/vue-start 1.169.7 → 1.169.8 Dependent

@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The router plugin now resolves and caches shared bindings when compiling split and shared modules. When the reference module has not been compiled in the current process, those modules can compute bindings from route-file code. Tests cover grouping options and compilation order.

Changes: Shared bindings in split route modules

Layer / File(s) Summary
Resolve and cache shared bindings
packages/router-plugin/src/core/router-code-splitter-plugin.ts, packages/router-plugin/ARCHITECTURE-CODE-SPLITTING.md
The resolver selects grouping configuration, computes bindings, and caches the result, including an empty set. Plugin split behavior uses the route map to find the route ID. The architecture documentation describes the resolver and cache behavior.
Use fallback during module compilation
packages/router-plugin/src/core/router-code-splitter-plugin.ts, packages/router-plugin/tests/code-splitter-plugin-pipeline.test.ts, packages/router-plugin/ARCHITECTURE-CODE-SPLITTING.md, .changeset/router-plugin-shared-bindings-memo.md
Virtual and shared module compilation resolve bindings when the cache has no entry. Tests cover grouping options and compilation before reference-module compilation. The changeset describes the persistent transform cache scenario.

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

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant VirtualRouteCompilation
  participant getSharedBindings
  participant resolveSharedBindings
  participant sharedBindingsMap
  VirtualRouteCompilation->>getSharedBindings: Request bindings for base route
  getSharedBindings->>sharedBindingsMap: Look up cached bindings
  getSharedBindings->>resolveSharedBindings: Resolve when no entry exists
  resolveSharedBindings->>sharedBindingsMap: Store computed bindings
  getSharedBindings-->>VirtualRouteCompilation: Return bindings
Loading

Suggested reviewers: sheraff

Merge Risk: Minimal · up to 4c041

This change fixes duplicate bindings in split route chunks when the route module is restored from the transform cache. The supplied evidence shows no remaining merge-blocking risk, and the bundler output is reported unchanged.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the fix (computing shared bindings when the reference module was not compiled in this process), which matches the changeset: the split and shared transforms now compute bindings when t…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description covers the change and its motivation well. It includes a reproduction snippet, explains the root cause (sharedBindingsMap is filled only by the reference transform, and Vitest's module…
Full details: Title check

Explanation

The title names the fix (computing shared bindings when the reference module was not compiled in this process), which matches the changeset: the split and shared transforms now compute bindings when the shared-bindings map has no entry for a file, as happens when Vitest restores the reference module from its cache. The title is specific and accurate, though long at 102 characters.

Full details: Description check

Explanation

The description covers the change and its motivation well. It includes a reproduction snippet, explains the root cause (sharedBindingsMap is filled only by the reference transform, and Vitest's module cache skips the transform), describes the fix, and lists the tests and the local test commands run. It also notes the rebase dependency on #8965. The template's checklist is filled in, and the release impact section marks a changeset as generated, which matches the raw summary's changeset file. The unchecked 'I fully understand the code' box is a gap: the author left it unchecked while the PR is AI-assisted, and the template asks for AI disclosure. The description discloses AI authorship via the Claude Code footer, so the template's AI disclosure rule is satisfied. The description is complete enough to pass.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 2cbcf09 and 4c04102.

Files selected for processing: 3

  • packages/router-plugin/ARCHITECTURE-CODE-SPLITTING.md
  • packages/router-plugin/src/core/router-code-splitter-plugin.ts
  • packages/router-plugin/tests/code-splitter-plugin-pipeline.test.ts
Files skipped from review as they are similar to previous changes: 1

  • packages/router-plugin/ARCHITECTURE-CODE-SPLITTING.md

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.

@github-actions

Copy link
Copy Markdown
Contributor

Bundle Size Benchmarks

This pull request does not affect bundle size in any measured scenario.

@pkg-pr-new

pkg-pr-new Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
More templates

@tanstack/arktype-adapter

npm i https://pkg.pr.new/@tanstack/arktype-adapter@9023

@tanstack/eslint-plugin-router

npm i https://pkg.pr.new/@tanstack/eslint-plugin-router@9023

@tanstack/eslint-plugin-start

npm i https://pkg.pr.new/@tanstack/eslint-plugin-start@9023

@tanstack/history

npm i https://pkg.pr.new/@tanstack/history@9023

@tanstack/react-router

npm i https://pkg.pr.new/@tanstack/react-router@9023

@tanstack/react-router-devtools

npm i https://pkg.pr.new/@tanstack/react-router-devtools@9023

@tanstack/react-router-ssr-query

npm i https://pkg.pr.new/@tanstack/react-router-ssr-query@9023

@tanstack/react-start

npm i https://pkg.pr.new/@tanstack/react-start@9023

@tanstack/react-start-client

npm i https://pkg.pr.new/@tanstack/react-start-client@9023

@tanstack/react-start-rsc

npm i https://pkg.pr.new/@tanstack/react-start-rsc@9023

@tanstack/react-start-server

npm i https://pkg.pr.new/@tanstack/react-start-server@9023

@tanstack/router-cli

npm i https://pkg.pr.new/@tanstack/router-cli@9023

@tanstack/router-core

npm i https://pkg.pr.new/@tanstack/router-core@9023

@tanstack/router-devtools

npm i https://pkg.pr.new/@tanstack/router-devtools@9023

@tanstack/router-devtools-core

npm i https://pkg.pr.new/@tanstack/router-devtools-core@9023

@tanstack/router-generator

npm i https://pkg.pr.new/@tanstack/router-generator@9023

@tanstack/router-plugin

npm i https://pkg.pr.new/@tanstack/router-plugin@9023

@tanstack/router-ssr-query-core

npm i https://pkg.pr.new/@tanstack/router-ssr-query-core@9023

@tanstack/router-utils

npm i https://pkg.pr.new/@tanstack/router-utils@9023

@tanstack/router-vite-plugin

npm i https://pkg.pr.new/@tanstack/router-vite-plugin@9023

@tanstack/solid-router

npm i https://pkg.pr.new/@tanstack/solid-router@9023

@tanstack/solid-router-devtools

npm i https://pkg.pr.new/@tanstack/solid-router-devtools@9023

@tanstack/solid-router-ssr-query

npm i https://pkg.pr.new/@tanstack/solid-router-ssr-query@9023

@tanstack/solid-start

npm i https://pkg.pr.new/@tanstack/solid-start@9023

@tanstack/solid-start-client

npm i https://pkg.pr.new/@tanstack/solid-start-client@9023

@tanstack/solid-start-server

npm i https://pkg.pr.new/@tanstack/solid-start-server@9023

@tanstack/start-client-core

npm i https://pkg.pr.new/@tanstack/start-client-core@9023

@tanstack/start-fn-stubs

npm i https://pkg.pr.new/@tanstack/start-fn-stubs@9023

@tanstack/start-plugin-core

npm i https://pkg.pr.new/@tanstack/start-plugin-core@9023

@tanstack/start-server-core

npm i https://pkg.pr.new/@tanstack/start-server-core@9023

@tanstack/start-static-server-functions

npm i https://pkg.pr.new/@tanstack/start-static-server-functions@9023

@tanstack/start-storage-context

npm i https://pkg.pr.new/@tanstack/start-storage-context@9023

@tanstack/valibot-adapter

npm i https://pkg.pr.new/@tanstack/valibot-adapter@9023

@tanstack/virtual-file-routes

npm i https://pkg.pr.new/@tanstack/virtual-file-routes@9023

@tanstack/vue-router

npm i https://pkg.pr.new/@tanstack/vue-router@9023

@tanstack/vue-router-devtools

npm i https://pkg.pr.new/@tanstack/vue-router-devtools@9023

@tanstack/vue-router-ssr-query

npm i https://pkg.pr.new/@tanstack/vue-router-ssr-query@9023

@tanstack/vue-start

npm i https://pkg.pr.new/@tanstack/vue-start@9023

@tanstack/vue-start-client

npm i https://pkg.pr.new/@tanstack/vue-start-client@9023

@tanstack/vue-start-server

npm i https://pkg.pr.new/@tanstack/vue-start-server@9023

@tanstack/zod-adapter

npm i https://pkg.pr.new/@tanstack/zod-adapter@9023

commit: 4c04102

@codspeed

codspeed Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Merging this PR will improve performance by 3.94%

2 warnings

⚠️ 41 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

⚠️ 1 benchmark with a significant change ran on different hardware

Its base and head results were measured on machines with a different CPU, core count or memory, so the change might not come from the code. Run base and head on the same runner type.

Learn more about Macro Runners

See affected benchmarks

⚡ 1 improved benchmark
✅ 199 untouched benchmarks
⏩ 3 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
⚡ Memory mem client navigation-churn (solid) 114.7 KB 110.4 KB +3.94%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing fix/router-plugin-shared-bindings-memo (4c04102) with main (10b22c2)

Open in CodSpeed

Footnotes

  1. 3 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

…s asked

`resolveSharedBindings` reads the route of a file itself, so its callers no
longer pass a route id that may be missing. The reference compile gets the
set as it is, as the split compile does. The tests are one table.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Sheraff added a commit that referenced this pull request Nov 28, 2026
…oute shares the route's store (#9023)

Fails on main without #9023 (<p>0</p>, two stores), passes with it and here.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sheraff added a commit that referenced this pull request Nov 28, 2026
…uleCache and renders through the route's lazy component

No private split query: the second run loads the chunk as an app's test
does. Fails on main without #9023 ({ html: '<p>0</p>', stores: 2 }).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant