Skip to content

Commit 89d1d87

Browse files
committed
docs(migration): note ssr-only module reload
1 parent 74079f7 commit 89d1d87

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

guide/migration.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,53 @@ Vite 5 のように `style.css` を使い続けたい場合は、代わりに `b
101101
- キャッシュフォルダにファイルを書き込んですぐにインポートするといったエッジケースのために、このオプトイン最適化は削除されました。
102102
- [[#18697] fix(deps)!: update dependency dotenv-expand to v12](https://github.com/vitejs/vite/pull/18697)
103103
- 補間に使用される変数は、補間の実行前に宣言する必要があるようになりました。詳しくは、[`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+
- SSR 専用モジュールの更新がクライアント側でページ全体のリロードを引き起こすことはなくなりました。以前の動作に戻すには、カスタム Vite プラグインを使用できます:
107+
<details>
108+
<summary>クリックして例を表示</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
## v4 からの移行
106153

0 commit comments

Comments
 (0)