Skip to content

Commit 367d2b0

Browse files
authoredFeb 28, 2025··
feat(dev-server): add handleHotUpdate option (#235)
* feat(dev-server): add `handleHotUpdate` option * add changeset
1 parent abb8f2c commit 367d2b0

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed
 

‎.changeset/spotty-ads-design.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@hono/vite-dev-server': minor
3+
---
4+
5+
feat: add `handleHotUpdate` option

‎packages/dev-server/README.md

+8
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ export type DevServerOptions = {
107107
env?: Env
108108
onServerClose?: () => Promise<void>
109109
}
110+
handleHotUpdate?: VitePlugin['handleHotUpdate']
110111
}
111112
```
112113
@@ -127,6 +128,13 @@ export const defaultOptions: Required<Omit<DevServerOptions, 'cf'>> = {
127128
/^\/node_modules\/.*/,
128129
],
129130
ignoreWatching: [/\.wrangler/],
131+
handleHotUpdate: ({ server, modules }) => {
132+
const isSSR = modules.some((mod) => mod._ssrModule)
133+
if (isSSR) {
134+
server.hot.send({ type: 'full-reload' })
135+
return []
136+
}
137+
},
130138
}
131139
```
132140

‎packages/dev-server/src/dev-server.ts

+11-9
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export type DevServerOptions = {
4343
*
4444
*/
4545
adapter?: Adapter | Promise<Adapter> | (() => Adapter | Promise<Adapter>)
46+
handleHotUpdate?: VitePlugin['handleHotUpdate']
4647
}
4748

4849
export const defaultOptions: Required<Omit<DevServerOptions, 'env' | 'adapter' | 'loadModule'>> = {
@@ -60,6 +61,15 @@ export const defaultOptions: Required<Omit<DevServerOptions, 'env' | 'adapter' |
6061
/^\/node_modules\/.*/,
6162
],
6263
ignoreWatching: [/\.wrangler/, /\.mf/],
64+
handleHotUpdate: ({ server, modules }) => {
65+
// Force reload the page if any of the modules is SSR
66+
const isSSR = modules.some((mod) => mod._ssrModule)
67+
if (isSSR) {
68+
server.hot.send({ type: 'full-reload' })
69+
return []
70+
}
71+
// Apply HMR for the client-side modules
72+
},
6373
}
6474

6575
export function devServer(options?: DevServerOptions): VitePlugin {
@@ -208,15 +218,7 @@ export function devServer(options?: DevServerOptions): VitePlugin {
208218
}
209219
})
210220
},
211-
handleHotUpdate({ server, modules }) {
212-
// Force reload the page if any of the modules is SSR
213-
const isSSR = modules.some((mod) => mod._ssrModule)
214-
if (isSSR) {
215-
server.hot.send({ type: 'full-reload' })
216-
return []
217-
}
218-
// Apply HMR for the client-side modules
219-
},
221+
handleHotUpdate: options?.handleHotUpdate ?? defaultOptions.handleHotUpdate,
220222
config: () => {
221223
return {
222224
server: {

0 commit comments

Comments
 (0)
Please sign in to comment.