From 249ca8f25cad4ced19c636c497bff7ef15d2e335 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Wed, 6 Mar 2024 10:22:25 +0100 Subject: [PATCH] Comlink API: Pass the context argument to windowEndpoint, not wrap 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. --- packages/php-wasm/web/src/lib/api.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/php-wasm/web/src/lib/api.ts b/packages/php-wasm/web/src/lib/api.ts index ce1632106e..ea92562533 100644 --- a/packages/php-wasm/web/src/lib/api.ts +++ b/packages/php-wasm/web/src/lib/api.ts @@ -22,7 +22,9 @@ export function consumeAPI( 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 @@ -33,7 +35,7 @@ export function consumeAPI( * * @TODO: Remove this workaround. */ - const api = Comlink.wrap(endpoint, context); + const api = Comlink.wrap(endpoint); const methods = proxyClone(api); return new Proxy(methods, { get: (target, prop) => {