Skip to content

Commit

Permalink
fix: make handleInvoke interface compatible with invoke (#18876)
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red authored Dec 5, 2024
1 parent ea802f8 commit a1dd396
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions packages/vite/src/node/server/hmr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export interface NormalizedHotChannel<Api = any> {
off(event: string, listener: Function): void
/** @internal */
setInvokeHandler(invokeHandlers: InvokeMethods | undefined): void
handleInvoke(payload: HotPayload): Promise<{ r: any } | { e: any }>
handleInvoke(payload: HotPayload): Promise<{ result: any } | { error: any }>
/**
* Start listening for messages
*/
Expand Down Expand Up @@ -301,7 +301,13 @@ export const normalizeHotChannel = (
}
channel.on?.('vite:invoke', listenerForInvokeHandler)
},
handleInvoke,
handleInvoke: async (payload) => {
const data = await handleInvoke(payload)
if (data.e) {
return { error: data.e }
}
return { result: data.r }
},
send: (...args: any[]) => {
let payload: HotPayload
if (typeof args[0] === 'string') {
Expand Down Expand Up @@ -1161,7 +1167,7 @@ export function createDeprecatedHotBroadcaster(
send: ws.send,
setInvokeHandler: ws.setInvokeHandler,
handleInvoke: async () => ({
e: {
error: {
name: 'TransportError',
message: 'handleInvoke not implemented',
stack: new Error().stack,
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/server/ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export function createWebSocketServer(
off: noop as any as WebSocketServer['off'],
setInvokeHandler: noop,
handleInvoke: async () => ({
e: {
error: {
name: 'TransportError',
message: 'handleInvoke not implemented',
stack: new Error().stack,
Expand Down

0 comments on commit a1dd396

Please sign in to comment.