From 229967de20a464d827fe5db688860971d7538494 Mon Sep 17 00:00:00 2001 From: unadlib Date: Mon, 11 Nov 2024 10:20:37 +0800 Subject: [PATCH] fix(worker): fix workerRemote handler --- examples/basic/app2/src/bootstrap.tsx | 6 +++--- packages/builder/src/make.ts | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/examples/basic/app2/src/bootstrap.tsx b/examples/basic/app2/src/bootstrap.tsx index 867b929..f7510cb 100644 --- a/examples/basic/app2/src/bootstrap.tsx +++ b/examples/basic/app2/src/bootstrap.tsx @@ -14,9 +14,9 @@ import type App3 from '@example/app3/src/bootstrap'; import App from './App'; console.log('testValue in main thread', testValue); -const worker = new SharedWorker(new URL('./worker', import.meta.url), { - name: getWorkerName('app2'), -}); +// const worker = new SharedWorker(new URL('./worker', import.meta.url), { +// name: getWorkerName('app2'), +// }); (window as any)._log2 = useLogger({ name: 'app2', diff --git a/packages/builder/src/make.ts b/packages/builder/src/make.ts index aae9252..3469770 100644 --- a/packages/builder/src/make.ts +++ b/packages/builder/src/make.ts @@ -40,11 +40,12 @@ export const makeRemoteScript = ( } // TODO: support custom worker remote const url = new URL(remoteEntry); - const pathname = url.pathname.split('/'); - pathname.splice(-1, 0, 'worker'); // replace the default remote with the worker remote // e.g. http://localhost:3000/remoteEntry.js -> http://localhost:3000/worker/remoteEntry.js - const workerRemote = `${url.origin}${pathname.join('/')}`; + const workerRemote = remoteEntry.replace( + url.pathname, + `/worker${url.pathname}` + ); importScripts(workerRemote); } const toBeResolved = () => {