Skip to content

Commit

Permalink
reliably update service worker (#2638)
Browse files Browse the repository at this point in the history
  • Loading branch information
Feiyang1 committed Feb 18, 2020
1 parent fde2314 commit b40d71e
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/messaging/src/controllers/window-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ export class WindowController implements FirebaseMessaging, FirebaseService {
scope: DEFAULT_SW_SCOPE
}
);

// The timing when browser updates sw when sw has an update is unreliable by my experiment.
// It leads to version conflict when the SDK upgrades to a newer version in the main page, but
// sw is stuck with the old version. For example, https://github.com/firebase/firebase-js-sdk/issues/2590
// The following line reliably updates sw if there was an update.
this.swRegistration.update().catch(() => { /* it is non blocking and we don't care if it failed */ });
} catch (e) {
throw ERROR_FACTORY.create(ErrorCode.FAILED_DEFAULT_REGISTRATION, {
browserErrorMessage: e.message
Expand Down

0 comments on commit b40d71e

Please sign in to comment.