fix(core): cleanup loading promise when no dependencies are defined (#53031)

This commit cleans up the `loadingPromise` when no `dependenciesFn` is defined,
as it's already cleaned up after the resolution of `Promise.allSettled`. This
occurs with `prefetch on` triggers, such as when `triggerResourceLoading` is called
from `ɵɵdeferPrefetchOnImmediate`, where there are no dependencies to load. The
`loadingPromise` should still be cleaned up because it typically involves the
`ZoneAwarePromise`, which isn't properly garbage collected when referenced elsewhere
(in this case, it would be referenced from the `tView` data).

PR Close #53031
This commit is contained in:
arturovt
2023-11-18 23:06:14 +02:00
committed by Andrew Kushnir
parent 54823893c8
commit ed0fbd4071
+2 -1
View File
@@ -655,10 +655,11 @@ export function triggerResourceLoading(tDetails: TDeferBlockDetails, lView: LVie
}
// The `dependenciesFn` might be `null` when all dependencies within
// a given defer block were eagerly references elsewhere in a file,
// a given defer block were eagerly referenced elsewhere in a file,
// thus no dynamic `import()`s were produced.
if (!dependenciesFn) {
tDetails.loadingPromise = Promise.resolve().then(() => {
tDetails.loadingPromise = null;
tDetails.loadingState = DeferDependenciesLoadingState.COMPLETE;
});
return;