Open History to see the last commit
1import { InjectionToken, inject } from '@angular/core'
2import * as ng from '@angular/core'
3import { noop } from '@tanstack/query-core'
4β
5type PendingTasksCompat = { add: () => PendingTaskRef }
6β
7/**
8 * Removes a pending task registered with Angular's `PendingTasks`, so the app can become stable
9 * again. Without `PendingTasks` (Angular < 19), it does nothing.
10 */
11export type PendingTaskRef = () => void
12β
13export const PENDING_TASKS = new InjectionToken<PendingTasksCompat>(
14 'PENDING_TASKS',
15 {
16 factory: (): PendingTasksCompat => {
17 // Access via Reflect so bundlers stay quiet when the token is absent (Angular < 19).
18 const token = Reflect.get(ng, 'PendingTasks') as unknown as
19 Parameters<typeof inject>[0] | undefined
20β
21 const svc: PendingTasksCompat | null = token
22 ? (inject(token, { optional: true }) as PendingTasksCompat | null)
23 : null
24β
25 // Without PendingTasks we fall back to a stable no-op shim.
26 return {
27 add: svc ? () => svc.add() : () => noop,
28 }
29 },
30 },
31)