Skip to content

Commit

Permalink
fix: apply changes from vite 6 compat (#632)
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa authored Aug 29, 2024
1 parent 40640e5 commit 28356c6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
10 changes: 9 additions & 1 deletion packages/react-server/src/features/assets/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ export function vitePluginServerAssets({

createVirtualPlugin(DEV_SSR_CSS.split(":")[1]!, async () => {
tinyassert(!manager.buildType);
// normalize it again to workaround inconsistent hmr path issue
// https://github.com/hi-ogawa/reproductions/tree/main/vite-v6-hmr-path
const root = manager.config.root;
const clientReferences = [...manager.clientReferenceMap.keys()].map(
(file) => {
return file.startsWith(root) ? file.slice(root.length) : file;
},
);
const styles = await Promise.all([
`/******* react-server ********/`,
collectStyle($__global.dev.reactServer, {
Expand All @@ -107,7 +115,7 @@ export function vitePluginServerAssets({
entryBrowser,
"virtual:client-routes",
// TODO: dev should also use RouteManifest to manage client css
...manager.clientReferenceMap.keys(),
...clientReferences,
],
ssr: false,
}),
Expand Down
3 changes: 3 additions & 0 deletions packages/react-server/src/plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ export function vitePluginReactServer(
clearScreen: false,
configFile: false,
cacheDir: "./node_modules/.vite-rsc",
server: {
middlewareMode: true,
},
optimizeDeps: {
noDiscovery: true,
include: [],
Expand Down
7 changes: 5 additions & 2 deletions packages/react-server/src/plugin/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ export function hashString(v: string) {
.slice(0, 10);
}

export function createVirtualPlugin(name: string, load: Plugin["load"]) {
export function createVirtualPlugin(
name: string,
load: Plugin["load"],
): Plugin {
name = "virtual:" + name;
return {
name: `virtual-${name}`,
Expand All @@ -46,7 +49,7 @@ export function createVirtualPlugin(name: string, load: Plugin["load"]) {
return (load as any).apply(this, [id, options]);
}
},
} satisfies Plugin;
};
}

// silence warning due to "use ..." directives
Expand Down

0 comments on commit 28356c6

Please sign in to comment.