Skip to content

Conversation

@schiller-manuel
Copy link
Contributor

@schiller-manuel schiller-manuel commented Jan 10, 2026

… errors with React 18

fixes #6332

Summary by CodeRabbit

  • Refactor
    • Improved internal handling of component suspension and lazy loading mechanisms for enhanced compatibility.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 10, 2026

📝 Walkthrough

Walkthrough

This PR resolves a Webpack build failure occurring with React 18 by replacing direct React.use references with a new reactUse utility that safely accesses the hook via dynamic property lookup. The utility only exposes React.use when available (React 19+), preventing static analysis issues. The existing defer-based fallback logic remains intact.

Changes

Cohort / File(s) Summary
New React.use utility
packages/react-router/src/utils.ts
Introduces reactUse export that safely accesses React.use through dynamic property access using the REACT_USE constant, returning undefined if unavailable. Avoids Webpack static analysis issues with React 18.
Hook consumption updates
packages/react-router/src/awaited.tsx, packages/react-router/src/lazyRouteComponent.tsx
Both files updated to import and use reactUse instead of direct React.use invocation. Conditional logic unchanged; only the hook invocation mechanism is substituted.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Suggested labels

package: react-router

Poem

A webpack wise rabbit once said with cheer,
"Dynamic access keeps React.use clear!"
No static snags, just runtime grace,
React 18 and 19 both have their place. 🐰✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly addresses the main change: implementing safe dynamic lookup for React.use to avoid compilation errors with React 18, which matches the core purpose of the PR.
Linked Issues check ✅ Passed The PR successfully addresses the compilation error reported in issue #6332 by implementing dynamic property access to React.use via a utility function, preventing Webpack from statically analyzing the non-existent export in React 18.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the React.use compilation issue: creating a reactUse utility and replacing direct React.use calls with dynamic lookup. No unrelated modifications are present.

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

✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fad5fdb and 60fc9a7.

📒 Files selected for processing (3)
  • packages/react-router/src/awaited.tsx
  • packages/react-router/src/lazyRouteComponent.tsx
  • packages/react-router/src/utils.ts
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Use TypeScript strict mode with extensive type safety for all code

Files:

  • packages/react-router/src/lazyRouteComponent.tsx
  • packages/react-router/src/awaited.tsx
  • packages/react-router/src/utils.ts
