Skip to content

Commit e0cb4c8

Browse files
committed
fix(angular-query): call withDevtools function within injection context to not throw
1 parent 058bfc9 commit e0cb4c8

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

packages/angular-query-experimental/src/providers.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ import {
22
DestroyRef,
33
ENVIRONMENT_INITIALIZER,
44
InjectionToken,
5+
Injector,
56
PLATFORM_ID,
67
computed,
78
effect,
89
inject,
10+
runInInjectionContext,
911
} from '@angular/core'
1012
import { QueryClient, noop, onlineManager } from '@tanstack/query-core'
1113
import { isPlatformBrowser } from '@angular/common'
@@ -270,14 +272,19 @@ export function withDevtools(
270272
// Do not use provideEnvironmentInitializer while Angular < v19 is supported
271273
provide: ENVIRONMENT_INITIALIZER,
272274
multi: true,
273-
useFactory: () => {
275+
deps: [Injector],
276+
useFactory: (injector: Injector) => {
274277
if (!isPlatformBrowser(inject(PLATFORM_ID))) return noop
275278
const injectedClient = inject(QueryClient, {
276279
optional: true,
277280
})
278281
const destroyRef = inject(DestroyRef)
279282

280-
const options = computed(() => withDevtoolsFn?.() ?? {})
283+
const options = computed(() => {
284+
return runInInjectionContext(injector, () => {
285+
return withDevtoolsFn?.() ?? {}
286+
})
287+
})
281288

282289
let devtools: TanstackQueryDevtools | null = null
283290
let el: HTMLElement | null = null

0 commit comments

Comments
 (0)