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:
@@ -339,6 +339,15 @@ describe('compiler: transform <slot> outlets', () => {
|
||||
})
|
||||
})
|
||||
|
||||
test('slot with slotted: true', async () => {
|
||||
const ast = parseWithSlots(`<slot/>`, { slotted: true })
|
||||
expect((ast.children[0] as ElementNode).codegenNode).toMatchObject({
|
||||
type: NodeTypes.JS_CALL_EXPRESSION,
|
||||
callee: RENDER_SLOT,
|
||||
arguments: [`$slots`, `"default"`, `{}`, `undefined`, `true`]
|
||||
})
|
||||
})
|
||||
|
||||
test(`error on unexpected custom directive on <slot>`, () => {
|
||||
const onError = jest.fn()
|
||||
const source = `<slot v-foo />`
|
||||
|
||||
Reference in New Issue
Block a user