Rendering slots and updated
hook
#5978
Replies: 5 comments 6 replies
-
Seems related #5579 |
Beta Was this translation helpful? Give feedback.
-
For comparison I also replicated the same example using Vue 2 (2.6.14): https://codesandbox.io/s/vue2-slot-render-n89n0k?file=/src/App.vue It works as I would expect - no updates, no matter if slot was rendered in render function/template, not depending on property type passed to child components. However the syntax seems to be slightly different ( render(h) {
return h("div", ["ParentRender", this.$slots.default]);
} |
Beta Was this translation helpful? Give feedback.
-
likely a bug. <Child name="child3" :dummy="[1]" /> should be compiled: _createVNode(Child, {
name: "child3",
dummy: [1]
}, null, 8 /* PROPS */, ["dummy"]), got: _createVNode(Child, {
name: "child3",
dummy: [1]
}), I think + // optimized is true and patchFlag is 0 when use renderSlot in this scenario
+ // causing the component to skip the update.
if (optimized && patchFlag >= 0) {
if (patchFlag & PatchFlags.DYNAMIC_SLOTS) {
// slot content that references values that might have changed,
// e.g. in a v-for
return true
}
if (patchFlag & PatchFlags.FULL_PROPS) {
if (!prevProps) {
return !!nextProps
}
// presence of this flag indicates props are always non-null
return hasPropsChanged(prevProps, nextProps!, emits)
} else if (patchFlag & PatchFlags.PROPS) {
const dynamicProps = nextVNode.dynamicProps!
for (let i = 0; i < dynamicProps.length; i++) {
const key = dynamicProps[i]
if (
nextProps![key] !== prevProps![key] &&
!isEmitListener(emits, key)
) {
return true
}
}
}
} |
Beta Was this translation helpful? Give feedback.
-
@edison1105, I see you strike out your answers, did you have a chance to discuss this behaviour? |
Beta Was this translation helpful? Give feedback.
-
Hi, I faced a strange behaviour when rendering slots from render function.
Reproduction: sfc.vuejs.org
I have parent component with a slot. Inside it I put several child components varying only by passed property type. Also there is a counter in this slot. When it is incremented, I expect only parent component to be updated, as it is not used in any of child components. However if property passed to child component is array or object, then I notice that for these components
updated
hook is also invoked (child7 & child8 in the example above), but for chid5 & child6, which either don't havedummy
property at all, or it has a primitive type likeString
. This is reproduced if I'm manually rendering slots as described in the documentation:Trying to debug this issue, I created an alternative implementation of this component using template:
With this implementation everything worked as I expected, and none of child's
updated
hook was called, no matter which property types where passed to them.Comparing generated code with my implementation, I noticed that there was used
renderSlot
function, and indeed, if I changed my implementation to:the issue has gone.
Unfortunately I haven't found this function in the official documentation, so I'm not sure what is the purpose of this function? Should it be used from outside of Vue core? And why I'm seeing this difference in behaviour?
Would appreciate any clarification, thanks!
Beta Was this translation helpful? Give feedback.
All reactions