-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
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
changes to nonreactive variables containing primitive values are reflected in prod, but not in dev. #5655
Comments
// Result of compilation
_createElementVNode("div", _hoisted_1, _toDisplayString(_unref(foo).fooProp), 1 /* TEXT */),
_createElementVNode("div", _hoisted_2, _toDisplayString(bar.value), 1 /* TEXT */),
// I guess both of that should be tagged STATIC or hoisted |
I'm not sure what what you mean with "only happens in SFC playground". What you see there is normal. when one reactive dependency of the template changes, the whole component is re-rendered, with all the latest data. So I'm not sure what behavior you expect. |
https://user-images.githubusercontent.com/30561277/161329929-05c80ef9-c299-422f-82bd-096dbf14874d.mov
When I tested it in my project, I considered that all non-responsive data would not update the DOM ( like nonReactive in video ) |
Thanks for the video, but that doesn't tell me much without understanding how exactly to replicate it. |
https://github.com/xiexuan-star/issue-demo |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
No I see what you mean. This is in fact a side-effect of the way script setup is compiled for dev. it essentially looks like this: import { ref,shallowRef, defineComponent } from 'vue'
export default defineComponent({
setup() {
const foo = shallowRef({fooProp:1})
const bar = ref(1);
let nonReactive = 1
function onClick(){
foo.value.fooProp++;
bar.value++;
nonReactive++;
}
return {
foo,
bar,
nonReactive // this will now forever be 1, as it reassigned a primitive value to an object property
}
}
}) Whereas in production/playground, it will look more like this:<script> import { ref,shallowRef, defineComponent } from 'vue'
export default defineComponent({
setup() {
const foo = shallowRef({fooProp:1})
const bar = ref(1);
let nonReactive = 1
function onClick(){
foo.value.fooProp++;
bar.value++;
nonReactive++;
}
return () => {
// render function directly accessing the above variables in its closure.
// here, changes to `nonReactive` will be picked up when this render function is being re-run
}
}
}) So to summarize:
This is surely something we could improve on. |
Thank you for your patience. Now I understand the difference |
@LinusBorg do you not consider different behavior between dev and prod build a bug? |
…les declared in `<script setup>` fix vuejs#5655
…les declared in `<script setup>` fix vuejs#5655
Version
3.2.31
Reproduction link
sfc.vuejs.org/
Steps to reproduce
The element node should not be updated when the shallowRef changes.
However, when other responsive data changes, the element node(bound to shallowRef) is also updated
What is expected?
not updated
What is actually happening?
element node updated
The text was updated successfully, but these errors were encountered: