Skip to content

Commit

Permalink
fix: skip react-server hmr for client reference
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Apr 10, 2024
1 parent 87def96 commit ee64988
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions examples/react-server/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,18 @@ function vitePluginReactServer(): PluginOption {
ids,
invalidated: [...invalidated],
});
console.log("[react-server:hmr]", ctx.file);
__global.server.environments.client.hot.send({
type: "custom",
event: "react-server:update",
data: {
file: ctx.file,
},
});
// client reference id is also in react server module graph,
// but we skip RSC HMR for this case since Client HMR handles it.
if (!ids.some((id) => manager.clientReferences.has(id))) {
console.log("[react-server:hmr]", ctx.file);
__global.server.environments.client.hot.send({
type: "custom",
event: "react-server:update",
data: {
file: ctx.file,
},
});
}
return [];
}
}
Expand All @@ -132,6 +136,7 @@ function vitePluginUseClient(): PluginOption {
const transformPlugin: Plugin = {
name: vitePluginUseClient.name + ":transform",
async transform(code, id, _options) {
manager.clientReferences.delete(id);
if (this.environment?.name === "react-server") {
if (/^("use client")|('use client')/.test(code)) {
manager.clientReferences.add(id);
Expand Down

0 comments on commit ee64988

Please sign in to comment.