From: daiwei Date: Fri, 24 Jan 2025 01:11:12 +0000 (+0800) Subject: wip: properly inject fallthrough attrs to alternate node X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f725472d548656f70dc753984ffd1a7c7171e1d3;p=thirdparty%2Fvuejs%2Fcore.git wip: properly inject fallthrough attrs to alternate node --- diff --git a/packages/compiler-ssr/__tests__/ssrVSkip.spec.ts b/packages/compiler-ssr/__tests__/ssrVSkip.spec.ts index 57f47d1d20..3c1c8cfc02 100644 --- a/packages/compiler-ssr/__tests__/ssrVSkip.spec.ts +++ b/packages/compiler-ssr/__tests__/ssrVSkip.spec.ts @@ -363,4 +363,39 @@ describe('ssr: v-skip', () => { }" `) }) + + test('fragment with component v-skip', () => { + expect( + compile(` +
+ + `).code, + ).toMatchInlineSnapshot(` + "const { withCtx: _withCtx, resolveComponent: _resolveComponent, createVNode: _createVNode } = require("vue") + const { ssrRenderComponent: _ssrRenderComponent } = require("vue/server-renderer") + + return function ssrRender(_ctx, _push, _parent, _attrs) { + const _component_Comp = _resolveComponent("Comp") + + _push(\`
\`) + if (_ctx.ok) { + _push(\`\`) + } else { + _push(_ssrRenderComponent(_component_Comp, null, { + default: _withCtx((_, _push, _parent, _scopeId) => { + if (_push) { + _push(\`\`) + } else { + return [ + _createVNode("span") + ] + } + }), + _: 1 /* STABLE */ + }, _parent)) + } + _push(\`\`) + }" + `) + }) }) diff --git a/packages/compiler-ssr/src/transforms/ssrInjectFallthroughAttrs.ts b/packages/compiler-ssr/src/transforms/ssrInjectFallthroughAttrs.ts index 719c67aec8..33c6cc545c 100644 --- a/packages/compiler-ssr/src/transforms/ssrInjectFallthroughAttrs.ts +++ b/packages/compiler-ssr/src/transforms/ssrInjectFallthroughAttrs.ts @@ -67,11 +67,14 @@ export const ssrInjectFallthroughAttrs: NodeTransform = (node, context) => { } } injectFallthroughAttrs(node.children[0]) - } else if (node.type === NodeTypes.SKIP) { - const children = filterChild(node.alternate) - children.forEach(injectFallthroughAttrs) } else if (hasSingleChild(parent)) { - injectFallthroughAttrs(node) + if (node.type === NodeTypes.SKIP) { + // for skip node, inject fallthrough attrs to the alternate branch + const children = filterChild(node.alternate) + injectFallthroughAttrs(children[0]) + } else { + injectFallthroughAttrs(node) + } } }