Skip to content

Commit

Permalink
fix(vite): compatible with vite4 for messaging
Browse files Browse the repository at this point in the history
  • Loading branch information
webfansplz committed Mar 22, 2024
1 parent d45ed17 commit aec7f73
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions packages/core/src/vite-bridge/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ export function callViteServerAction<T>(name: string) {
const uniqueEventKey = nanoid()
return new Promise<T>((resolve) => {
const cb = (e: T) => {
viteClient.off(uniqueEventKey, cb)
if (viteClient.off)
viteClient.off(uniqueEventKey, cb)

else
// compatible with vite 4.x
viteClient.dispose?.(cb)

resolve(e)
}
viteClient.on(uniqueEventKey, cb)
Expand All @@ -38,7 +44,12 @@ export function defineViteClientListener(name: string) {
const viteClient = getViteClientHotContext()
viteClient.on(name, listener)
return () => {
viteClient.off(name, listener)
if (viteClient.off)
viteClient.off(name, listener)

else
// compatible with vite 4.x
viteClient.dispose?.(listener)
}
}
}

0 comments on commit aec7f73

Please sign in to comment.