From 90fb6236141c3dd82a11bb50de124fb3be22e5bb Mon Sep 17 00:00:00 2001 From: Andrew Kushnir Date: Sat, 3 Feb 2024 17:29:25 -0800 Subject: [PATCH] refactor(core): create pending task while defer block loading is in progress (#54239) This commit updates the logic of defer blocks to create an internal pending task to indicate that an application is not yet stable. This change would be helpful for zoneless applications. PR Close #54239 --- packages/core/src/defer/instructions.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/core/src/defer/instructions.ts b/packages/core/src/defer/instructions.ts index f115cbb153a..c6878614294 100644 --- a/packages/core/src/defer/instructions.ts +++ b/packages/core/src/defer/instructions.ts @@ -12,6 +12,7 @@ import {InjectionToken, Injector} from '../di'; import {RuntimeError, RuntimeErrorCode} from '../errors'; import {findMatchingDehydratedView} from '../hydration/views'; import {populateDehydratedViewsInLContainer} from '../linker/view_container_ref'; +import {PendingTasks} from '../pending_tasks'; import {assertLContainer, assertTNodeForLView} from '../render3/assert'; import {bindingUpdated} from '../render3/bindings'; import {getComponentDef, getDirectiveDef, getPipeDef} from '../render3/definition'; @@ -656,6 +657,10 @@ export function triggerResourceLoading(tDetails: TDeferBlockDetails, lView: LVie } } + // Indicate that an application is not stable and has a pending task. + const pendingTasks = injector.get(PendingTasks); + const taskId = pendingTasks.add(); + // The `dependenciesFn` might be `null` when all dependencies within // a given defer block were eagerly referenced elsewhere in a file, // thus no dynamic `import()`s were produced. @@ -663,6 +668,7 @@ export function triggerResourceLoading(tDetails: TDeferBlockDetails, lView: LVie tDetails.loadingPromise = Promise.resolve().then(() => { tDetails.loadingPromise = null; tDetails.loadingState = DeferDependenciesLoadingState.COMPLETE; + pendingTasks.remove(taskId); }); return; } @@ -691,8 +697,10 @@ export function triggerResourceLoading(tDetails: TDeferBlockDetails, lView: LVie } } - // Loading is completed, we no longer need this Promise. + // Loading is completed, we no longer need the loading Promise + // and a pending task should also be removed. tDetails.loadingPromise = null; + pendingTasks.remove(taskId); if (failed) { tDetails.loadingState = DeferDependenciesLoadingState.FAILED;