-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
fix(ssr): watchEffect onInvalidate runner initialization (close #3322) #3323
Conversation
Hey, thank you for your PR, but I think there is a better way. In SSR, we do not need to initialize const onInvalidate: InvalidateCbRegistrator = (fn: () => void) => {
cleanup = () => {
callWithErrorHandling(fn, instance, ErrorCodes.WATCH_CLEANUP)
}
if (!(__NODE_JS__ && isInSSRComponentSetup)) {
runner.options.onStop = cleanup
}
} |
I rethink about that, the callback registered with |
@HcySunYang thanks for the feedback, that actually makes sense! I'll do another pass. Do you have a suggestion for improving the test? PS: Edited the patch (much better!) |
} else { | ||
watchEffect(onInvalidate => { | ||
expect(() => onInvalidate(noop)).not.toThrow(ReferenceError) | ||
done() |
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.
done
will get called by the first watchEffect bootstrap/run, which is not the SSR one, so an error in the SSR one would not be part of the test anymore, I think?
Will think about how to do this with async/await.
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'm assuming (and running the tests seems to validate) that setup gets called twice. The first time, instance
is not set, so we just set instance
. The second setup call with SSR triggers the watchEffect
branch.
I could rewrite with promises but I think it would be a bit more verbose... is that preferred?
I think it would be better if we write test case in |
@HcySunYang thanks for that pointer... much better place for it! Let me know if anything else should be touched up. |
@tjk , great work, thanks |
No description provided.