Skip to content

Commit 57bb37b

Browse files
committed
fix(ssr): should not hoist transformed asset urls in ssr compile
fix #3874
1 parent fec12d7 commit 57bb37b

8 files changed

+277
-154
lines changed

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

+46
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,51 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`should not hoist srcset URLs in SSR mode 1`] = `
4+
"import { resolveComponent as _resolveComponent, withCtx as _withCtx, createVNode as _createVNode } from \\"vue\\"
5+
import { ssrRenderAttr as _ssrRenderAttr, ssrRenderComponent as _ssrRenderComponent } from \\"vue/server-renderer\\"
6+
import _imports_0 from './img/foo.svg'
7+
import _imports_1 from './img/bar.svg'
8+
9+
10+
export function ssrRender(_ctx, _push, _parent, _attrs) {
11+
const _component_router_link = _resolveComponent(\\"router-link\\")
12+
13+
_push(\`<!--[--><picture><source\${
14+
_ssrRenderAttr(\\"srcset\\", _imports_0)
15+
}><img\${
16+
_ssrRenderAttr(\\"src\\", _imports_0)
17+
}></picture>\`)
18+
_push(_ssrRenderComponent(_component_router_link, null, {
19+
default: _withCtx((_, _push, _parent, _scopeId) => {
20+
if (_push) {
21+
_push(\`<picture\${
22+
_scopeId
23+
}><source\${
24+
_ssrRenderAttr(\\"srcset\\", _imports_1)
25+
}\${
26+
_scopeId
27+
}><img\${
28+
_ssrRenderAttr(\\"src\\", _imports_1)
29+
}\${
30+
_scopeId
31+
}></picture>\`)
32+
} else {
33+
return [
34+
_createVNode(\\"picture\\", null, [
35+
_createVNode(\\"source\\", {
36+
srcset: _imports_1
37+
}),
38+
_createVNode(\\"img\\", { src: _imports_1 })
39+
])
40+
]
41+
}
42+
}),
43+
_: 1 /* STABLE */
44+
}, _parent))
45+
_push(\`<!--]-->\`)
46+
}"
47+
`;
48+
349
exports[`source map 1`] = `
450
Object {
551
"mappings": ";;;wBACE,oBAA8B;IAAzB,oBAAmB,4BAAbA,WAAM",

packages/compiler-sfc/__tests__/__snapshots__/templateTransformAssetUrl.spec.ts.snap

+4-2
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,13 @@ import _imports_0 from '@svg/file.svg'
3838
3939
4040
const _hoisted_1 = _imports_0 + '#fragment'
41+
const _hoisted_2 = /*#__PURE__*/_createElementVNode(\\"use\\", { href: _hoisted_1 }, null, -1 /* HOISTED */)
42+
const _hoisted_3 = /*#__PURE__*/_createElementVNode(\\"use\\", { href: _hoisted_1 }, null, -1 /* HOISTED */)
4143
4244
export function render(_ctx, _cache) {
4345
return (_openBlock(), _createElementBlock(_Fragment, null, [
44-
_createElementVNode(\\"use\\", { href: _hoisted_1 }),
45-
_createElementVNode(\\"use\\", { href: _hoisted_1 })
46+
_hoisted_2,
47+
_hoisted_3
4648
], 64 /* STABLE_FRAGMENT */))
4749
}"
4850
`;

0 commit comments

Comments
 (0)