From bc148c30d57a8134a1f315bf1b3339ca20d21f9b Mon Sep 17 00:00:00 2001 From: Andrew Scott Date: Tue, 15 Nov 2022 08:54:13 -0800 Subject: [PATCH] refactor(router): Remove unnecessary logic in enabledBlocking option (#48064) The `initNavigated` flag is not necessary. The way `enabledBlocking` works is by blocking any navigations from finishing until the application has bootstrapped. The bootstrap is unblocked as soon as we hit the `afterPreactivation` step. After that point, `afterPreactivation` is always unblocked because the `bootstrapDone` Subject is completed/stopped. There is no need for an additional variable to track this information. PR Close #48064 --- packages/router/src/provide_router.ts | 10 +--------- packages/router/test/bootstrap.spec.ts | 5 +++-- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/packages/router/src/provide_router.ts b/packages/router/src/provide_router.ts index a094c99c249..f886e6bdb32 100644 --- a/packages/router/src/provide_router.ts +++ b/packages/router/src/provide_router.ts @@ -314,7 +314,6 @@ export function withEnabledBlockingInitialNavigation(): EnabledBlockingInitialNa useFactory: (injector: Injector) => { const locationInitialized: Promise = injector.get(LOCATION_INITIALIZED, Promise.resolve()); - let initNavigation = false; /** * Performs the given action once the router finishes its next/current navigation. @@ -358,7 +357,6 @@ export function withEnabledBlockingInitialNavigation(): EnabledBlockingInitialNa // Unblock APP_INITIALIZER in case the initial navigation was canceled or errored // without a redirect. resolve(true); - initNavigation = true; }); router.afterPreactivation = () => { @@ -366,13 +364,7 @@ export function withEnabledBlockingInitialNavigation(): EnabledBlockingInitialNa // assume activation will complete successfully (even though this is not // guaranteed). resolve(true); - // only the initial navigation should be delayed until bootstrapping is done. - if (!initNavigation) { - return bootstrapDone.closed ? of(void 0) : bootstrapDone; - // subsequent navigations should not be delayed - } else { - return of(void 0); - } + return bootstrapDone.closed ? of(void 0) : bootstrapDone; }; router.initialNavigation(); }); diff --git a/packages/router/test/bootstrap.spec.ts b/packages/router/test/bootstrap.spec.ts index 51c6b2a4ac9..2a925d69236 100644 --- a/packages/router/test/bootstrap.spec.ts +++ b/packages/router/test/bootstrap.spec.ts @@ -152,8 +152,9 @@ describe('bootstrap', () => { class TestModule { } - await Promise.all( - [platformBrowserDynamic([]).bootstrapModule(TestModule), navigationEndPromise]); + await expectAsync(Promise.all([ + platformBrowserDynamic([]).bootstrapModule(TestModule), navigationEndPromise + ])).toBeResolved(); }); it('should wait for redirect when initialNavigation = enabledBlocking', async () => {