Skip to content

fix(react-router): prevent webpack static analysis of React.use with let binding#7182

Open
mixelburg wants to merge 2 commits intoTanStack:mainfrom
mixelburg:fix/react-use-webpack-regression
Open

fix(react-router): prevent webpack static analysis of React.use with let binding#7182
mixelburg wants to merge 2 commits intoTanStack:mainfrom
mixelburg:fix/react-use-webpack-regression

Conversation

@mixelburg
Copy link
Copy Markdown

@mixelburg mixelburg commented Apr 13, 2026

Fixes #7176

In #6926, the const REACT_USE = 'use' statement started getting optimized away by the bundler (constant folding), replacing React[REACT_USE] with React['use'] in the published ESM output. This caused Webpack to fail on React 18 apps again since it statically analyzes the 'use' property access.

Changing const to let prevents the bundler from inlining the string literal, restoring the dynamic lookup behaviour in the compiled output:

let REACT_USE = 'use';
var reactUse = React[REACT_USE];

Summary by CodeRabbit

  • Chores
    • Minor internal change to preserve runtime behavior and avoid build-time optimization from altering how a React hook is accessed. No user-visible changes or API differences.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 13, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f3db09f4-d5a2-486e-b7d9-1ff128433c81

📥 Commits

Reviewing files that changed from the base of the PR and between 22a3484 and cddfe3c.

📒 Files selected for processing (1)
  • packages/react-router/src/utils.ts

📝 Walkthrough

Walkthrough

The REACT_USE declaration in packages/react-router/src/utils.ts was changed from a const to a let to preserve dynamic property access like React[REACT_USE] and avoid bundler constant-folding that breaks builds with certain webpack/react combinations.

Changes

Cohort / File(s) Summary
Webpack Optimization Fix
packages/react-router/src/utils.ts
Changed REACT_USE declaration from const to let so the React[REACT_USE] access remains dynamic and is not constant-folded by bundlers.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

A rabbit hops through webpack's code,
Where constants once did firmly load,
Now let keeps use from being seen,
Dynamic access stays pristine,
Hooray—builds run smooth and keen! 🐇✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: converting const to let binding to prevent webpack's static analysis of React.use.
Linked Issues check ✅ Passed The code change directly addresses the requirements from issue #7176 by switching const to let to prevent bundler constant-folding and restore dynamic lookup behavior.
Out of Scope Changes check ✅ Passed The change is narrowly scoped to the specific regression fix, modifying only the REACT_USE binding in utils.ts with no unrelated alterations.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 and usage tips.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 13, 2026

Bundle Size Benchmarks

  • Commit: 4b8df29336c3
  • Measured at: 2026-04-15T02:24:31.275Z
  • Baseline source: history:e30814d94911
  • Dashboard: bundle-size history
Scenario Current (gzip) Delta vs baseline Raw Brotli Trend
react-router.minimal 87.35 KiB 0 B (0.00%) 274.60 KiB 75.97 KiB ▅▅▁▁▁▁▁▁███
react-router.full 90.63 KiB 0 B (0.00%) 285.74 KiB 78.87 KiB ▅▅▁▁▁▁▁▁▂▂█
solid-router.minimal 35.51 KiB 0 B (0.00%) 106.60 KiB 31.91 KiB ██▁▁▁▁▁▁▃▃▃
solid-router.full 39.99 KiB 0 B (0.00%) 120.09 KiB 35.93 KiB ██▁▁▁▁▁▁▆▆▆
vue-router.minimal 53.30 KiB 0 B (0.00%) 152.01 KiB 47.88 KiB ██▁▁▁▁▁▁▄▄▄
vue-router.full 58.20 KiB 0 B (0.00%) 167.43 KiB 52.06 KiB ██▁▁▁▁▁▁▄▄▄
react-start.minimal 101.77 KiB 0 B (0.00%) 322.39 KiB 88.05 KiB ▄▄▁▁▁▁▁▁▃▃█
react-start.full 105.21 KiB 0 B (0.00%) 332.72 KiB 90.89 KiB ▅▅▁▁▁▁▁▁▃▃█
solid-start.minimal 49.52 KiB 0 B (0.00%) 152.41 KiB 43.66 KiB ██▁▁▁▁▁▁▄▄▄
solid-start.full 55.04 KiB 0 B (0.00%) 168.61 KiB 48.44 KiB ██▁▁▁▁▁▁▅▅▅

