Skip to content

Commit 49f4072

Browse files
authored
fix(compiler-ssr): keep the order of imports expression for the fallback branch of SSR (#3448)
fix #3447
1 parent 7769513 commit 49f4072

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

packages/compiler-sfc/__tests__/compileTemplate.spec.ts

+16
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,19 @@ test('preprocessor errors', () => {
137137
`The end of the string reached with no closing bracket ) found.`
138138
)
139139
})
140+
141+
// #3447
142+
test('should generate the correct imports expression', () => {
143+
const { code } = compile({
144+
filename: 'example.vue',
145+
source: `
146+
<img src="./foo.svg"/>
147+
<Comp>
148+
<img src="./bar.svg"/>
149+
</Comp>
150+
`,
151+
ssr: true
152+
})
153+
expect(code).toMatch(`_ssrRenderAttr(\"src\", _imports_1)`)
154+
expect(code).toMatch(`_createVNode(\"img\", { src: _imports_1 })`)
155+
})

packages/compiler-ssr/src/transforms/ssrTransformComponent.ts

+1
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ function subTransform(
293293
// inherit parent scope analysis state
294294
childContext.scopes = { ...parentContext.scopes }
295295
childContext.identifiers = { ...parentContext.identifiers }
296+
childContext.imports = parentContext.imports
296297
// traverse
297298
traverseNode(childRoot, childContext)
298299
// merge helpers/components/directives into parent context

0 commit comments

Comments
 (0)