Skip to content
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

Remove wrapping request args in reactive to fix memory leak #3612

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .changeset/quick-pens-battle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@urql/vue': minor
---

Remove wrapping request `args` in `reactive` to fix memory leak
6 changes: 2 additions & 4 deletions packages/vue-urql/src/useQuery.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable react-hooks/rules-of-hooks */

import type { Ref, WatchStopHandle } from 'vue';
import { isRef, reactive, ref, shallowRef, watch, watchEffect } from 'vue';
import { isRef, ref, shallowRef, watch, watchEffect } from 'vue';

import type { Subscription, Source } from 'wonka';
import { pipe, subscribe, onEnd } from 'wonka';
Expand Down Expand Up @@ -241,12 +241,10 @@ export function useQuery<T = any, V extends AnyVariables = AnyVariables>(
}

export function callUseQuery<T = any, V extends AnyVariables = AnyVariables>(
_args: UseQueryArgs<T, V>,
args: UseQueryArgs<T, V>,
client: Ref<Client> = useClient(),
stops: WatchStopHandle[] = []
): UseQueryResponse<T, V> {
const args = reactive(_args) as UseQueryArgs<T, V>;

const data: Ref<T | undefined> = ref();
const stale: Ref<boolean> = ref(false);
const fetching: Ref<boolean> = ref(false);
Expand Down
6 changes: 2 additions & 4 deletions packages/vue-urql/src/useSubscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { Source } from 'wonka';
import { pipe, subscribe, onEnd } from 'wonka';

import type { Ref, WatchStopHandle } from 'vue';
import { isRef, reactive, ref, shallowRef, watch, watchEffect } from 'vue';
import { isRef, ref, shallowRef, watch, watchEffect } from 'vue';

import type {
Client,
Expand Down Expand Up @@ -239,13 +239,11 @@ export function callUseSubscription<
R = T,
V extends AnyVariables = AnyVariables,
>(
_args: UseSubscriptionArgs<T, V>,
args: UseSubscriptionArgs<T, V>,
handler?: MaybeRef<SubscriptionHandler<T, R>>,
client: Ref<Client> = useClient(),
stops: WatchStopHandle[] = []
): UseSubscriptionResponse<T, R, V> {
const args = reactive(_args) as UseSubscriptionArgs<T, V>;

const data: Ref<R | undefined> = ref();
const stale: Ref<boolean> = ref(false);
const fetching: Ref<boolean> = ref(false);
Expand Down