Skip to content

Commit b40d71e

Browse files
authored
reliably update service worker (#2638)
1 parent fde2314 commit b40d71e

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

packages/messaging/src/controllers/window-controller.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,12 @@ export class WindowController implements FirebaseMessaging, FirebaseService {
167167
scope: DEFAULT_SW_SCOPE
168168
}
169169
);
170+
171+
// The timing when browser updates sw when sw has an update is unreliable by my experiment.
172+
// It leads to version conflict when the SDK upgrades to a newer version in the main page, but
173+
// sw is stuck with the old version. For example, https://github.com/firebase/firebase-js-sdk/issues/2590
174+
// The following line reliably updates sw if there was an update.
175+
this.swRegistration.update().catch(() => { /* it is non blocking and we don't care if it failed */ });
170176
} catch (e) {
171177
throw ERROR_FACTORY.create(ErrorCode.FAILED_DEFAULT_REGISTRATION, {
172178
browserErrorMessage: e.message

0 commit comments

Comments
 (0)