Skip to content

Commit 15c91a5

Browse files
alan-agius4AndrewKushnir
authored andcommitted
fix(http): delay accessing pendingTasks.whenAllTasksComplete (#49784)
Accessing `pendingTasks.whenAllTasksComplete` too early causes the `InitialRenderPendingTasks` to return a resolved promise too early. This commit changes the way we access `whenAllTasksComplete` to only happen when the application is stabilized. PR Close #49784
1 parent 2f2ef14 commit 15c91a5

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

packages/common/http/src/transfer_cache.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {APP_BOOTSTRAP_LISTENER, ApplicationRef, inject, InjectionToken, makeStateKey, Provider, StateKey, TransferState, ɵENABLED_SSR_FEATURES as ENABLED_SSR_FEATURES, ɵInitialRenderPendingTasks as InitialRenderPendingTasks} from '@angular/core';
9+
import {APP_INITIALIZER, ApplicationRef, inject, InjectionToken, makeStateKey, Provider, StateKey, TransferState, ɵENABLED_SSR_FEATURES as ENABLED_SSR_FEATURES, ɵInitialRenderPendingTasks as InitialRenderPendingTasks} from '@angular/core';
1010
import {Observable, of} from 'rxjs';
1111
import {first, tap} from 'rxjs/operators';
1212

@@ -160,7 +160,7 @@ export function withHttpTransferCache(): Provider[] {
160160
deps: [TransferState, CACHE_STATE]
161161
},
162162
{
163-
provide: APP_BOOTSTRAP_LISTENER,
163+
provide: APP_INITIALIZER,
164164
multi: true,
165165
useFactory: () => {
166166
const appRef = inject(ApplicationRef);
@@ -169,9 +169,7 @@ export function withHttpTransferCache(): Provider[] {
169169

170170
return () => {
171171
const isStablePromise = appRef.isStable.pipe(first((isStable) => isStable)).toPromise();
172-
const pendingTasksPromise = pendingTasks.whenAllTasksComplete;
173-
174-
Promise.allSettled([isStablePromise, pendingTasksPromise]).then(() => {
172+
isStablePromise.then(() => pendingTasks.whenAllTasksComplete).then(() => {
175173
cacheState.isCacheActive = false;
176174
});
177175
};

0 commit comments

Comments
 (0)