fix(react-router-dom-v6): polish react-router-dom#3125
Conversation
There was a problem hiding this comment.
Pull request overview
Updates Rspress SSR/SSG-MD runtime to import StaticRouter via a bundler alias so it works across react-router-dom v6 (server subpath) and v7 (main entry), and wires that alias through the rsbuild/rspack alias resolver.
Changes:
- Switch SSR/SSG-MD server entries to import
StaticRouterfromREACT_ROUTER_DOM_SERVERinstead ofreact-router-dom. - Extend
resolveReactRouterDomAlias()to provide aREACT_ROUTER_DOM_SERVERalias that points toserver.mjsfor react-router-dom v6. - Minor refactor in alias resolution (naming/typing, computed router-dom dir).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| packages/core/src/runtime/ssrServerEntry.tsx | Swap StaticRouter import to a new alias-based module ID for SSR compatibility. |
| packages/core/src/runtime/ssrMdServerEntry.tsx | Same alias-based StaticRouter import change for markdown SSR/SSG-MD entry (but introduces a TS directive issue). |
| packages/core/src/node/utils/reactAlias.ts | Add alias mapping for REACT_ROUTER_DOM_SERVER based on detected react-router-dom major version. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -1,5 +1,8 @@ | |||
| // biome-ignore lint/suspicious/noTsIgnore: bundleless | |||
| // @ts-ignore | |||
| // @ts-expect-error | |||
There was a problem hiding this comment.
There is a standalone // @ts-expect-error directive followed by a blank line, so it won’t apply to the import below and will likely trigger TypeScript’s “Unused '@ts-expect-error' directive” error. Remove this directive (or move it to directly precede the specific line that errors with no blank line).
| // @ts-expect-error |
| @@ -1,5 +1,8 @@ | |||
| // biome-ignore lint/suspicious/noTsIgnore: bundleless | |||
There was a problem hiding this comment.
The biome-ignore lint/suspicious/noTsIgnore comment no longer matches the code (this file now uses @ts-expect-error, not @ts-ignore). Either remove the Biome ignore or update it to the relevant rule to avoid carrying stale lint suppressions.
| // biome-ignore lint/suspicious/noTsIgnore: bundleless | |
| // biome-ignore lint/suspicious/noTsExpectError: bundleless |
| @@ -1,3 +1,5 @@ | |||
| // @ts-expect-error in v7, StaticRouter is exported from the main entry, but in v6 it's exported from 'react-router-dom/server' | |||
There was a problem hiding this comment.
The @ts-expect-error explanation mentions v6/v7 export differences, but the actual TypeScript error being suppressed here is most likely that REACT_ROUTER_DOM_SERVER is a bundler alias/virtual module that TS can’t resolve. Consider adding an ambient module declaration for REACT_ROUTER_DOM_SERVER (preferred), or update the directive comment to reflect the real error being suppressed.
| // @ts-expect-error in v7, StaticRouter is exported from the main entry, but in v6 it's exported from 'react-router-dom/server' | |
| declare module 'REACT_ROUTER_DOM_SERVER' { | |
| export { StaticRouter } from 'react-router-dom/server'; | |
| } | |
| // Bundler alias for StaticRouter to handle react-router-dom v6/v7 differences |
| // we create a shim that re-exports everything from the main entry plus | ||
| // StaticRouter from the server subpath. |
There was a problem hiding this comment.
The comment says “we create a shim that re-exports everything from the main entry plus StaticRouter from the server subpath”, but the implementation only creates an alias to server.mjs (no shim/re-export layer). Either implement the described shim, or update the comment to accurately describe the alias behavior so future readers aren’t misled.
| // we create a shim that re-exports everything from the main entry plus | |
| // StaticRouter from the server subpath. | |
| // we resolve 'react-router-dom' to its package directory and add a | |
| // separate alias pointing directly to the 'server.mjs' entry when present. |
Summary
Related Issue
Checklist