Skip to content

fix(angular-query): call withDevtools function within injection conte… #9236

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions packages/angular-query-experimental/src/providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import {
DestroyRef,
ENVIRONMENT_INITIALIZER,
InjectionToken,
Injector,
PLATFORM_ID,
computed,
effect,
inject,
runInInjectionContext,
} from '@angular/core'
import { QueryClient, noop, onlineManager } from '@tanstack/query-core'
import { isPlatformBrowser } from '@angular/common'
Expand Down Expand Up @@ -270,14 +272,19 @@ export function withDevtools(
// Do not use provideEnvironmentInitializer while Angular < v19 is supported
provide: ENVIRONMENT_INITIALIZER,
multi: true,
useFactory: () => {
deps: [Injector],
useFactory: (injector: Injector) => {
if (!isPlatformBrowser(inject(PLATFORM_ID))) return noop
const injectedClient = inject(QueryClient, {
optional: true,
})
const destroyRef = inject(DestroyRef)

const options = computed(() => withDevtoolsFn?.() ?? {})
const options = computed(() => {
return runInInjectionContext(injector, () => {
return withDevtoolsFn?.() ?? {}
})
})

let devtools: TanstackQueryDevtools | null = null
let el: HTMLElement | null = null
Expand Down
Loading