-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
Combination of watch, computed and h creates an infinite loop after building #8131
Comments
Is this a regression only in 3.3 alpha, or reproducible in 3.2? |
The playground example also breaks with 3.2.47 selected |
I forked the SFC Playground project to add some extra logging about the bug. You can test it out by opening the devtools console, clearing it and changing the "United States" selector to "Spain". You will see the following: Expected behavior (the one that happens in dev mode)
Explanation: when you set the new country, the Actual behavior (the one that happens after build):
Explanation: as you can see, lines 4-7 are the same as 8-11, forever since this is an infinite loop. The actual difference between dev and prod occurs in the line 9, when the watcher in BuggyForm receives the oldValue (California) instead of the new one (Madrid). TL;DR the core of this issue is: a watcher is triggered, but when on build mode the newValues are actually the old ones |
Is there any update / some way I can help to fix it? |
I don't think this is an internal vue problem. <BuggyForm type="select" name="state" :value="formValue.state" :options="stateOptions"/> see playground |
Vue version
3.3.0-alpha.13
Link to minimal reproduction
https://stackblitz.com/edit/vitejs-vite-ccxqc4?file=src/components/BuggyForm.vue
Steps to reproduce
npm run dev
in the terminal).npm run preview
to see how it would work after doing build.What is expected?
The same behavior as in step 3.
What is actually happening?
An infinite loop.
System Info
Any additional comments?
The original bug only happened to us when building the application for production.
The BuggyForm component is a minimal version of our custom form component, which can have more components of the same type inside that are the form controls. Thus, the v-model of the input wthi name country would be
"United States"
, while the v-model of its parent node, the form, would be{"country": "United States", "state": "California"}
. To do that we need to double-bind the form slot children to the form, which is why we need to use theh
function.In the BuggyForm component, we watch for changes on the options or value when the input is a
type="select"
, to make sure it always contain a valid value. Thus, if the current value is not in the options, it is reset to the first option available. However, this is triggering an update that calls this watcher again, with the old value ONLY when using a build (orvite preview
).It can also be triggered in Vue SFC Playground, but it's not possible to run it in dev mode to see the normal behavior.
The text was updated successfully, but these errors were encountered: