From d4fa95c2070ca69b0b0214c22fb5448953eceb19 Mon Sep 17 00:00:00 2001 From: omergronich Date: Fri, 29 Nov 2024 13:39:15 +0200 Subject: [PATCH] fix(angular-query): used effect onCleanup instead of destroy ref --- .../src/create-base-query.ts | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/packages/angular-query-experimental/src/create-base-query.ts b/packages/angular-query-experimental/src/create-base-query.ts index 8f447207a0b..2174abf8e10 100644 --- a/packages/angular-query-experimental/src/create-base-query.ts +++ b/packages/angular-query-experimental/src/create-base-query.ts @@ -1,5 +1,4 @@ import { - DestroyRef, Injector, NgZone, computed, @@ -45,7 +44,6 @@ export function createBaseQuery< const injector = inject(Injector) return lazyInit(() => { const ngZone = injector.get(NgZone) - const destroyRef = injector.get(DestroyRef) const queryClient = injector.get(QueryClient) const isRestoring = injectIsRestoring(injector) @@ -94,11 +92,10 @@ export function createBaseQuery< ) effect( - () => { + (onCleanup) => { const _isRestoring = isRestoring() - - untracked(() => { - const unsubscribe = _isRestoring + const cleanup = untracked(() => + _isRestoring ? () => undefined : ngZone.runOutsideAngular(() => // observer.trackResult is not used as this optimization is not needed for Angular @@ -121,9 +118,9 @@ export function createBaseQuery< }, ), ), - ) - destroyRef.onDestroy(unsubscribe) - }) + ), + ) + onCleanup(cleanup) }, { injector,