Skip to content

Commit

Permalink
fix(angular-query): used effect onCleanup instead of destroy ref
Browse files Browse the repository at this point in the history
  • Loading branch information
OmerGronich committed Nov 29, 2024
1 parent a864815 commit d4fa95c
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions packages/angular-query-experimental/src/create-base-query.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
DestroyRef,
Injector,
NgZone,
computed,
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand All @@ -121,9 +118,9 @@ export function createBaseQuery<
},
),
),
)
destroyRef.onDestroy(unsubscribe)
})
),
)
onCleanup(cleanup)
},
{
injector,
Expand Down

0 comments on commit d4fa95c

Please sign in to comment.