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

fix(react-router): guard React.use lookup with an in check - #9011

Open
hai-x wants to merge 1 commit into
TanStack:mainfrom
hai-x:fix/react-use-in-guard
Open

hai-x wants to merge 1 commit into
TanStack:mainfrom
hai-x:fix/react-use-in-guard

Conversation

@hai-x

@hai-x hai-x commented Nov 27, 2026 •

Copy link
Copy Markdown

🎯 Changes

Fixes #7538.

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'

This guards the lookup with in instead:

export const reactUse = 'use' in React ? React.use : undefined

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.

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

Tested:

  • @tanstack/react-router unit tests, ESLint, and test:types on TS 5.6–7.0.
  • Production builds with Rspack 2.3.3 and webpack 5.113, using the new utils.js patched into 1.170.46:
    • React 18.3.1: both build; reactUse is undefined.
    • React 19: both build; reactUse is React.use.

🚀 Release Impact

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

Written with AI assistance and reviewed by me.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed errors involving React’s use export in production builds with React 18 and Rspack or webpack.

@changeset-bot

changeset-bot Bot commented Nov 27, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4ea7a3e

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

This PR includes changesets to release 5 packages
Name Type
@tanstack/react-router Patch
@tanstack/react-start-client Patch
@tanstack/react-start-rsc Patch
@tanstack/react-start-server Patch
@tanstack/react-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

@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

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.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested labels: package: react-router

Suggested reviewers: schiller-manuel

Merge Risk: Minimal · up to 4ea7a

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: Passed 4

Check name Status Explanation
Title check Passed 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 Passed 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 Passed 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 Passed 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.

Share

Recent review info

Run configuration

Commits

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant