fix(router-plugin): omit browser warnings from production bundles #8269
main fromfix/router-production-splitter-warning·merged by Sheraff(GitHub profile, opens in a new tab) 🎯 Changes#
The bug#
webpack build with NODE_ENV unset ships the code splitter's development warning in the client bundle. It's a top-level console.warn("[tanstack-router] These exports from \"/abs/path/src/routes/x.tsx\" will not be code-split …"). It runs on every page load and leaks the absolute path of the route file on the build machine.
It happens when a route exports a component that would otherwise be split, and another option of that route is still split. It happens with the repo's webpack example and with the config in docs/router/installation/with-webpack.md.
Cause: the compiler read process.env.NODE_ENV at compile time to decide whether to inject the warning. webpack-cli sets NODE_ENV only with --node-env, and webpack only defines it inside the bundle. The Rspack and webpack Node APIs don't set it either. Vite, Rsbuild and the Rspack CLI set NODE_ENV=production before building, so their CLI builds were clean.
Fix#
- The code splitter already knows the bundler's mode (
isProduction), and it now passes it to the compiler. The compiler injects the warning only when it isn't production. TheNODE_ENVread is gone: the plugin always passes the flag, so aNODE_ENVfallback could only be reached by direct test calls. - webpack and Rspack: a config without
modecounts as production. Both bundlers apply the plugins before they fill in defaults, socompiler.options.modeis stillundefinedat that point. Then they build in production (mode || 'production', and webpack prints "webpack will fallback to 'production'"). Before this change, a config withoutmodealso got route HMR and the React Refresh transforms. In a production build those are dead code. - The warning still prints in the build output. Development builds still log it in the page.
Scope: @tanstack/router-plugin only. Vite builds already decide by command === 'build'. The one visible change there is that NODE_ENV=development vite build no longer injects the warning. esbuild has no mode and is unchanged.
Tests#
packages/router-plugin/tests/production-warnings.test.ts runs real webpack and Rspack builds through the public tanstackRouter plugin, following source-maps.test.ts. The app has a route that exports its component and splits its errorComponent. It builds with mode: 'production' and with mode left out. The checks:
- the error component is split;
- the exported component is either split or reported by the build, so the scenario really triggers;
- no emitted JS contains the app's absolute path.
Vitest sets NODE_ENV=test, which behaves like an unset NODE_ENV here.
- On
main, all 4 cases fail. - With only the
isProductionpass-through, the 2 "mode left out" cases fail. - With the full change, all 4 pass.
These replace the fake-compiler matrix that the first version added to router-plugin-context.test.ts.
Validation#
pnpm format.Nx,
@tanstack/router-plugin:test:unit,test:types,test:eslint,test:buildpass. Nx,@tanstack/start-plugin-core:test:unitpasses.examples/react/quickstart-webpack-file-based, built with webpack 5.97.1 and webpack-cli 5.1.4,NODE_ENVunset (env -i), with an extra route that exports its component:Build Warning in client JS Warning in build output webpack build(example config,mode: 'production')none yes docs config, no modenone yes docs config, --mode productionnone yes --mode development(control)present yes Bundle size: all 18 scenarios are unchanged (gzip, raw and brotli all +0) against
mainat01fab5a6c8.
Relation to #8817#
#8817 deletes compilers.ts and router-code-splitter-plugin.ts. Merging #8817 on top of this PR gives 2 new conflicts, both modify/delete on those files. The resolution is to take #8817's deletion. The changeset and the new test merge cleanly.
On #8817's head, the new test passes for mode: 'production'. It fails for mode left out: #8817's webpack/Rspack host treats a missing mode as dev, so its production bundle ships $$tsrRefreshId strings with absolute paths. A one-line change in #8817's src/hosts/webpack.ts makes all 4 cases pass: (compiler.options.mode ?? 'production') === 'production'. This was tried locally and not pushed.
Credits#
Original fix and analysis by LadyBluenotes (a1014f5015). The follow-up commits merge main, remove the NODE_ENV fallback, rewrite the changeset, and replace the test with real builds.
✅ 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
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: router-plugin
Note
Reviews paused#
It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the
reviews.auto_review.auto_pause_after_reviewed_commitssetting.- Last reviewed commit: 8ddcd833eda7fa3259436ccaeb4f224e7d510bdc
- Latest commit, not reviewed: 96d73b86909df317b5c0f2c8ed2aaaf93794b7e8
Use the following commands to manage reviews:
@coderabbitai resumeto resume automatic reviews.@coderabbitai reviewto trigger a single review.
Use the checkboxes below for quick actions:
- ▶️ Resume reviews
- 🔍 Trigger review
No actionable comments were generated in the recent review.
Walkthrough
-
The router plugin now passes bundler production mode to code-split compilation. Browser warning injection uses this mode to determine whether warning code appears. Tests cover webpack, rspack, and Vite across mode and
NODE_ENVconfigurations.Changes: Code-splitting warning behavior
Layer / File(s) Summary Production mode propagation and warning compilation
packages/router-plugin/src/core/code-splitter/compilers.ts,packages/router-plugin/src/core/router-code-splitter-plugin.ts,packages/router-plugin/tests/router-plugin-context.test.ts,.changeset/calm-tables-warn.mdcompileCodeSplitReferenceRouteacceptsisProduction. Webpack and rspack integrations treat an omitted compiler mode as production and pass the flag to the compiler. Tests check browser warning output for webpack, rspack, and Vite across mode andNODE_ENVcombinations. The changeset records a patch release.Estimated code review effort: 2 (Simple) | ~12 minutes
Change: Bug fix
Suggested reviewers:
schiller-manuel,brenelz
Merge Risk:
Minimal · up to8ddcd-
No actionable issue is established from the supplied evidence; the change is mergeable after normal checks.
Pre-merge checks:
4-
Check name Status Explanation Title check The title clearly identifies the main change: removing browser warnings from production bundles in the router plugin. Linked Issues check Check skipped because no linked issues were found for this pull request. Out of Scope Changes check Check skipped because no linked issues were found for this pull request. Description check The description is complete and relevant. It explains the bug, cause, fix, scope, tests, validation results, release impact, and credits. It also includes all required checklist sections and a generat… Full details: Description check
-
Explanation
The description is complete and relevant. It explains the bug, cause, fix, scope, tests, validation results, release impact, and credits. It also includes all required checklist sections and a generated changeset.
-
Finishing Touches
-
Generate docstrings
- - [ ] Create stacked PR - [ ] Commit on current branch
🧪 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.
Recent review info-
Run configuration-
- Source mode: Auto
- Repository: TanStack/router
- Branch: fix/router-production-splitter-warning
- File: .coderabbit.yaml
- Commit: 8ddcd83
- Layers: Repository YAML
- Review profile: CHILL
- Plan: Advanced
- Run ID:
e21e4872-39a9-4feb-9474-e88e276a47fc
Commits-
Reviewing files that changed from the base of the PR and between 64affb84cb6c6c6b19cb9f516b4bb3e23db10d8b and 8ddcd833eda7fa3259436ccaeb4f224e7d510bdc.
Files selected for processing: 2-
packages/router-plugin/src/core/router-code-splitter-plugin.tspackages/router-plugin/tests/router-plugin-context.test.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
-
🚀 Changeset Version Preview#
9 package(s) bumped directly, 2 bumped as dependents.
🟨 Minor bumps#
Package Version Reason @tanstack/router-cli1.167.46 → 1.168.0 Changeset @tanstack/router-generator1.167.46 → 1.168.0 Changeset @tanstack/router-plugin1.168.48 → 1.169.0 Changeset @tanstack/router-utils1.162.4 → 1.163.0 Changeset 🟩 Patch bumps#
Package Version Reason @tanstack/react-start1.169.4 → 1.169.5 Changeset @tanstack/react-start-client1.168.44 → 1.168.45 Changeset @tanstack/solid-start1.169.4 → 1.169.5 Changeset @tanstack/start-plugin-core1.171.55 → 1.171.56 Changeset @tanstack/vue-start1.169.4 → 1.169.5 Changeset @tanstack/react-start-rsc0.1.65 → 0.1.66 Dependent @tanstack/router-vite-plugin1.167.48 → 1.167.49 Dependent Bundle Size Benchmarks#
This pull request does not affect bundle size in any measured scenario.
More templates
- tanstack-router-solid-example-authenticated-routes
- tanstack-router-solid-example-authenticated-routes-firebase
- tanstack-router-solid-example-basic
- tanstack-router-solid-example-basic-default-search-params
- tanstack-router-solid-example-basic-devtools-panel
- tanstack-router-solid-example-basic-file-based
- tanstack-router-solid-example-basic-non-nested-devtools
- tanstack-router-solid-example-basic-solid-query
- tanstack-router-solid-example-basic-solid-query-file-based
- tanstack-router-solid-example-basic-ssr-file-based
- tanstack-router-solid-example-basic-ssr-streaming-file-based
- tanstack-router-solid-example-basic-virtual-file-based
- tanstack-router-solid-example-basic-virtual-inside-file-based
- tanstack-router-solid-example-deferred-data
- tanstack-router-solid-i18n-paraglide
- tanstack-router-solid-example-kitchen-sink
- tanstack-router-solid-example-kitchen-sink-file-based
- tanstack-router-solid-example-kitchen-sink-solid-query
- tanstack-router-solid-example-kitchen-sink-solid-query-file-based
- tanstack-router-solid-example-large-file-based
- tanstack-router-solid-example-location-masking
- tanstack-router-solid-example-navigation-blocking
- tanstack-router-solid-example-quickstart
- tanstack-router-solid-example-quickstart-esbuild-file-based
- tanstack-router-solid-example-quickstart-file-based
- tanstack-router-solid-example-quickstart-rspack-file-based
- tanstack-router-solid-example-quickstart-webpack-file-based
- @tanstack/router-solid-mono-simple
- router-solid-mono-simple-lazy
- router-solid-monorepo-solid-query
- tanstack-router-solid-example-scroll-restoration
- tanstack-solid-router-search-validator-adapters
- tanstack-solid-start-example-basic
- tanstack-solid-start-example-basic-auth
- tanstack-solid-start-example-basic-authjs
- tanstack-solid-start-example-basic-cloudflare
- tanstack-solid-start-example-basic-netlify
- tanstack-solid-start-example-basic-nitro
- tanstack-start-example-basic-solid-query
- tanstack-solid-start-example-basic-static
- tanstack-solid-start-bun-hosting
- tanstack-solid-start-example-convex-better-auth
- tanstack-solid-start-example-counter
- tanstack-solid-start-i18n-paraglide
- tanstack-solid-start-example-large
- tanstack-solid-start-streaming-data-from-server-functions
- tanstack-solid-start-example-supabase-basic
- tanstack-solid-start-tailwind-v4
- tanstack-router-solid-example-view-transitions
- tanstack-router-solid-example-with-framer-motion
- tanstack-router-solid-example-with-trpc
- tanstack-router-react-example-authenticated-routes
- tanstack-router-react-example-authenticated-routes-firebase
- tanstack-router-react-example-basic
- tanstack-router-react-example-basic-default-search-params
- tanstack-router-react-example-basic-devtools-panel
- tanstack-router-react-example-basic-file-based
- tanstack-router-react-example-basic-non-nested-devtools
- tanstack-router-react-example-react-query
- tanstack-router-react-example-basic-react-query-file-based
- tanstack-router-react-example-basic-ssr-file-based
- tanstack-router-react-example-basic-ssr-streaming-file-based
- tanstack-router-react-example-basic-virtual-file-based
- tanstack-router-react-example-basic-virtual-inside-file-based
- tanstack-router-react-example-deferred-data
- tanstack-router-i18n-paraglide
- tanstack-router-react-example-kitchen-sink
- tanstack-router-react-example-kitchen-sink-file-based
- tanstack-router-react-example-kitchen-sink-react-query
- tanstack-router-react-example-kitchen-sink-react-query-file-based
- tanstack-router-react-example-large-file-based
- tanstack-router-react-example-location-masking
- tanstack-router-react-example-navigation-blocking
- tanstack-router-react-example-quickstart
- tanstack-router-react-example-quickstart-esbuild-file-based
- tanstack-router-react-example-quickstart-file-based
- tanstack-router-react-example-quickstart-rspack-file-based
- tanstack-router-react-example-quickstart-webpack-file-based
- router-monorepo-react-query
- router-mono-simple
- router-mono-simple-lazy
- tanstack-router-react-example-scroll-restoration
- tanstack-search-validator-adapters
- tanstack-start-example-bare
- tanstack-start-example-basic
- tanstack-start-example-basic-auth
- tanstack-router-react-example-basic-authjs
- tanstack-start-example-basic-cloudflare
- tanstack-start-example-basic-react-query
- tanstack-start-example-basic-rsbuild
- tanstack-start-example-basic-static
- tanstack-start-bun-hosting
- tanstack-start-example-clerk-basic
- tanstack-start-example-convex-trellaux
- tanstack-start-example-counter
- tanstack-start-i18n-paraglide
- tanstack-start-example-large
- tanstack-start-example-material-ui
- tanstack-start-example-next-migration
- tanstack-start-example-rscs
- tanstack-start-streaming-data-from-server-functions
- tanstack-start-example-supabase-basic
- tanstack-start-tailwind-v4
- tanstack-start-example-trellaux
- tanstack-start-example-workos
- tanstack-router-react-example-view-transitions
- tanstack-router-react-example-with-framer-motion
- tanstack-router-react-example-with-trpc
- tanstack-router-react-example-with-trpc-react-query
- tanstack-router-vue-example-basic-jsx
- tanstack-router-vue-example-basic-file-based-jsx
- tanstack-router-vue-example-basic-file-based-sfc
@tanstack/arktype-adapter
npm i https://pkg.pr.new/@tanstack/arktype-adapter@8269@tanstack/eslint-plugin-router
npm i https://pkg.pr.new/@tanstack/eslint-plugin-router@8269@tanstack/eslint-plugin-start
npm i https://pkg.pr.new/@tanstack/eslint-plugin-start@8269@tanstack/history
npm i https://pkg.pr.new/@tanstack/history@8269@tanstack/react-router
npm i https://pkg.pr.new/@tanstack/react-router@8269@tanstack/react-router-devtools
npm i https://pkg.pr.new/@tanstack/react-router-devtools@8269@tanstack/react-router-ssr-query
npm i https://pkg.pr.new/@tanstack/react-router-ssr-query@8269@tanstack/react-start
npm i https://pkg.pr.new/@tanstack/react-start@8269@tanstack/react-start-client
npm i https://pkg.pr.new/@tanstack/react-start-client@8269@tanstack/react-start-rsc
npm i https://pkg.pr.new/@tanstack/react-start-rsc@8269@tanstack/react-start-server
npm i https://pkg.pr.new/@tanstack/react-start-server@8269@tanstack/router-cli
npm i https://pkg.pr.new/@tanstack/router-cli@8269@tanstack/router-core
npm i https://pkg.pr.new/@tanstack/router-core@8269@tanstack/router-devtools
npm i https://pkg.pr.new/@tanstack/router-devtools@8269@tanstack/router-devtools-core
npm i https://pkg.pr.new/@tanstack/router-devtools-core@8269@tanstack/router-generator
npm i https://pkg.pr.new/@tanstack/router-generator@8269@tanstack/router-plugin
npm i https://pkg.pr.new/@tanstack/router-plugin@8269@tanstack/router-ssr-query-core
npm i https://pkg.pr.new/@tanstack/router-ssr-query-core@8269@tanstack/router-utils
npm i https://pkg.pr.new/@tanstack/router-utils@8269@tanstack/router-vite-plugin
npm i https://pkg.pr.new/@tanstack/router-vite-plugin@8269@tanstack/solid-router
npm i https://pkg.pr.new/@tanstack/solid-router@8269@tanstack/solid-router-devtools
npm i https://pkg.pr.new/@tanstack/solid-router-devtools@8269@tanstack/solid-router-ssr-query
npm i https://pkg.pr.new/@tanstack/solid-router-ssr-query@8269@tanstack/solid-start
npm i https://pkg.pr.new/@tanstack/solid-start@8269@tanstack/solid-start-client
npm i https://pkg.pr.new/@tanstack/solid-start-client@8269@tanstack/solid-start-server
npm i https://pkg.pr.new/@tanstack/solid-start-server@8269@tanstack/start-client-core
npm i https://pkg.pr.new/@tanstack/start-client-core@8269@tanstack/start-fn-stubs
npm i https://pkg.pr.new/@tanstack/start-fn-stubs@8269@tanstack/start-plugin-core
npm i https://pkg.pr.new/@tanstack/start-plugin-core@8269@tanstack/start-server-core
npm i https://pkg.pr.new/@tanstack/start-server-core@8269@tanstack/start-static-server-functions
npm i https://pkg.pr.new/@tanstack/start-static-server-functions@8269@tanstack/start-storage-context
npm i https://pkg.pr.new/@tanstack/start-storage-context@8269@tanstack/valibot-adapter
npm i https://pkg.pr.new/@tanstack/valibot-adapter@8269@tanstack/virtual-file-routes
npm i https://pkg.pr.new/@tanstack/virtual-file-routes@8269@tanstack/vue-router
npm i https://pkg.pr.new/@tanstack/vue-router@8269@tanstack/vue-router-devtools
npm i https://pkg.pr.new/@tanstack/vue-router-devtools@8269@tanstack/vue-router-ssr-query
npm i https://pkg.pr.new/@tanstack/vue-router-ssr-query@8269@tanstack/vue-start
npm i https://pkg.pr.new/@tanstack/vue-start@8269@tanstack/vue-start-client
npm i https://pkg.pr.new/@tanstack/vue-start-client@8269@tanstack/vue-start-server
npm i https://pkg.pr.new/@tanstack/vue-start-server@8269@tanstack/zod-adapter
npm i https://pkg.pr.new/@tanstack/zod-adapter@8269commit:
96d73b8Merging this PR will not alter performance#
1 warning
:warning: 60 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.
✅ 194untouched benchmarks⏩ 3skipped benchmarks1
Comparingfix/router-production-splitter-warning(96d73b8) withmain(01fab5a)Footnotes#
-
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. ↩
-
brenelz(GitHub profile, opens in a new tab) approved these changes
🦋 Changeset detected#
Latest commit: 96d73b86909df317b5c0f2c8ed2aaaf93794b7e8
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
Sheraff(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
View your CI Pipeline Execution ↗ for commit 96d73b86909df317b5c0f2c8ed2aaaf93794b7e8
nx affected --targets=test:eslint,test:unit,tes...nx run-many --target=build --exclude=examples/*...☁️ Nx Cloud last updated this comment at
2026-11-04 07:40:33UTC