Skip to content

Commit b052807

Browse files
committed
fix(angular-query): call withDevtools function within injection context to not throw
1 parent 7cf6ef5 commit b052807

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, onlineManager } from '@tanstack/query-core'
1113
import { isPlatformBrowser } from '@angular/common'
@@ -271,14 +273,19 @@ export function withDevtools(
271273
// Do not use provideEnvironmentInitializer while Angular < v19 is supported
272274
provide: ENVIRONMENT_INITIALIZER,
273275
multi: true,
274-
useFactory: () => {
276+
deps: [Injector],
277+
useFactory: (injector: Injector) => {
275278
if (!isPlatformBrowser(inject(PLATFORM_ID))) return noop
276279
const injectedClient = inject(QueryClient, {
277280
optional: true,
278281
})
279282
const destroyRef = inject(DestroyRef)
280283

281-
const options = computed(() => withDevtoolsFn?.() ?? {})
284+
const options = computed(() => {
285+
return runInInjectionContext(injector, () => {
286+
return withDevtoolsFn?.() ?? {}
287+
})
288+
})
282289

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

0 commit comments

Comments
 (0)