Trend sparkline is historical gzip bytes ending with this PR measurement; lower is better.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/react-router/src/utils.ts`:
- Line 7: Replace the silent use of let REACT_USE = 'use' with an inline ESLint
disable comment that documents why mutable binding is intentional; specifically
add a comment like /* eslint-disable-next-line prefer-const -- mutable binding
prevents bundlers from constant-folding the string so React[REACT_USE] remains
dynamic */ directly above or on the REACT_USE declaration to suppress
prefer-const and explain the rationale (symbol: REACT_USE in
packages/react-router/src/utils.ts).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: efaa0812-1371-418a-9f88-75a286f37e12

📥 Commits

Reviewing files that changed from the base of the PR and between f1a4973 and 22a3484.

📒 Files selected for processing (1)
  • packages/react-router/src/utils.ts

Comment thread packages/react-router/src/utils.ts
@schiller-manuel
Copy link
Copy Markdown
Contributor

this feels like a "hacky" workaround... let's see if we can make this work reliably

@nx-cloud
Copy link
Copy Markdown
Contributor

nx-cloud bot commented Apr 15, 2026

View your CI Pipeline Execution ↗ for commit cddfe3c

Command Status Duration Result
nx affected --targets=test:eslint,test:unit,tes... ❌ Failed 12m 23s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 1m 4s View ↗

☁️ Nx Cloud last updated this comment at 2026-04-15 02:37:47 UTC

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 15, 2026

More templates

@tanstack/arktype-adapter

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

@tanstack/eslint-plugin-router

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

@tanstack/eslint-plugin-start

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

@tanstack/history

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

@tanstack/nitro-v2-vite-plugin

npm i https://pkg.pr.new/@tanstack/nitro-v2-vite-plugin@7182

@tanstack/react-router

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

@tanstack/react-router-devtools

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

@tanstack/react-router-ssr-query

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

@tanstack/react-start

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

@tanstack/react-start-client

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

@tanstack/react-start-rsc

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

@tanstack/react-start-server

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

@tanstack/router-cli

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

@tanstack/router-core

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

@tanstack/router-devtools

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

@tanstack/router-devtools-core

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

@tanstack/router-generator

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

@tanstack/router-plugin

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

@tanstack/router-ssr-query-core

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

@tanstack/router-utils

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

@tanstack/router-vite-plugin

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

@tanstack/solid-router

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

@tanstack/solid-router-devtools

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

@tanstack/solid-router-ssr-query

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

@tanstack/solid-start

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

@tanstack/solid-start-client

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

@tanstack/solid-start-server

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

@tanstack/start-client-core

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

@tanstack/start-fn-stubs

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

@tanstack/start-plugin-core

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

@tanstack/start-server-core

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

@tanstack/start-static-server-functions

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

@tanstack/start-storage-context

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

@tanstack/valibot-adapter

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

@tanstack/virtual-file-routes

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

@tanstack/vue-router

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

@tanstack/vue-router-devtools

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

@tanstack/vue-router-ssr-query

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

@tanstack/vue-start

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

@tanstack/vue-start-client

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

@tanstack/vue-start-server

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

@tanstack/zod-adapter

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

commit: 22a3484

Copy link
Copy Markdown
Contributor

@nx-cloud nx-cloud bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nx Cloud is proposing a fix for your failed CI:

We add the missing eslint-disable-next-line prefer-const comment above the let REACT_USE = 'use' declaration to fix the failing ESLint task. The PR commit changed const to let to prevent bundler constant-folding, but omitted the suppression comment, causing ESLint's prefer-const rule to flag the never-reassigned let binding. These changes restore the intended state that the PR diff described.

Tip

We verified this fix by re-running tanstack-react-start-e2e-css-modules:test:e2e, @tanstack/react-router:test:eslint, tanstack-vue-start-e2e-basic-spa:test:e2e.

diff --git a/packages/react-router/src/utils.ts b/packages/react-router/src/utils.ts
index 8052d007e2..f3cbf54613 100644
--- a/packages/react-router/src/utils.ts
+++ b/packages/react-router/src/utils.ts
@@ -5,6 +5,7 @@ import * as React from 'react'
 // React 18 with Webpack, which statically analyzes imports and fails when it
 // sees React.use referenced (since 'use' is not exported from React 18).
 // This uses a dynamic string lookup to avoid the static analysis.
+// eslint-disable-next-line prefer-const -- Must be `let` to prevent bundler constant-folding
 let REACT_USE = 'use'
 
 /**

Because this branch comes from a fork, it is not possible for us to apply fixes directly, but you can apply the changes locally using the available options below.

Apply changes locally with:

npx nx-cloud apply-locally V4o8-7y2x

Apply fix locally with your editor ↗   View interactive diff ↗



🎓 Learn more about Self-Healing CI on nx.dev

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Apr 15, 2026

Merging this PR will not alter performance

✅ 6 untouched benchmarks


Comparing mixelburg:fix/react-use-webpack-regression (22a3484) with main (e30814d)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (f1a4973) during the generation of this report, so e30814d was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

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.

Regression: React.use build error with React 18 and Webpack

2 participants