Skip to content

Commit

Permalink
fix: make result interfaces for ModuleRunnerTransport#invoke more e…
Browse files Browse the repository at this point in the history
…xplicit (#18851)
  • Loading branch information
dario-piotrowicz authored Dec 2, 2024
1 parent 44a0f40 commit a75fc31
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
4 changes: 1 addition & 3 deletions docs/guide/api-environment-runtimes.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,7 @@ interface ModuleRunnerTransport {
connect?(handlers: ModuleRunnerTransportHandlers): Promise<void> | void
disconnect?(): Promise<void> | void
send?(data: HotPayload): Promise<void> | void
invoke?(
data: HotPayload,
): Promise<{ /** result */ r: any } | { /** error */ e: any }>
invoke?(data: HotPayload): Promise<{ result: any } | { error: any }>
timeout?: number
}
```
Expand Down
10 changes: 4 additions & 6 deletions packages/vite/src/shared/moduleRunnerTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ export interface ModuleRunnerTransport {
connect?(handlers: ModuleRunnerTransportHandlers): Promise<void> | void
disconnect?(): Promise<void> | void
send?(data: HotPayload): Promise<void> | void
invoke?(
data: HotPayload,
): Promise<{ /** result */ r: any } | { /** error */ e: any }>
invoke?(data: HotPayload): Promise<{ result: any } | { error: any }>
timeout?: number
}

Expand Down Expand Up @@ -58,10 +56,10 @@ const createInvokeableTransport = (
data,
} satisfies InvokeSendData,
} satisfies CustomPayload)
if ('e' in result) {
throw reviveInvokeError(result.e)
if ('error' in result) {
throw reviveInvokeError(result.error)
}
return result.r
return result.result
},
}
}
Expand Down

0 comments on commit a75fc31

Please # to comment.