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(compiler-sfc) fix setup result binding of primitive (non inlined mode) closes #5655 #5777
Conversation
…ed mode. make it consistent with inlined behaviour
✅ Deploy Preview for vue-next-template-explorer ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for vuejs-coverage ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for vue-sfc-playground ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
I think this fix is the right direction. One thing we need to consider is that I have seen this type of code far too often in setup functions: let myFlag = ref(false)
return {
myFlag
} And I think the current implementation of this fix would break such existing code as it would no longer assign a value from the template and instead reassign the let variable? If so, we could use a |
the fix should work for that use case as well the only case that I am not covering is |
the fix can be seen in this playground. |
I understand, thanks. TIL you can reassign a function declaration 🤯 Never tried that in my life 😝 |
Thanks a lot for the PR - sorry I noticed this only after pushing 5a3d45a, and realized we do need to consider import bindings as well. Unfortunately, the diffs between the branches got really messy and it was difficult to resolve the snapshots properly, so I wasn't able to reuse this PR and had to work upon my branch in 0594400. Really sorry for letting this hang for so long and thanks again for you contributions! |
closes #5655
compiled result of a setup in non inlined mode, may lose binding to non reactive primitives
in inlined mode the template always have the binding to a.
if a changes and view updates, a will reflect the new value
in non inlined mode, the setup result is a snapshot of the value
at the time setup() was called
a
will remain 123, even if a mutated and component re renderedThe fix:
instead of compiling the setup result to
compile with a getter/setter for any mutable and settable variable to keep a binding to the original variable.
{get a(){ return a}, set a(v){a=v} }
if the variable is only mutable but not settable ( like an es import specifier )
only return getter