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
This commit is contained in:
Andrew Scott
2022-11-15 08:54:13 -08:00
committed by Dylan Hunn
parent 73f03ad2d2
commit bc148c30d5
2 changed files with 4 additions and 11 deletions
+1 -9
View File
@@ -314,7 +314,6 @@ export function withEnabledBlockingInitialNavigation(): EnabledBlockingInitialNa
useFactory: (injector: Injector) => {
const locationInitialized: Promise<any> =
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();
});
+3 -2
View File
@@ -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 () => {