Skip to content

Commit ce50bd4

Browse files
authored
docs(migration): note ssr-only module reload (#18755)
1 parent cf5028d commit ce50bd4

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

docs/guide/migration.md

+47
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,53 @@ There are other breaking changes which only affect few users.
101101
- This opt-in optimization was removed due to edge cases when writing a file in a cached folder and immediately importing it.
102102
- [[#18697] fix(deps)!: update dependency dotenv-expand to v12](https://github.com/vitejs/vite/pull/18697)
103103
- Variables used in interpolation should be declared before the interpolation now. For more details, see [the `dotenv-expand` changelog](https://github.com/motdotla/dotenv-expand/blob/v12.0.1/CHANGELOG.md#1200-2024-11-16).
104+
- [[#16471] feat: v6 - Environment API](https://github.com/vitejs/vite/pull/16471)
105+
106+
- Updates to an SSR-only module no longer triggers a full page reload in the client. To return to the previous behaviour, a custom Vite plugin can be used:
107+
<details>
108+
<summary>Click to expand example</summary>
109+
110+
```ts twoslash
111+
import type { Plugin, EnvironmentModuleNode } from 'vite'
112+
113+
function hmrReload(): Plugin {
114+
return {
115+
name: 'hmr-reload',
116+
enforce: 'post',
117+
hotUpdate: {
118+
order: 'post',
119+
handler({ modules, server, timestamp }) {
120+
if (this.environment.name !== 'ssr') return
121+
122+
let hasSsrOnlyModules = false
123+
124+
const invalidatedModules = new Set<EnvironmentModuleNode>()
125+
for (const mod of modules) {
126+
if (mod.id == null) continue
127+
const clientModule =
128+
server.environments.client.moduleGraph.getModuleById(mod.id)
129+
if (clientModule != null) continue
130+
131+
this.environment.moduleGraph.invalidateModule(
132+
mod,
133+
invalidatedModules,
134+
timestamp,
135+
true,
136+
)
137+
hasSsrOnlyModules = true
138+
}
139+
140+
if (hasSsrOnlyModules) {
141+
server.ws.send({ type: 'full-reload' })
142+
return []
143+
}
144+
},
145+
},
146+
}
147+
}
148+
```
149+
150+
</details>
104151

105152
## Migration from v4
106153

0 commit comments

Comments
 (0)