diff --git a/packages/service-worker/src/module.ts b/packages/service-worker/src/module.ts index 7e7779f5d7..85eef4f67c 100644 --- a/packages/service-worker/src/module.ts +++ b/packages/service-worker/src/module.ts @@ -100,7 +100,9 @@ export function ngswAppInitializer( if (typeof options.registrationStrategy === 'function') { readyToRegister$ = options.registrationStrategy(); } else { - const [strategy, ...args] = (options.registrationStrategy || 'registerWhenStable').split(':'); + const [strategy, ...args] = + (options.registrationStrategy || 'registerWhenStable:30000').split(':'); + switch (strategy) { case 'registerImmediately': readyToRegister$ = of (null); diff --git a/packages/service-worker/test/module_spec.ts b/packages/service-worker/test/module_spec.ts index 46591e100f..2f6d8a3768 100644 --- a/packages/service-worker/test/module_spec.ts +++ b/packages/service-worker/test/module_spec.ts @@ -147,7 +147,7 @@ describe('ServiceWorkerModule', () => { return isStableSub; }; - it('defaults to registering the SW when the app stabilizes', fakeAsync(() => { + it('defaults to registering the SW when the app stabilizes (under 30s)', fakeAsync(() => { const isStableSub = configTestBedWithMockedStability(); isStableSub.next(false); @@ -156,7 +156,7 @@ describe('ServiceWorkerModule', () => { tick(); expect(swRegisterSpy).not.toHaveBeenCalled(); - tick(60000); + tick(20000); expect(swRegisterSpy).not.toHaveBeenCalled(); isStableSub.next(true); @@ -165,6 +165,17 @@ describe('ServiceWorkerModule', () => { expect(swRegisterSpy).toHaveBeenCalledWith('sw.js', {scope: undefined}); })); + it('defaults to registering the SW after 30s if the app does not stabilize sooner', + fakeAsync(() => { + const isStableSub = configTestBedWithMockedStability(); + + tick(29999); + expect(swRegisterSpy).not.toHaveBeenCalled(); + + tick(1); + expect(swRegisterSpy).toHaveBeenCalledWith('sw.js', {scope: undefined}); + })); + it('registers the SW when the app stabilizes with `registerWhenStable:`', fakeAsync(() => { const isStableSub = configTestBedWithMockedStability('registerWhenStable:1000');