Skip to content

Commit e8ddf86

Browse files
authored
fix(runtime-core): properly check forwarded slots type (#3781)
fix #3779
1 parent 4e3f82f commit e8ddf86

File tree

2 files changed

+53
-3
lines changed

2 files changed

+53
-3
lines changed

packages/runtime-core/__tests__/rendererOptimizedMode.spec.ts

+50
Original file line numberDiff line numberDiff line change
@@ -734,4 +734,54 @@ describe('renderer: optimized mode', () => {
734734
await nextTick()
735735
expect(inner(root)).toBe('<p>1</p>')
736736
})
737+
738+
// #3779
739+
test('treat slots manually written by the user as dynamic', async () => {
740+
const Middle = {
741+
setup(props: any, { slots }: any) {
742+
return slots.default!
743+
}
744+
}
745+
746+
const Comp = {
747+
setup(props: any, { slots }: any) {
748+
return () => {
749+
return (
750+
openBlock(),
751+
createBlock('div', null, [
752+
createVNode(Middle, null, {
753+
default: withCtx(
754+
() => [
755+
createVNode('div', null, [renderSlot(slots, 'default')])
756+
],
757+
undefined
758+
),
759+
_: 3 /* FORWARDED */
760+
})
761+
])
762+
)
763+
}
764+
}
765+
}
766+
767+
const loading = ref(false)
768+
const app = createApp({
769+
setup() {
770+
return () => {
771+
// important: write the slot content here
772+
const content = h('span', loading.value ? 'loading' : 'loaded')
773+
return h(Comp, null, {
774+
default: () => content
775+
})
776+
}
777+
}
778+
})
779+
780+
app.mount(root)
781+
expect(inner(root)).toBe('<div><div><span>loaded</span></div></div>')
782+
783+
loading.value = true
784+
await nextTick()
785+
expect(inner(root)).toBe('<div><div><span>loading</span></div></div>')
786+
})
737787
})

packages/runtime-core/src/vnode.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -651,12 +651,12 @@ export function normalizeChildren(vnode: VNode, children: unknown) {
651651
// a child component receives forwarded slots from the parent.
652652
// its slot type is determined by its parent's slot type.
653653
if (
654-
currentRenderingInstance.vnode.patchFlag & PatchFlags.DYNAMIC_SLOTS
654+
(currentRenderingInstance.slots as RawSlots)._ === SlotFlags.STABLE
655655
) {
656+
;(children as RawSlots)._ = SlotFlags.STABLE
657+
} else {
656658
;(children as RawSlots)._ = SlotFlags.DYNAMIC
657659
vnode.patchFlag |= PatchFlags.DYNAMIC_SLOTS
658-
} else {
659-
;(children as RawSlots)._ = SlotFlags.STABLE
660660
}
661661
}
662662
}

0 commit comments

Comments
 (0)