From e56713cd1d54c0bb39313401c33fb1497d888fcd Mon Sep 17 00:00:00 2001 From: Joan Varvenne Date: Thu, 2 Mar 2023 13:40:22 +0000 Subject: [PATCH] Prevent endpoint from being closed when all proxies are gone but an object was exposed on endpoint. --- src/comlink.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/comlink.ts b/src/comlink.ts index 8896b71d..ad6e974c 100644 --- a/src/comlink.ts +++ b/src/comlink.ts @@ -295,6 +295,9 @@ export function expose( ep: Endpoint = globalThis as any, allowedOrigins: (string | RegExp)[] = ["*"] ) { + const newCount = (proxyCounter.get(ep) || 0) + 1; + proxyCounter.set(ep, newCount); + ep.addEventListener("message", function callback(ev: MessageEvent) { if (!ev || !ev.data) { return;