Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 }
},
Comment on lines +304 to +310
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason we don't want handleInvoke to return complete error or result directly too? IIUC it'd break the vite:invoke event, but we're already breaking the naming convention in #18851

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's to reduce the payload size. But I'm fine with making them consistent as I'm not sure about the perf difference.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'd lean on having consistent names as the payload savings probably isn't much compared to the data that the values can usually contain. But we can change it in a different PR if we'd like.

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