Skip to content

Commit

Permalink
fix(trpc): cache-state turns to inactive once app is stable (#522)
Browse files Browse the repository at this point in the history
  • Loading branch information
goetzrobin authored Jul 7, 2023
1 parent cd8b518 commit ac2226a
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions packages/trpc/src/lib/client/cache-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
ApplicationRef,
inject,
InjectionToken,
ɵInitialRenderPendingTasks as InitialRenderPendingTasks,
} from '@angular/core';

export const tRPC_CACHE_STATE = new InjectionToken<{
Expand All @@ -22,20 +21,11 @@ export const provideTrpcCacheStateStatusManager = () => ({
useFactory: () => {
const appRef = inject(ApplicationRef);
const cacheState = inject(tRPC_CACHE_STATE);
const pendingTasks = inject(InitialRenderPendingTasks);

return () => {
const isStablePromise = appRef.isStable
return () =>
appRef.isStable
.pipe(first((isStable) => isStable))
.toPromise();
const pendingTasksPromise = pendingTasks.hasPendingTasks.toPromise();

(Promise as any)
.allSettled([isStablePromise, pendingTasksPromise])
.then(() => {
cacheState.isCacheActive.next(false);
});
};
.subscribe(() => cacheState.isCacheActive.next(false));
},
deps: [ApplicationRef, tRPC_CACHE_STATE, InitialRenderPendingTasks],
deps: [ApplicationRef, tRPC_CACHE_STATE],
});

0 comments on commit ac2226a

Please sign in to comment.