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]
20 | undefined
21β
22 const svc: PendingTasksCompat | null = token
23 ? (inject(token, { optional: true }) as PendingTasksCompat | null)
24 : null
25β
26 // Without PendingTasks we fall back to a stable no-op shim.
27 return {
28 add: svc ? () => svc.add() : () => noop,
29 }
30 },
31 },
32)