fix: correctly expose routeDiscovery configuration for React Router v7 #25
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.
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 thevirtual/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 thevirtual/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:
✓ 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