Skip to content

Commit 7c328d5

Browse files
authored
Limit scope of bun react-dom/server hack (#5532)
Some upstream js packages may have a legitimate need to use `react-dom/server` on the client side, which is valid. To ensure this works, only force `react-dom/server.node` for the entry.server.js where the bun/node issue exists.
1 parent 4a765ea commit 7c328d5

1 file changed

Lines changed: 27 additions & 6 deletions

File tree

reflex/.templates/web/vite.config.js

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,33 @@ import { reactRouter } from "@react-router/dev/vite";
33
import { defineConfig } from "vite";
44
import safariCacheBustPlugin from "./vite-plugin-safari-cachebust";
55

6+
// Ensure that bun always uses the react-dom/server.node functions.
7+
function alwaysUseReactDomServerNode() {
8+
return {
9+
name: "vite-plugin-always-use-react-dom-server-node",
10+
enforce: "pre",
11+
12+
resolveId(source, importer) {
13+
if (
14+
typeof importer === "string" &&
15+
importer.endsWith("/entry.server.node.tsx") &&
16+
source.includes("react-dom/server")
17+
) {
18+
return this.resolve("react-dom/server.node", importer, {
19+
skipSelf: true,
20+
});
21+
}
22+
return null;
23+
},
24+
};
25+
}
26+
627
export default defineConfig((config) => ({
7-
plugins: [reactRouter(), safariCacheBustPlugin()],
28+
plugins: [
29+
alwaysUseReactDomServerNode(),
30+
reactRouter(),
31+
safariCacheBustPlugin(),
32+
],
833
build: {
934
rollupOptions: {
1035
jsx: {},
@@ -30,10 +55,6 @@ export default defineConfig((config) => ({
3055
find: "@",
3156
replacement: fileURLToPath(new URL("./public", import.meta.url)),
3257
},
33-
].concat(
34-
config.command === "build"
35-
? [{ find: "react-dom/server", replacement: "react-dom/server.node" }]
36-
: [],
37-
),
58+
],
3859
},
3960
}));

0 commit comments

Comments
 (0)