You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(react-router): guard React.use lookup with an in check - #9011
The build folds let REACT_USE = 'use' away, so the published ESM ships React$1["use"]. Rspack and webpack treat that as a static import of use, which React 18 doesn't export, so production builds fail:
export 'use' (imported as 'React$1') was not found in 'react'
Both bundlers recognize an in guard and skip the export check (webpack 5.105+ via webpack/webpack#20320, Rspack 2.1+ via web-infra-dev/rspack#14426). The build emits it unchanged, so nothing is left to constant-fold.
No actionable comments were generated in the recent review.
Walkthrough
The reactUse utility now checks whether React has a use property before returning it. A patch changeset describes the React 18 production-build error with Rspack and webpack.
Changes: React.use compatibility
Layer / File(s)
Summary
Guard React.use and record the fix packages/react-router/src/utils.ts, .changeset/react-use-in-guard.md
reactUse replaces the dynamic lookup with a property-presence check and returns React.use when present. The changeset records a patch for the reported React 18 build error.
This change makes the optional React.use lookup safe for React 18 builds with Rspack and webpack. Behavior is unchanged at runtime. No actionable merge risk remains.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the change: a guard on the React.use lookup using an in check, in the react-router package. The raw summary confirms reactUse now checks for 'use' with in and returns React.use or …
Description check
The description follows the template. It has the Changes section with the problem, the fix, and the reason it works. It has the checklist, with items marked, and the Release Impact section with the ch…
Linked Issues check
Issue #7538 requires that Router builds without errors with React 18 under webpack or Rspack. The root cause is the let REACT_USE = 'use' lookup in packages/react-router/src/utils.ts, which the buil…
Out of Scope Changes check
The whole-PR diff against the merge base changes two files. packages/react-router/src/utils.ts removes the dynamic lookup and its workaround comments and adds the in guard for reactUse. This is the …
Full details: Title check
Explanation
The title names the change: a guard on the React.use lookup using an in check, in the react-router package. The raw summary confirms reactUse now checks for 'use' with in and returns React.use or undefined. The title is specific and matches the main change.
Full details: Description check
Explanation
The description follows the template. It has the Changes section with the problem, the fix, and the reason it works. It has the checklist, with items marked, and the Release Impact section with the changeset item checked. It also discloses AI assistance, as the template requires. It gives concrete test details: unit tests, ESLint, type checks, and production builds on React 18.3.1 and React 19 with Rspack and webpack. It links issue #7538.
Full details: Linked Issues check
Explanation
Issue #7538 requires that Router builds without errors with React 18 under webpack or Rspack. The root cause is the let REACT_USE = 'use' lookup in packages/react-router/src/utils.ts, which the build constant-folds into React$1["use"]. The diff replaces that lookup with export const reactUse = 'use' in React ? React.use : undefined. The in guard is the pattern the PR cites as recognized by webpack 5.105+ and Rspack 2.1+, so the static export check is skipped. The author reports production builds with Rspack 2.3.3 and webpack 5.113 for React 18.3.1 (builds, reactUse undefined) and React 19 (builds, reactUse equal to React.use). The PR adds a changeset. No automated test was added for the build behavior. The bundler behavior that makes the guard effective is external to this repository and was not verified here. The issue reproducer uses Rspack 2.0.6, which is below the cited 2.1 threshold, so the guard alone does not establish a fix for that exact version.
Full details: Out of Scope Changes check
Explanation
The whole-PR diff against the merge base changes two files. packages/react-router/src/utils.ts removes the dynamic lookup and its workaround comments and adds the in guard for reactUse. This is the direct fix for #7538. The changeset file .changeset/react-use-in-guard.md declares a patch release for @tanstack/react-router, which supports the published-code change. No unrelated changes were found in the summary. No dependency or test changes appear in the summary.
Finishing Touches
Generate unit tests (beta)
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.
Reviewing files that changed from the base of the PR and between 10b22c2 and 4ea7a3e.
Files selected for processing: 2
.changeset/react-use-in-guard.md
packages/react-router/src/utils.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
This branch has not been deployed
No deployments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🎯 Changes
Fixes #7538.
The build folds
let REACT_USE = 'use'away, so the published ESM shipsReact$1["use"]. Rspack and webpack treat that as a static import ofuse, which React 18 doesn't export, so production builds fail:This guards the lookup with
ininstead:Both bundlers recognize an
inguard and skip the export check (webpack 5.105+ via webpack/webpack#20320, Rspack 2.1+ via web-infra-dev/rspack#14426). The build emits it unchanged, so nothing is left to constant-fold.✅ Checklist
Tested:
@tanstack/react-routerunit tests, ESLint, andtest:typeson TS 5.6–7.0.utils.jspatched into 1.170.46:reactUseisundefined.reactUseisReact.use.🚀 Release Impact
Written with AI assistance and reviewed by me.
Summary by CodeRabbit
useexport in production builds with React 18 and Rspack or webpack.