-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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
feat(app): support app level effect scope #8801
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general this feature makes sense to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remember we intentionally stuck to only inject and provide.
That being said I think this is really useful and did propose it too but wanted to avoid adding too much right away to runWithContext()
🤪. The router and pinia could benefit from this too.
Could you add a test?
This could probably be moved to createApp()
too
This would potentially also enable an app.onUnmount = (fn) => app.runWithContext(() => onScopeDispose(fn)) |
Co-authored-by: Eduardo San Martin Morote <[email protected]>
Thank you for your feedback. I have a couple of questions I would like to confirm:
Thank you! Your invaluable guidance means a lot to me. |
|
I have moved the implementation to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me. It would be nice to have feedback from @yyx990803 to know if he can think of any reason not to have an effect like this.
One thing work noting is that any user doing this:
const myEffect = effectScope()
myEffect.run(() => app.runWithContext(fn))
Will have to rewrite it to
app.runWithContext(() => myEffect.run(fn))
Which is technically a breaking change. I haven't checked the usage of this in the wild though but I will have to update pinia before this comes out as I currently have the code shown above 😆
const scope = effectScope(true) | ||
const context = createAppContext() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes me wonder if the effectScope should be in app context 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Co-authored-by: Eduardo San Martin Morote <[email protected]>
# Conflicts: # packages/runtime-core/__tests__/apiCreateApp.spec.ts
# Conflicts: # packages/runtime-core/__tests__/apiCreateApp.spec.ts
I'm wondering about whether this could cause memory leaks, and whether that matters. I've put together an example using Vue Router: Steps to reproduce:
The key parts of the code are: router.beforeEach(() => {
const { doubled } = useBlah()
if (doubled.value) {
// ...
}
}) with: function useBlah() {
const raw = ref(1)
const doubled = computed(() => raw.value * 2)
raw.marker = new VTrackLeak()
return { raw, doubled }
} The callback for |
@skirtles-code I'm surprised they don't both leak. I would consider that usage wrong, but it does show a distinction between being able to |
I studied the issue and found that it is likely caused by the I am unsure if the usage in the example is intended. Should we discourage users from using I am not sure how to fix this issue. I would greatly appreciate any guidance or suggestions. |
close #8787