const msg = ref('foo')
const fn = jest.fn()
const { vnode, container } = mountWithHydration(
- '<div><!----><span>foo</span><!----><span class="foo"></span><!----><!----></div>',
+ '<div><!--[--><span>foo</span><!--[--><span class="foo"></span><!--]--><!--]--></div>',
() =>
h('div', [
[h('span', msg.value), [h('span', { class: msg.value, onClick: fn })]]
)
expect(vnode.el).toBe(container.firstChild)
+ // should remove anchors in dev mode
+ expect(vnode.el.innerHTML).toBe(`<span>foo</span><span class="foo"></span>`)
+
// start fragment 1
const fragment1 = (vnode.children as VNode[])[0]
expect(fragment1.el).toBe(vnode.el.childNodes[0])
msg.value = 'bar'
await nextTick()
- expect(vnode.el.innerHTML).toBe(
- `<!----><span>bar</span><!----><span class="bar"></span><!----><!---->`
- )
+ expect(vnode.el.innerHTML).toBe(`<span>bar</span><span class="bar"></span>`)
})
test('portal', async () => {
foo: ({ list }, _push, _parent, _scopeId) => {
if (_push) {
if (_ctx.ok) {
- _push(\`<div\${_scopeId}><!--1-->\`)
+ _push(\`<div\${_scopeId}><!--[-->\`)
_ssrRenderList(list, (i) => {
_push(\`<span\${_scopeId}></span>\`)
})
- _push(\`<!--0--></div>\`)
+ _push(\`<!--]--></div>\`)
} else {
_push(\`<!---->\`)
}
bar: ({ ok }, _push, _parent, _scopeId) => {
if (_push) {
if (ok) {
- _push(\`<div\${_scopeId}><!--1-->\`)
+ _push(\`<div\${_scopeId}><!--[-->\`)
_ssrRenderList(_ctx.list, (i) => {
_push(\`<span\${_scopeId}></span>\`)
})
- _push(\`<!--0--></div>\`)
+ _push(\`<!--]--></div>\`)
} else {
_push(\`<!---->\`)
}
.toMatchInlineSnapshot(`
"
return function ssrRender(_ctx, _push, _parent) {
- _push(\`<!--1--><div></div><!--0-->\`)
+ _push(\`<!--[--><div></div><!--]-->\`)
}"
`)
"const { ssrRenderList: _ssrRenderList } = require(\\"@vue/server-renderer\\")
return function ssrRender(_ctx, _push, _parent) {
- _push(\`<!--1-->\`)
+ _push(\`<!--[-->\`)
_ssrRenderList(_ctx.list, (i) => {
_push(\`<div></div>\`)
})
- _push(\`<!--0-->\`)
+ _push(\`<!--]-->\`)
}"
`)
})
"const { ssrRenderList: _ssrRenderList } = require(\\"@vue/server-renderer\\")
return function ssrRender(_ctx, _push, _parent) {
- _push(\`<!--1-->\`)
+ _push(\`<!--[-->\`)
_ssrRenderList(_ctx.list, (i) => {
_push(\`<div>foo<span>bar</span></div>\`)
})
- _push(\`<!--0-->\`)
+ _push(\`<!--]-->\`)
}"
`)
})
"const { ssrInterpolate: _ssrInterpolate, ssrRenderList: _ssrRenderList } = require(\\"@vue/server-renderer\\")
return function ssrRender(_ctx, _push, _parent) {
- _push(\`<!--1-->\`)
+ _push(\`<!--[-->\`)
_ssrRenderList(_ctx.list, (row, i) => {
- _push(\`<div><!--1-->\`)
+ _push(\`<div><!--[-->\`)
_ssrRenderList(row, (j) => {
_push(\`<div>\${
_ssrInterpolate(i)
_ssrInterpolate(j)
}</div>\`)
})
- _push(\`<!--0--></div>\`)
+ _push(\`<!--]--></div>\`)
})
- _push(\`<!--0-->\`)
+ _push(\`<!--]-->\`)
}"
`)
})
"const { ssrInterpolate: _ssrInterpolate, ssrRenderList: _ssrRenderList } = require(\\"@vue/server-renderer\\")
return function ssrRender(_ctx, _push, _parent) {
- _push(\`<!--1-->\`)
+ _push(\`<!--[-->\`)
_ssrRenderList(_ctx.list, (i) => {
- _push(\`<!--1-->\${_ssrInterpolate(i)}<!--0-->\`)
+ _push(\`<!--[-->\${_ssrInterpolate(i)}<!--]-->\`)
})
- _push(\`<!--0-->\`)
+ _push(\`<!--]-->\`)
}"
`)
})
"const { ssrInterpolate: _ssrInterpolate, ssrRenderList: _ssrRenderList } = require(\\"@vue/server-renderer\\")
return function ssrRender(_ctx, _push, _parent) {
- _push(\`<!--1-->\`)
+ _push(\`<!--[-->\`)
_ssrRenderList(_ctx.list, (i) => {
_push(\`<span>\${_ssrInterpolate(i)}</span>\`)
})
- _push(\`<!--0-->\`)
+ _push(\`<!--]-->\`)
}"
`)
})
"const { ssrInterpolate: _ssrInterpolate, ssrRenderList: _ssrRenderList } = require(\\"@vue/server-renderer\\")
return function ssrRender(_ctx, _push, _parent) {
- _push(\`<!--1-->\`)
+ _push(\`<!--[-->\`)
_ssrRenderList(_ctx.list, (i) => {
- _push(\`<!--1--><span>\${
+ _push(\`<!--[--><span>\${
_ssrInterpolate(i)
}</span><span>\${
_ssrInterpolate(i + 1)
- }</span><!--0-->\`)
+ }</span><!--]-->\`)
})
- _push(\`<!--0-->\`)
+ _push(\`<!--]-->\`)
}"
`)
})
"const { ssrInterpolate: _ssrInterpolate, ssrRenderList: _ssrRenderList } = require(\\"@vue/server-renderer\\")
return function ssrRender(_ctx, _push, _parent) {
- _push(\`<!--1-->\`)
+ _push(\`<!--[-->\`)
_ssrRenderList(_ctx.list, ({ foo }, index) => {
_push(\`<div>\${_ssrInterpolate(foo + _ctx.bar + index)}</div>\`)
})
- _push(\`<!--0-->\`)
+ _push(\`<!--]-->\`)
}"
`)
})
"
return function ssrRender(_ctx, _push, _parent) {
if (_ctx.foo) {
- _push(\`<!--1-->hello<!--0-->\`)
+ _push(\`<!--[-->hello<!--]-->\`)
} else {
_push(\`<!---->\`)
}
"
return function ssrRender(_ctx, _push, _parent) {
if (_ctx.foo) {
- _push(\`<!--1--><div>hi</div><div>ho</div><!--0-->\`)
+ _push(\`<!--[--><div>hi</div><div>ho</div><!--]-->\`)
} else {
_push(\`<!---->\`)
}
return function ssrRender(_ctx, _push, _parent) {
if (_ctx.foo) {
- _push(\`<!--1-->\`)
+ _push(\`<!--[-->\`)
_ssrRenderList(_ctx.list, (i) => {
_push(\`<div></div>\`)
})
- _push(\`<!--0-->\`)
+ _push(\`<!--]-->\`)
} else {
_push(\`<!---->\`)
}
"
return function ssrRender(_ctx, _push, _parent) {
if (_ctx.foo) {
- _push(\`<!--1--><div>hi</div><div>ho</div><!--0-->\`)
+ _push(\`<!--[--><div>hi</div><div>ho</div><!--]-->\`)
} else {
_push(\`<div></div>\`)
}
asFragment = false
) {
if (asFragment) {
- context.pushStringPart(`<!--1-->`)
+ context.pushStringPart(`<!--[-->`)
}
for (let i = 0; i < children.length; i++) {
const child = children[i]
}
}
if (asFragment) {
- context.pushStringPart(`<!--0-->`)
+ context.pushStringPart(`<!--]-->`)
}
}
needFragmentWrapper
)
// v-for always renders a fragment
- context.pushStringPart(`<!--1-->`)
+ context.pushStringPart(`<!--[-->`)
context.pushStatement(
createCallExpression(context.helper(SSR_RENDER_LIST), [
node.source,
renderLoop
])
)
- context.pushStringPart(`<!--0-->`)
+ context.pushStringPart(`<!--]-->`)
}
parentSuspense: SuspenseBoundary | null,
optimized = false
): Node | null => {
- const isFragmentStart = isComment(node) && node.data === '1'
+ const isFragmentStart = isComment(node) && node.data === '['
if (__DEV__ && isFragmentStart) {
// in dev mode, replace comment anchors with invisible text nodes
// for easier debugging
while (node) {
node = nextSibling(node)
if (node && isComment(node)) {
- if (node.data === '1') match++
- if (node.data === '0') {
+ if (node.data === '[') match++
+ if (node.data === ']') {
if (match === 0) {
return nextSibling(node)
} else {
)
).toBe(
`<div>parent<div class="child">` +
- `<!--1--><span>from slot</span><!--0-->` +
+ `<!--[--><span>from slot</span><!--]-->` +
`</div></div>`
)
})
)
).toBe(
- `<div>parent<div class="child"><!--1-->fallback<!--0--></div></div>`
+ `<div>parent<div class="child"><!--[-->fallback<!--]--></div></div>`
)
})
)
).toBe(
`<div>parent<div class="child">` +
- `<!--1--><span>from slot</span><!--0-->` +
+ `<!--[--><span>from slot</span><!--]-->` +
`</div></div>`
)
})
expect(await renderToString(app)).toBe(
`<div>parent<div class="child">` +
- `<!--1--><span>from slot</span><!--0-->` +
+ `<!--[--><span>from slot</span><!--]-->` +
`</div></div>`
)
})
])
)
).toBe(
- `<div>foo<span>bar</span><!--1--><span>baz</span><!--0--><!--qux--></div>`
+ `<div>foo<span>bar</span><!--[--><span>baz</span><!--]--><!--qux--></div>`
)
})
}
})
- expect(await renderToString(app)).toBe(`<!--1--><div>async</div><!--0-->`)
+ expect(await renderToString(app)).toBe(`<!--[--><div>async</div><!--]-->`)
})
test('with async component', async () => {
}
})
- expect(await renderToString(app)).toBe(`<!--1--><div>async</div><!--0-->`)
+ expect(await renderToString(app)).toBe(`<!--[--><div>async</div><!--]-->`)
})
test('fallback', async () => {
})
expect(await renderToString(app)).toBe(
- `<!--1--><div>fallback</div><!--0-->`
+ `<!--[--><div>fallback</div><!--]-->`
)
expect('Uncaught error in async setup').toHaveBeenWarned()
})
parentComponent: ComponentInternalInstance
) {
// template-compiled slots are always rendered as fragments
- push(`<!--1-->`)
+ push(`<!--[-->`)
const slotFn = slots[slotName]
if (slotFn) {
if (slotFn.length > 1) {
} else if (fallbackRenderFn) {
fallbackRenderFn()
}
- push(`<!--0-->`)
+ push(`<!--]-->`)
}
try {
if (renderContent) {
const { push, getBuffer } = createBuffer()
- push(`<!--1-->`)
+ push(`<!--[-->`)
renderContent(push)
- push(`<!--0-->`)
+ push(`<!--]-->`)
return await getBuffer()
} else {
return []
} catch {
if (renderFallback) {
const { push, getBuffer } = createBuffer()
- push(`<!--1-->`)
+ push(`<!--[-->`)
renderFallback(push)
- push(`<!--0-->`)
+ push(`<!--]-->`)
return getBuffer()
} else {
return []
push(children ? `<!--${children}-->` : `<!---->`)
break
case Fragment:
- push(`<!--1-->`) // open
+ push(`<!--[-->`) // open
renderVNodeChildren(push, children as VNodeArrayChildren, parentComponent)
- push(`<!--0-->`) // close
+ push(`<!--]-->`) // close
break
default:
if (shapeFlag & ShapeFlags.ELEMENT) {