From 25628d2677f74e5f1cb56139fb03ddfd076fe5ea Mon Sep 17 00:00:00 2001 From: Josh Kasten Date: Thu, 16 Nov 2023 15:37:23 -0500 Subject: [PATCH] fixup! fix race condition getting wrong sw registration --- src/shared/managers/ServiceWorkerManager.ts | 4 ++-- src/sw/helpers/ServiceWorkerUtilHelper.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/shared/managers/ServiceWorkerManager.ts b/src/shared/managers/ServiceWorkerManager.ts index 337e46298..182da639b 100644 --- a/src/shared/managers/ServiceWorkerManager.ts +++ b/src/shared/managers/ServiceWorkerManager.ts @@ -174,7 +174,7 @@ export class ServiceWorkerManager { }); } - // Returns true if a the OneSignal service worker can't be installed + // Returns false if the OneSignal service worker can't be installed // or is already installed and doesn't need updating. private async shouldInstallWorker(): Promise { // 1. Does the browser support ServiceWorkers? @@ -541,7 +541,7 @@ export class ServiceWorkerManager { `[Service Worker Installation] Service worker installed. Waiting for activation`, ); - await ServiceWorkerUtilHelper.waitForServiceWorkerToActive(registration); + await ServiceWorkerUtilHelper.waitUntilActive(registration); Log.debug(`[Service Worker Installation] Service worker active`); diff --git a/src/sw/helpers/ServiceWorkerUtilHelper.ts b/src/sw/helpers/ServiceWorkerUtilHelper.ts index 8d5b79438..dbb25b660 100644 --- a/src/sw/helpers/ServiceWorkerUtilHelper.ts +++ b/src/sw/helpers/ServiceWorkerUtilHelper.ts @@ -37,7 +37,7 @@ export default class ServiceWorkerUtilHelper { // Allows waiting for the service worker registration to become active. // Some APIs, like registration.pushManager.subscribe, required it be active // otherwise it throws. - static waitForServiceWorkerToActive( + static waitUntilActive( registration: ServiceWorkerRegistration, ): Promise { return new Promise((resolver) => {