Skip to content

Commit aec7f73

Browse files
committed
fix(vite): compatible with vite4 for messaging
1 parent d45ed17 commit aec7f73

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

packages/core/src/vite-bridge/client.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@ export function callViteServerAction<T>(name: string) {
2121
const uniqueEventKey = nanoid()
2222
return new Promise<T>((resolve) => {
2323
const cb = (e: T) => {
24-
viteClient.off(uniqueEventKey, cb)
24+
if (viteClient.off)
25+
viteClient.off(uniqueEventKey, cb)
26+
27+
else
28+
// compatible with vite 4.x
29+
viteClient.dispose?.(cb)
30+
2531
resolve(e)
2632
}
2733
viteClient.on(uniqueEventKey, cb)
@@ -38,7 +44,12 @@ export function defineViteClientListener(name: string) {
3844
const viteClient = getViteClientHotContext()
3945
viteClient.on(name, listener)
4046
return () => {
41-
viteClient.off(name, listener)
47+
if (viteClient.off)
48+
viteClient.off(name, listener)
49+
50+
else
51+
// compatible with vite 4.x
52+
viteClient.dispose?.(listener)
4253
}
4354
}
4455
}

0 commit comments

Comments
 (0)