-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: vite 6 breaking change for ssr module hmr, add migration plugin
- Loading branch information
1 parent
eb128d7
commit b0026e4
Showing
3 changed files
with
45 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import type { Plugin, EnvironmentModuleNode } from 'vite'; | ||
|
||
// NOTE: From https://vite.dev/guide/migration#advanced (Vite 5>6 migration). | ||
export function hmrSsrReload(): Plugin { | ||
return { | ||
name: 'vite-plugin-gracile-hmr-ssr-reload', | ||
enforce: 'post', | ||
|
||
hotUpdate: { | ||
order: 'post', | ||
|
||
handler({ modules, server, timestamp }) { | ||
if (this.environment.name !== 'ssr') return; | ||
|
||
let hasSsrOnlyModules = false; | ||
|
||
const invalidatedModules = new Set<EnvironmentModuleNode>(); | ||
for (const module_ of modules) { | ||
if (module_.id == null) continue; | ||
const clientModule = | ||
server.environments.client.moduleGraph.getModuleById(module_.id); | ||
if (clientModule != null) continue; | ||
|
||
this.environment.moduleGraph.invalidateModule( | ||
module_, | ||
invalidatedModules, | ||
timestamp, | ||
true, | ||
); | ||
hasSsrOnlyModules = true; | ||
} | ||
|
||
if (hasSsrOnlyModules) { | ||
server.ws.send({ type: 'full-reload' }); | ||
return []; | ||
} | ||
}, | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters