-
-
Notifications
You must be signed in to change notification settings - Fork 33.6k
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 2.0 infinite update loop when using functional component props as a props for its root element #3276
Comments
the below rendering flow:
I think that render function of functional component is updating the parent props is bad practice in Vue 2.0 @yyx990803 If you have my mistake comment or any comments, please tell us. |
@kazupon Sorry, counter was here for showing purposes only. I didn't realize that it will affect to rendering flow of child component.
|
Thanks!! I found your mistake at components: {
HelloWorld: {
props: ['params'],
functional: true,
render (h, ctx) {
console.log(ctx.props.params.style.background)
//return h('div', ctx.props.params, ctx.children)
return h('div', ctx.data, ctx.children) // correct usage
}
}
} About |
@kazupon Hmm |
Okay. |
@kazupon No, again. By props i meant tag attributes not component properties. Sorry for mistake. So, params: {
style: { backgroundColor: "#ccc" }
} I need to create node which looks like: h('div', {style: { backgroundColor: "#ccc" }}, ctx.children) My component gets props: ['params'],
functional: true,
render (h, ctx) {
console.log(ctx.props.params) //{style: { backgroundColor: "#ccc" }}
return h('div', ctx.props.params, ctx.children)
}
} |
This is somewhat expected because vnode data should be fresh objects on each render. I've added a warning for using observed objects as vnode data. To get around this, simply shallow copy the object before sending it in: render (h, ctx) {
return h('div', Vue.util.extend({}, ctx.props.params), ctx.children)
} |
@yyx990803 Thanks! |
Vue.js version
2.0.0-beta.1
Reproduction Link
http://codepen.io/OEvgeny/pen/qNpBqX?editors=1010
Steps to reproduce
Open console devtools to see error message
What is Expected?
HelloWorld component renders div with passed down style without warning.
What is actually happening?
I've got warning from Vue:
The text was updated successfully, but these errors were encountered: