-
-
Notifications
You must be signed in to change notification settings - Fork 444
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
Use effectScope instead of manually stopping effects #3610
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 6c2c896 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Adding this would break our compatibility with older Vue versions https://github.com/vuejs/core/blob/main/changelogs/CHANGELOG-3.2.md#reactivity - we have to stick to the minimum peerDep version described in our package.json or it will be a breaking change. |
Indeed, I didn't notice. Perhaps a major change might be worth considering then? For example, a router for Vue 3 asks for a minimum of [email protected] At the same time, Vue 2 has already reached its EOL https://v2.vuejs.org/eol/ A good option would be to install the minimum version 3.3. We could use native |
we don't need to stop watchers explicitly, as watcher automatically stopped when the owner component is unmounted |
@yurks I don't want to sound too harsh, but please don't comment assuming that something that's been required is there for no reason 😅❤️ urql/packages/vue-urql/src/useClientHandle.ts Line 134 in 1bb05f5
@negezor: I'm a bit concerned about raising the requirement too soon after the recent fixes, since they've been quite important overall. |
@kitten Based on the all above, I can conclude that it's impossible to use this method outside vue context and left a comment here. Am I wrong? |
Feel free to browse past issues and discussions regarding this topic. The function instantiates in component setup functions, but is then meant to assist with contexts that are outside of components and Vue's tracking contexts after. This in fact becomes pretty apparent when you try to call |
I may be wrong and I would appreciate it if you could help me realize this, but based on current code, watchers are always connected to component instance. How it possible to stay active, as un-watching should be handled internally by vue? I can see only one possible reason, based on date this code parts was authored - it was developed with beta version of vue 3, where was a number of similar issues. PS: I just did a little refactoring with care of reactivity handling, and propose to remove PSS: I'm not the only one who wonders about the necessity of this feature. |
@kitten I found your use case - handling several awaits when calling several const handle = useClientHandle();
const resultOne = await handle.useQuery(/* ... */);
const resultTwo = await handle.useQuery(/* ... */); But it looks like incorrect code pattern, as it's known vue issue and even vue lint trying to be aware of it. It's ok to handle such cases manually for sure, but I think it perpetuates the misuse of the framework. Even more, you can't handle possible awaits before calling I would suggest to document this case and prevent such usage with proposing correct pattern like: const resultOne = useQuery(/* ... */);
const resultTwo = useQuery(/* ... */);
// sequential execution
await resultOne;
await resultTwo;
// or parallel execution
await Promise.all([resultOne, resultTwo]) |
Summary
This PR eliminates the need to manually stop effects, as Vue has an efficient
effectScope
API. Manual stopping is less readable and consumes more memory unnecessarily, since Vue will still write the effects to scope.Set of changes
stops
inuseQuery.ts
anduseSubscription.ts
stops
witheffectScope
inuseClientHandle.ts
This should be a minor change. However, for most users this won't matter because everything basically uses methods directly instead of
useClientHandle
, which is much more efficient.