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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/crazy-books-kiss.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'rsbuild-plugin-react-router': patch
---

Fix: Correctly expose routeDiscovery configuration for React Router v7 in Rspack builds.
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ export const pluginReactRouter = (
return {} as Config;
});

// Set default routeDiscovery configuration
const routeDiscovery = { mode: 'lazy', manifestPath: '/__manifest' } as const;

const routesPath = findEntryFile(resolve(appDirectory, 'routes'));

// Then read the routes
Expand Down Expand Up @@ -175,6 +178,7 @@ export const pluginReactRouter = (
appDirectory,
ssr,
federation: options.federation,
routeDiscovery,
}),
'virtual/react-router/with-props': generateWithProps(),
});
Expand Down
29 changes: 29 additions & 0 deletions src/server-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ function generateAsyncTemplate(
basename: string;
appDirectory: string;
ssr: boolean;
routeDiscovery:
| {
mode: 'lazy';
manifestPath?: string;
}
| {
mode: 'initial';
}
| undefined;
}
): string {
return `
Expand Down Expand Up @@ -82,6 +91,7 @@ function generateAsyncTemplate(
export const future = ${JSON.stringify({})};
export const isSpaMode = ${!options.ssr};
export const ssr = ${options.ssr};
export const routeDiscovery = ${JSON.stringify(options.routeDiscovery)};
export const publicPath = "/";
export const prerender = [];
export const entry = { module: entryServer };
Expand Down Expand Up @@ -115,6 +125,15 @@ function generateStaticTemplate(
basename: string;
appDirectory: string;
ssr: boolean;
routeDiscovery:
| {
mode: 'lazy';
manifestPath?: string;
}
| {
mode: 'initial';
}
| undefined;
}
): string {
return `
Expand All @@ -136,6 +155,7 @@ function generateStaticTemplate(
export const future = ${JSON.stringify({})};
export const isSpaMode = ${!options.ssr};
export const ssr = ${options.ssr};
export const routeDiscovery = ${JSON.stringify(options.routeDiscovery)};
export const prerender = [];
export const publicPath = "/";
export const entry = { module: entryServer };
Expand Down Expand Up @@ -173,6 +193,15 @@ function generateServerBuild(
appDirectory: string;
ssr: boolean;
federation?: boolean;
routeDiscovery:
| {
mode: 'lazy';
manifestPath?: string;
}
| {
mode: 'initial';
}
| undefined;
}
): string {
return options.federation
Expand Down