Skip to content

fix: correctly expose routeDiscovery configuration for React Router v7 #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

anggihseptiawan
Copy link

@anggihseptiawan anggihseptiawan commented May 24, 2025

This PR aims to fix this issue #24

Issue:
The rsbuild-plugin-react-router failed to correctly provide the necessary route manifest information for React Router v7 when building with Rspack. This resulted in a TypeError: Cannot read properties of undefined (reading 'manifestPath') in the React Router consumer code, as the required routeDiscovery configuration was missing at runtime.

Root Cause:
The routeDiscovery configuration object, which contains essential information like manifestPath for React Router's data routers, was not being properly provided to generateServerBuild function to construct the virtual/react-router/server-build module within the rsbuild-plugin-react-router. Although routeDiscovery was intended to be part of the configuration flow, it was missing from the data ultimately consumed by the virtual module's export logic.

Solution:
The fix ensures that the routeDiscovery object is correctly passed into the generateServerBuild function that drives the generation of the virtual/react-router/server-build module. Furthermore, the routeDiscovery object is now explicitly exported as a const from this virtual module, using JSON.stringify() for proper serialization. This makes the routeDiscovery configuration fully accessible to the React Router consumer, resolving the TypeError and enabling the correct functioning of data routers and their associated features.

Test Result:

rsbuild-plugin-react-router@0.0.4 test
vitest run

✓ tests/index.test.ts (4 tests) 3ms
✓ tests/features.test.ts (8 tests) 7ms

Snapshots 6 obsolete
↳ tests/index.test.ts
· plugins/react > should configuring tools.swc to override react runtime 1
· plugins/react > should not apply splitChunks rule when strategy is not split-by-experience 1
· plugins/react > should work with swc-loader 1
↳ tests/features.test.ts
· splitChunks > should apply antd/semi/... splitChunks rule when pkg is installed 1
· splitChunks > should apply splitChunks.react/router plugin option when strategy is split-by-experience 1
· splitChunks > should not apply splitChunks rule when strategy is not split-by-experience 1

Test Files 2 passed (2)
Tests 12 passed (12)
Start at 11:33:05
Duration 530ms (transform 89ms, setup 46ms, collect 541ms, tests 10ms, environment 0ms, prepare 105ms)

rsbuild-plugin-react-router.mp4

@yf-yang
Copy link

yf-yang commented Jul 5, 2025

@ScriptedAlchemy Would you mind taking a look?

@ScriptedAlchemy
Copy link
Collaborator

Yes sorry. Will merge and release

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.

3 participants