**/*.{js,ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Implement ESLint rules for router best practices using the ESLint plugin router

Files:

  • packages/react-router/src/lazyRouteComponent.tsx
  • packages/react-router/src/awaited.tsx
  • packages/react-router/src/utils.ts
🧠 Learnings (1)
📚 Learning: 2025-12-17T02:17:55.086Z
Learnt from: schiller-manuel
Repo: TanStack/router PR: 6120
File: packages/router-generator/src/generator.ts:654-657
Timestamp: 2025-12-17T02:17:55.086Z
Learning: In `packages/router-generator/src/generator.ts`, pathless_layout routes must receive a `path` property when they have a `cleanedPath`, even though they are non-path routes. This is necessary because child routes inherit the path from their parent, and without this property, child routes would not have the correct full path at runtime.

Applied to files:

  • packages/react-router/src/lazyRouteComponent.tsx
🧬 Code graph analysis (2)
packages/react-router/src/lazyRouteComponent.tsx (1)
packages/react-router/src/utils.ts (1)
  • reactUse (13-15)
packages/react-router/src/awaited.tsx (1)
packages/react-router/src/utils.ts (1)
  • reactUse (13-15)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Test
  • GitHub Check: Preview
🔇 Additional comments (5)
packages/react-router/src/utils.ts (1)

3-15: Excellent solution to the Webpack static analysis issue!

The dynamic string lookup approach elegantly solves the React 18 compilation problem while maintaining type safety. The implementation correctly:

  • Avoids Webpack's static import analysis by using (React as any)[REACT_USE]
  • Provides accurate typing that matches React 19's use signature
  • Returns undefined gracefully when React.use isn't available (React 18)
  • Includes clear documentation explaining the rationale

This pattern effectively enables React 19 features while maintaining backward compatibility.

packages/react-router/src/awaited.tsx (2)

4-4: Clean integration of the reactUse utility.

The import is correctly placed and prepares the file for the conditional usage below.


12-15: Well-implemented conditional logic with proper fallback.

The conditional check correctly uses reactUse when available (React 19+) and falls back to the existing defer-based suspension mechanism for React 18. This maintains backward compatibility while enabling the newer, more efficient React 19 hook when present. The behavior is identical in both paths: suspending until the promise resolves and returning the data.

packages/react-router/src/lazyRouteComponent.tsx (2)

3-3: Correct import addition.

The reactUse utility is imported to enable conditional usage of React 19's use hook in the lazy component render path.


83-87: Proper conditional hook usage with fallback.

The implementation correctly uses reactUse(load()) when available and falls back to throw load() for React 18. Both approaches achieve the same suspension behavior:

  • React 19+: reactUse internally suspends the component until the promise resolves
  • React 18: throwing the promise triggers the nearest Suspense boundary

This maintains consistent lazy-loading behavior across React versions while fixing the Webpack compilation issue.


Comment @coderabbitai help to get the list of available commands and usage tips.

@nx-cloud
Copy link

nx-cloud bot commented Jan 10, 2026

View your CI Pipeline Execution ↗ for commit 60fc9a7

Command Status Duration Result
nx affected --targets=test:eslint,test:unit,tes... ✅ Succeeded 18m 51s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 59s View ↗

☁️ Nx Cloud last updated this comment at 2026-01-10 23:28:04 UTC

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 10, 2026

More templates

@tanstack/arktype-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/arktype-adapter@6355

@tanstack/eslint-plugin-router

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

@tanstack/history

npm i https://pkg.pr.new/TanStack/router/@tanstack/history@6355

@tanstack/nitro-v2-vite-plugin

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

@tanstack/react-router

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

@tanstack/react-router-devtools

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

@tanstack/react-router-ssr-query

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

@tanstack/react-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start@6355

@tanstack/react-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-client@6355

@tanstack/react-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server@6355

@tanstack/router-cli

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

@tanstack/router-core

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

@tanstack/router-devtools

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

@tanstack/router-devtools-core

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

@tanstack/router-generator

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

@tanstack/router-plugin

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

@tanstack/router-ssr-query-core

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

@tanstack/router-utils

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

@tanstack/router-vite-plugin

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

@tanstack/solid-router

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

@tanstack/solid-router-devtools

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

@tanstack/solid-router-ssr-query

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

@tanstack/solid-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start@6355

@tanstack/solid-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-client@6355

@tanstack/solid-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server@6355

@tanstack/start-client-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-client-core@6355

@tanstack/start-fn-stubs

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-fn-stubs@6355

@tanstack/start-plugin-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-plugin-core@6355

@tanstack/start-server-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-core@6355

@tanstack/start-static-server-functions

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

@tanstack/start-storage-context

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-storage-context@6355

@tanstack/valibot-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/valibot-adapter@6355

@tanstack/virtual-file-routes

npm i https://pkg.pr.new/TanStack/router/@tanstack/virtual-file-routes@6355

@tanstack/vue-router

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

@tanstack/vue-router-devtools

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

@tanstack/vue-router-ssr-query

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

@tanstack/vue-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-start@6355

@tanstack/vue-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-start-client@6355

@tanstack/vue-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-start-server@6355

@tanstack/zod-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/zod-adapter@6355

commit: 60fc9a7

@schiller-manuel schiller-manuel merged commit 2e2c868 into main Jan 10, 2026
6 checks passed
@schiller-manuel schiller-manuel deleted the fix-6332 branch January 10, 2026 23:36
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.

React.use build error with React 18 and Webpack

2 participants