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(ssr): fix hydration error for slot outlet inside transition-group #9937

Merged
merged 4 commits into from
Dec 30, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions packages/compiler-ssr/__tests__/ssrSlotOutlet.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,20 @@ describe('ssr: <slot>', () => {
}"
`)
})

test('inside transition-group', () => {
const { code } = compile(
`<TransitionGroup tag="div"><slot/></TransitionGroup>`,
)
expect(code).toMatch(ssrHelpers[SSR_RENDER_SLOT_INNER])
expect(code).toMatchInlineSnapshot(`
"const { ssrRenderSlotInner: _ssrRenderSlotInner, ssrRenderAttrs: _ssrRenderAttrs } = require("vue/server-renderer")

return function ssrRender(_ctx, _push, _parent, _attrs) {
_push(\`<div\${_ssrRenderAttrs(_attrs)}>\`)
_ssrRenderSlotInner(_ctx.$slots, "default", {}, null, _push, _parent, null, true)
_push(\`</div>\`)
}"
`)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
NodeTypes,
type SlotOutletNode,
TRANSITION,
TRANSITION_GROUP,
createCallExpression,
createFunctionExpression,
isSlotOutlet,
Expand Down Expand Up @@ -37,16 +38,18 @@ export const ssrTransformSlotOutlet: NodeTransform = (node, context) => {

let method = SSR_RENDER_SLOT

// #3989
// #3989, #9933
// check if this is a single slot inside a transition wrapper - since
// transition will unwrap the slot fragment into a single vnode at runtime,
// transition/transition-group will unwrap the slot fragment and render its children at runtime,
// we need to avoid rendering the slot as a fragment.
const parent = context.parent
if (
parent &&
parent.type === NodeTypes.ELEMENT &&
parent.tagType === ElementTypes.COMPONENT &&
resolveComponentType(parent, context, true) === TRANSITION &&
[TRANSITION, TRANSITION_GROUP].includes(
resolveComponentType(parent, context, true) as symbol,
) &&
edison1105 marked this conversation as resolved.
Show resolved Hide resolved
parent.children.filter(c => c.type === NodeTypes.ELEMENT).length === 1
) {
method = SSR_RENDER_SLOT_INNER
Expand Down