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): clone node support Set and Map #9983

Merged
merged 4 commits into from
Jan 4, 2024
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
25 changes: 25 additions & 0 deletions packages/compiler-sfc/__tests__/compileTemplate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,31 @@ test('prefixing edge case for reused AST', () => {
expect(code).not.toMatch(`_ctx.t`)
})

test('prefixing edge case for reused AST ssr mode', () => {
const src = `
<script setup lang="ts">
import { Foo } from './foo'
</script>
<template>
<Bar>
<template #option="{ foo }"></template>
</Bar>
</template>
`
const { descriptor } = parse(src)
// compileScript triggers importUsageCheck
compileScript(descriptor, { id: 'xxx' })
expect(() =>
compileTemplate({
id: 'xxx',
filename: 'test.vue',
ast: descriptor.template!.ast,
source: descriptor.template!.content,
ssr: true,
}),
).not.toThrowError()
})

interface Pos {
line: number
column: number
Expand Down
8 changes: 5 additions & 3 deletions packages/compiler-ssr/src/transforms/ssrTransformComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ import {
ssrProcessTransitionGroup,
ssrTransformTransitionGroup,
} from './ssrTransformTransitionGroup'
import { extend, isArray, isObject, isSymbol } from '@vue/shared'
import { extend, isArray, isObject, isPlainObject, isSymbol } from '@vue/shared'
import { buildSSRProps } from './ssrTransformElement'
import {
ssrProcessTransition,
Expand Down Expand Up @@ -121,6 +121,8 @@ export const ssrTransformComponent: NodeTransform = (node, context) => {
const vnodeBranches: ReturnStatement[] = []
const clonedNode = clone(node)

console.log(clonedNode)

return function ssrPostTransformComponent() {
// Using the cloned node, build the normal VNode-based branches (for
// fallback in case the child is render-fn based). Store them in an array
Expand Down Expand Up @@ -371,10 +373,10 @@ function subTransform(
function clone(v: any): any {
if (isArray(v)) {
return v.map(clone)
} else if (isObject(v)) {
} else if (isPlainObject(v)) {
const res: any = {}
for (const key in v) {
res[key] = clone(v[key])
res[key] = clone(v[key as keyof typeof v])
}
return res
} else {
Expand Down