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(compiler-ssr): TransitionGroup owns style-scoped properties on SSR #7557

Merged
merged 4 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions packages/compiler-ssr/__tests__/ssrScopeId.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,48 @@ describe('ssr: scopeId', () => {
}"
`)
})

// #7554
test('scopeId is correctly transform to scope attribute of transition-group ', () => {
expect(
compile(
`<transition-group tag="div" class="red"><span>hello</span></transition-group>`,
{
scopeId,
mode: 'module'
}
).code
).toMatchInlineSnapshot(`
"import { mergeProps as _mergeProps } from \\"vue\\"
import { ssrRenderAttrs as _ssrRenderAttrs } from \\"vue/server-renderer\\"

export function ssrRender(_ctx, _push, _parent, _attrs) {
_push(\`<div\${_ssrRenderAttrs(_mergeProps({ class: \\"red\\" }, _attrs))} data-v-xxxxxxx><span data-v-xxxxxxx>hello</span></div>\`)
}"
`)

// with dynamic tag
expect(
compile(
`<transition-group :tag="someTag" class="red"><span>hello</span></transition-group>`,
{
scopeId,
mode: 'module'
}
).code
).toMatchInlineSnapshot(`
"import { mergeProps as _mergeProps } from \\"vue\\"
import { ssrRenderAttrs as _ssrRenderAttrs } from \\"vue/server-renderer\\"

export function ssrRender(_ctx, _push, _parent, _attrs) {
_push(\`<\${
_ctx.someTag
}\${
_ssrRenderAttrs(_mergeProps({ class: \\"red\\" }, _attrs))
} data-v-xxxxxxx><span data-v-xxxxxxx>hello</span></\${
_ctx.someTag
}>\`)
}"
`)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const wipMap = new WeakMap<ComponentNode, WIPEntry>()
interface WIPEntry {
tag: AttributeNode | DirectiveNode
propsExp: string | JSChildNode | null
scopeId: string | null
}

// phase 1: build props
Expand Down Expand Up @@ -45,7 +46,8 @@ export function ssrTransformTransitionGroup(
}
wipMap.set(node, {
tag,
propsExp
propsExp,
scopeId: context.scopeId || null
})
}
}
Expand All @@ -58,14 +60,17 @@ export function ssrProcessTransitionGroup(
) {
const entry = wipMap.get(node)
if (entry) {
const { tag, propsExp } = entry
const { tag, propsExp, scopeId } = entry
if (tag.type === NodeTypes.DIRECTIVE) {
// dynamic :tag
context.pushStringPart(`<`)
context.pushStringPart(tag.exp!)
if (propsExp) {
context.pushStringPart(propsExp)
}
if (scopeId) {
context.pushStringPart(` ${scopeId}`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes made: we need to ensure a space before the scopeId since propsExp can either be non-existent or render an empty string. If there is no space, the scopeId will be connected to the open tag name and cause error.

}
context.pushStringPart(`>`)

processChildren(
Expand All @@ -89,6 +94,9 @@ export function ssrProcessTransitionGroup(
if (propsExp) {
context.pushStringPart(propsExp)
}
if (scopeId) {
context.pushStringPart(` ${scopeId}`)
}
context.pushStringPart(`>`)
processChildren(node, context, false, true)
context.pushStringPart(`</${tag.value!.content}>`)
Expand Down