Skip to content

Commit 305f6d6

Browse files
fix(dev/vite): remove stale server build when ssr:false
The buildApp post-handler that deletes serverBuildDirectory was commented out in 75de31f, leaving build/server/index.js behind. Reactivate it with async rm and fallback to getServerBuildDirectory for non-standard outDir layouts. Fixes #15305.
1 parent 1fd704a commit 305f6d6

1 file changed

Lines changed: 17 additions & 13 deletions

File tree

packages/react-router-dev/vite/plugin.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,19 +1359,23 @@ export const reactRouterVitePlugin: ReactRouterVitePlugin = () => {
13591359
},
13601360
};
13611361
},
1362-
// buildApp: {
1363-
// order: "post",
1364-
// handler: async (builder) => {
1365-
// let { reactRouterConfig } = ctx;
1366-
1367-
// let serverBuildDirectory =
1368-
// builder.environments.ssr.config?.build?.outDir;
1369-
// if (serverBuildDirectory && !reactRouterConfig.ssr) {
1370-
// // For both SPA mode and prerendering, we can remove the server builds
1371-
// rmSync(serverBuildDirectory, { force: true, recursive: true });
1372-
// }
1373-
// },
1374-
// },
1362+
buildApp: {
1363+
order: "post",
1364+
handler: async (builder) => {
1365+
let { reactRouterConfig } = ctx;
1366+
1367+
let serverBuildDirectory =
1368+
builder.environments.ssr?.config?.build?.outDir ??
1369+
getServerBuildDirectory(reactRouterConfig);
1370+
if (serverBuildDirectory && !reactRouterConfig.ssr) {
1371+
// For both SPA mode and prerendering, we can remove the server builds
1372+
// since there is no runtime server. The cleaner version of this was
1373+
// commented out in 75de31f but the `build/server/index.js` artifact
1374+
// was left behind (see https://github.com/remix-run/react-router/issues/15305).
1375+
await rm(serverBuildDirectory, { force: true, recursive: true });
1376+
}
1377+
},
1378+
},
13751379
configEnvironment(name, options) {
13761380
if (isReactRouterServerEnvironment(ctx, name)) {
13771381
const vite = getVite();

0 commit comments

Comments
 (0)