Skip to content

Commit d3a1277

Browse files
committed
fix(shelf): prevent rspack client clean from deleting server output and guard vite middleware against ssrLoadModule failures
- Rspack client: change output.clean from true to { keep: /^server\// } so the client compiler's clean pass preserves the server bundle in dist-rspack/server/. - Vite middleware: try/catch the load() call (which runs ssrLoadModule in dev) and fall through to next() on failure, so a broken server module does not block Vite's own requests (/@vite/client, HMR, transforms). The request body conversion is deferred until after a successful load.
1 parent a83e340 commit d3a1277

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

‎examples/shelf/rspack.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ const configs = [
6262
path: out,
6363
filename: 'static/[name].[contenthash:8].js',
6464
publicPath: '/',
65-
clean: true,
65+
clean: { keep: /^server\// },
6666
},
6767
module: { rules: [...rules, { test: /\.css$/, type: 'css/auto' }] },
6868
plugins: [

‎examples/shelf/vite.config.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,15 @@ function shelfServer(): Plugin {
2121
const middleware =
2222
(load: () => Promise<ShelfServer>, template: (file: string, url: URL) => Promise<string>) =>
2323
async (request: IncomingMessage, response: ServerResponse, next: () => void) => {
24+
let server: ShelfServer;
25+
try {
26+
server = await load();
27+
} catch {
28+
return next();
29+
}
2430
const incoming = nodeRequestToWebRequest(request, response);
2531
const url = new URL(incoming.url);
26-
const reply = await (await load()).fetch(incoming, (file) => template(file, url));
32+
const reply = await server.fetch(incoming, (file) => template(file, url));
2733
if (reply) await sendWebResponse(response, reply);
2834
else next();
2935
};

0 commit comments

Comments
 (0)