From 8e40724cd3e315e0df703cce8d9f2cf7ab6cdc73 Mon Sep 17 00:00:00 2001 From: Artem Zakharchenko Date: Thu, 10 Oct 2024 19:09:36 +0200 Subject: [PATCH] fix(setupWorker): perform worker update in the background (#2311) --- .../start/utils/getWorkerInstance.ts | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/browser/setupWorker/start/utils/getWorkerInstance.ts b/src/browser/setupWorker/start/utils/getWorkerInstance.ts index 05594426b..0a249977c 100644 --- a/src/browser/setupWorker/start/utils/getWorkerInstance.ts +++ b/src/browser/setupWorker/start/utils/getWorkerInstance.ts @@ -36,17 +36,19 @@ export const getWorkerInstance = async ( const [existingRegistration] = mockRegistrations if (existingRegistration) { - // When the Service Worker is registered, update it and return the reference. - return existingRegistration.update().then(() => { - return [ - getWorkerByRegistration( - existingRegistration, - absoluteWorkerUrl, - findWorker, - ), + // Schedule the worker update in the background. + // Update ensures the existing worker is up-to-date. + existingRegistration.update() + + // Return the worker reference immediately. + return [ + getWorkerByRegistration( existingRegistration, - ] - }) + absoluteWorkerUrl, + findWorker, + ), + existingRegistration, + ] } // When the Service Worker wasn't found, register it anew and return the reference.