Skip to content
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

fix(runtime-core): treat slots manually written by the user as dynamic #3781

Merged
merged 3 commits into from
May 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions packages/runtime-core/__tests__/rendererOptimizedMode.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -734,4 +734,54 @@ describe('renderer: optimized mode', () => {
await nextTick()
expect(inner(root)).toBe('<p>1</p>')
})

// #3779
test('treat slots manually written by the user as dynamic', async () => {
const Middle = {
setup(props: any, { slots }: any) {
return slots.default!
}
}

const Comp = {
setup(props: any, { slots }: any) {
return () => {
return (
openBlock(),
createBlock('div', null, [
createVNode(Middle, null, {
default: withCtx(
() => [
createVNode('div', null, [renderSlot(slots, 'default')])
],
undefined
),
_: 3 /* FORWARDED */
})
])
)
}
}
}

const loading = ref(false)
const app = createApp({
setup() {
return () => {
// important: write the slot content here
const content = h('span', loading.value ? 'loading' : 'loaded')
return h(Comp, null, {
default: () => content
})
}
}
})

app.mount(root)
expect(inner(root)).toBe('<div><div><span>loaded</span></div></div>')

loading.value = true
await nextTick()
expect(inner(root)).toBe('<div><div><span>loading</span></div></div>')
})
})
6 changes: 3 additions & 3 deletions packages/runtime-core/src/vnode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -651,12 +651,12 @@ export function normalizeChildren(vnode: VNode, children: unknown) {
// a child component receives forwarded slots from the parent.
// its slot type is determined by its parent's slot type.
if (
currentRenderingInstance.vnode.patchFlag & PatchFlags.DYNAMIC_SLOTS
(currentRenderingInstance.slots as RawSlots)._ === SlotFlags.STABLE
) {
;(children as RawSlots)._ = SlotFlags.STABLE
} else {
;(children as RawSlots)._ = SlotFlags.DYNAMIC
vnode.patchFlag |= PatchFlags.DYNAMIC_SLOTS
} else {
;(children as RawSlots)._ = SlotFlags.STABLE
}
}
}
Expand Down