Skip to content
Source
Sign inSign up
TanStack/router

fix(router-plugin): omit browser warnings from production bundles #8269

MergedLadyBluenotes(GitHub profile, opens in a new tab)merged 8 commits intomain fromfix/router-production-splitter-warningmerged 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. The NODE_ENV read is gone: the plugin always passes the flag, so a NODE_ENV fallback could only be reached by direct test calls.
  • webpack and Rspack: a config without mode counts as production. Both bundlers apply the plugins before they fill in defaults, so compiler.options.mode is still undefined at that point. Then they build in production (mode || 'production', and webpack prints "webpack will fallback to 'production'"). Before this change, a config without mode also 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 isProduction pass-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:build pass. Nx, @tanstack/start-plugin-core: test:unit passes.

  • examples/react/quickstart-webpack-file-based, built with webpack 5.97.1 and webpack-cli 5.1.4, NODE_ENV unset (env -i), with an extra route that exports its component:

    BuildWarning in client JSWarning in build output
    webpack build (example config, mode: 'production')noneyes
    docs config, no modenoneyes
    docs config, --mode productionnoneyes
    --mode development (control)presentyes
  • Bundle size: all 18 scenarios are unchanged (gzip, raw and brotli all +0) against main at 01fab5a6c8.

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

    2. View your CI Pipeline Execution ↗ for commit 96d73b86909df317b5c0f2c8ed2aaaf93794b7e8

      CommandStatusDurationResult
      nx affected --targets=test:eslint,test:unit,tes...✅ Succeeded10m 51sView ↗
      nx run-many --target=build --exclude=examples/*...✅ Succeeded1m 34sView ↗

      ☁️ Nx Cloud last updated this comment at 2026-11-04 07:40:33 UTC

    3. Review in Change Stack →

      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_commits setting.

      • Last reviewed commit: 8ddcd833eda7fa3259436ccaeb4f224e7d510bdc
      • Latest commit, not reviewed: 96d73b86909df317b5c0f2c8ed2aaaf93794b7e8

      Use the following commands to manage reviews:

      • @coderabbitai resume to resume automatic reviews.
      • @coderabbitai review to 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_ENV configurations.

      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.md
      compileCodeSplitReferenceRoute accepts isProduction. 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 and NODE_ENV combinations. 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 to 8ddcd

      No actionable issue is established from the supplied evidence; the change is mergeable after normal checks.

      Pre-merge checks: Passed 4
      Check nameStatusExplanation
      Title checkPassedThe title clearly identifies the main change: removing browser warnings from production bundles in the router plugin.
      Linked Issues checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck skipped because no linked issues were found for this pull request.
      Description checkPassedThe 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.

      Share
      Recent review info
      Run configuration
      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.ts
      • packages/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.

    4. 🚀 Changeset Version Preview

      9 package(s) bumped directly, 2 bumped as dependents.

      🟨 Minor bumps

      PackageVersionReason
      @tanstack/router-cli1.167.46 → 1.168.0Changeset
      @tanstack/router-generator1.167.46 → 1.168.0Changeset
      @tanstack/router-plugin1.168.48 → 1.169.0Changeset
      @tanstack/router-utils1.162.4 → 1.163.0Changeset

      🟩 Patch bumps

      PackageVersionReason
      @tanstack/react-start1.169.4 → 1.169.5Changeset
      @tanstack/react-start-client1.168.44 → 1.168.45Changeset
      @tanstack/solid-start1.169.4 → 1.169.5Changeset
      @tanstack/start-plugin-core1.171.55 → 1.171.56Changeset
      @tanstack/vue-start1.169.4 → 1.169.5Changeset
      @tanstack/react-start-rsc0.1.65 → 0.1.66Dependent
      @tanstack/router-vite-plugin1.167.48 → 1.167.49Dependent
    5. Bundle Size Benchmarks

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

    6. More templates

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

      commit: 96d73b8

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

      Learn more about system calls

      See affected benchmarks

      ✅ 194 untouched benchmarks ⏩ 3 skipped benchmarks1


      Comparing fix/router-production-splitter-warning (96d73b8) with main (01fab5a) 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. ↩

    8. brenelz(GitHub profile, opens in a new tab) approved these changes

    9. 🦋 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
      NameType
      @tanstack/router-pluginPatch
      @tanstack/router-vite-pluginPatch
      @tanstack/start-plugin-corePatch
      @tanstack/react-start-rscPatch
      @tanstack/react-startPatch
      @tanstack/solid-startPatch
      @tanstack/vue-startPatch

      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

Sign in to join this conversation.