perf: support only attaching slot scope ids when necessary

This is done by adding the `slotted: false` option to:

- compiler-dom
- compiler-ssr
- compiler-sfc (forwarded to template compiler)

At runtime, only slotted component will render slot fragments with
slot scope Ids. For SSR, only slotted component will add slot scope Ids
to rendered slot content. This should improve both runtime performance
and reduce SSR rendered markup size.

Note: requires SFC tooling (e.g. `vue-loader` and `vite`) to pass on
the `slotted` option from the SFC descriptoer to the `compileTemplate`
call.
This commit is contained in:
Evan You
2021-03-05 12:12:49 -05:00
parent f74b16ccfe
commit 02cbbb718c
11 changed files with 110 additions and 31 deletions

View File

@@ -40,7 +40,7 @@ describe('scopeId runtime support', () => {
const Child = {
__scopeId: 'child',
render(this: any) {
return h('div', renderSlot(this.$slots, 'default'))
return h('div', renderSlot(this.$slots, 'default', {}, undefined, true))
}
}
const Child2 = {
@@ -92,7 +92,9 @@ describe('scopeId runtime support', () => {
render(this: any) {
// <Wrapper><slot/></Wrapper>
return h(Wrapper, null, {
default: withCtx(() => [renderSlot(this.$slots, 'default')])
default: withCtx(() => [
renderSlot(this.$slots, 'default', {}, undefined, true)
])
})
}
}
@@ -118,8 +120,8 @@ describe('scopeId runtime support', () => {
render(h(Root), root)
expect(serializeInner(root)).toBe(
`<div class="wrapper" wrapper slotted root>` +
`<div root wrapper-s slotted-s>hoisted</div>` +
`<div root wrapper-s slotted-s>dynamic</div>` +
`<div root slotted-s>hoisted</div>` +
`<div root slotted-s>dynamic</div>` +
`</div>`
)
@@ -144,9 +146,9 @@ describe('scopeId runtime support', () => {
render(h(Root2), root2)
expect(serializeInner(root2)).toBe(
`<div class="wrapper" wrapper slotted root>` +
`<div class="wrapper" wrapper root wrapper-s slotted-s>` +
`<div root wrapper-s>hoisted</div>` +
`<div root wrapper-s>dynamic</div>` +
`<div class="wrapper" wrapper root slotted-s>` +
`<div root>hoisted</div>` +
`<div root>dynamic</div>` +
`</div>` +
`</div>`
)