Skip to content

Commit

Permalink
Comlink API: Pass the context argument to windowEndpoint, not wrap
Browse files Browse the repository at this point in the history
Follows up on #1085 that correctly identified the issue with
`postMessage` event handlers, but passed the context argument to the
wrong function call. `wrap()` uesd in that PR is not responsible for binding the message
event handler. `windowEndpoint()` is. This PR fixes the mistake.
  • Loading branch information
adamziel committed Mar 6, 2024
1 parent 7e392f6 commit 249ca8f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/php-wasm/web/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ export function consumeAPI<APIType>(
setupTransferHandlers();

const endpoint =
remote instanceof Worker ? remote : Comlink.windowEndpoint(remote);
remote instanceof Worker
? remote
: Comlink.windowEndpoint(remote, context);

/**
* This shouldn't be necessary, but Comlink doesn't seem to
Expand All @@ -33,7 +35,7 @@ export function consumeAPI<APIType>(
*
* @TODO: Remove this workaround.
*/
const api = Comlink.wrap<APIType & WithAPIState>(endpoint, context);
const api = Comlink.wrap<APIType & WithAPIState>(endpoint);
const methods = proxyClone(api);
return new Proxy(methods, {
get: (target, prop) => {
Expand Down

0 comments on commit 249ca8f

Please sign in to comment.