Skip to content

Commit

Permalink
fix(compiler-ssr): disable v-once transform in ssr vdom fallback branch
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 authored and IAmSSH committed Apr 29, 2023
1 parent e72e6d3 commit b473582
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/compiler-core/src/transforms/vOnce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const seen = new WeakSet()

export const transformOnce: NodeTransform = (node, context) => {
if (node.type === NodeTypes.ELEMENT && findDir(node, 'once', true)) {
if (seen.has(node) || context.inVOnce) {
if (seen.has(node) || context.inVOnce || context.inSSR) {
return
}
seen.add(node)
Expand Down
28 changes: 28 additions & 0 deletions packages/compiler-ssr/__tests__/ssrComponent.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,34 @@ describe('ssr: components', () => {
`)
})

// #7644
test('slot content with v-once', () => {
const { code } = compile(`<foo><bar v-once /></foo>`)
expect(code).not.toMatch(`_cache`)
expect(compile(`<foo><bar v-once /></foo>`).code).toMatchInlineSnapshot(`
"const { resolveComponent: _resolveComponent, withCtx: _withCtx, createVNode: _createVNode } = require(\\"vue\\")
const { ssrRenderComponent: _ssrRenderComponent } = require(\\"vue/server-renderer\\")
return function ssrRender(_ctx, _push, _parent, _attrs) {
const _component_foo = _resolveComponent(\\"foo\\")
const _component_bar = _resolveComponent(\\"bar\\")
_push(_ssrRenderComponent(_component_foo, _attrs, {
default: _withCtx((_, _push, _parent, _scopeId) => {
if (_push) {
_push(_ssrRenderComponent(_component_bar, null, null, _parent, _scopeId))
} else {
return [
_createVNode(_component_bar)
]
}
}),
_: 1 /* STABLE */
}, _parent))
}"
`)
})

describe('built-in fallthroughs', () => {
test('transition', () => {
expect(compile(`<transition><div/></transition>`).code)
Expand Down

0 comments on commit b473582

Please sign in to comment.