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
9 * can become stable again. Without `PendingTasks` (Angular < 19), it does
10 * nothing.
11 */
12export type PendingTaskRef = () => void
13β
14export const PENDING_TASKS = new InjectionToken<PendingTasksCompat>(
15 'PENDING_TASKS',
16 {
17 factory: (): PendingTasksCompat => {
18 // Access via Reflect so bundlers stay quiet when the token is absent (Angular < 19).
19 const token = Reflect.get(ng, 'PendingTasks') as unknown as
20 | Parameters<typeof inject>[0]
21 | undefined
22β
23 const svc: PendingTasksCompat | null = token
24 ? (inject(token, { optional: true }) as PendingTasksCompat | null)
25 : null
26β
27 // Without PendingTasks we fall back to a stable no-op shim.
28 return {
29 add: svc ? () => svc.add() : () => noop,
30 }
31 },
32 },
33)