-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
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
Vue causes browser to become unresponsive when createElement is called with Promise-returning function #6558
Comments
Thanks! This is a valid bug. It freezes browsers and node. |
I don't think it is a bug, |
It doesn't matter if we need to accept Promise as API. We should not freeze browser or node server when users give Vue wrong input. |
Oh, yeah I agree with that, it should be fixed if possible, it's unreasonable to freeze the platform 😆 . The reason I'm saying it's not a bug is because from my perspective a bug is a situation not working while it should edit: I misread the code! Got tricked by the syntax, I thought the promise was using the call of |
Preliminary investigation shows Vue relies on the function as context to resolve async component. In this case, render function will always return a new function instance so the handle Vue attaches to the async component function is lost. So Vue will think the component isn't properly resolved. The fix is simple, move the inline arrow function outside, with a stable identifier I guess really no one is using this API. Also the solution to fix it isn't clear to me :/ |
Exactly what @HerringtonDarkholme said - when the Promise resolves, it will cause the current component to re-render, resulting in a new async factory function, thus entering an infinite update loop. I also don't see a simple fix to this, but this is not supported usage anyway. I guess what we can do is documenting this behavior in the async component section? |
Is there a workaround? I have a use case where I want to dynamically load a component based on data that is loaded, but I don't want to have to specify each component outright. Something like: return h(() => resolveComponent(this.data)) |
Can it be documented or maybe log some error when its happen? |
I just fixed a similar case. My website started freezing while using AsyncComponent with Vue 2.7. new Vue({
render: function (h) {
return h(() => import("./my-component.vue"));
}
}).$mount(selector); into this const myComponent = import("./my-component.vue");
new Vue({
render: function (h) {
return h(myComponent);
}
}).$mount(selector); It seems like storing the component in a variable is enough to avoid the render loop. |
Version
2.4.2
Reproduction link
https://jsfiddle.net/2pbthd1v/
Steps to reproduce
When calling
createElement
, pass a function that returns a promise which resolves to a Vue options bag.For example:
What is expected?
Either something useful or an error message.
What is actually happening?
The entire page stops responding.
This was part of the .d.ts test suite. I wanted to see if a test case was legitimate, but I ended up finding that it triggers some sort of bad behavior.
The text was updated successfully, but these errors were encountered: