Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,24 @@ return function render(_ctx, _cache) {
}"
`;

exports[`stringify static html > eligible content + v-once node 1`] = `
"const { setBlockTracking: _setBlockTracking, toDisplayString: _toDisplayString, createTextVNode: _createTextVNode, createElementVNode: _createElementVNode, createStaticVNode: _createStaticVNode, openBlock: _openBlock, createElementBlock: _createElementBlock } = Vue

return function render(_ctx, _cache) {
return (_openBlock(), _createElementBlock("div", null, [
_cache[0] || (
_setBlockTracking(-1, true),
(_cache[0] = _createElementVNode("div", null, [
_createTextVNode(_toDisplayString(_ctx.msg), 1 /* TEXT */)
])).cacheIndex = 0,
_setBlockTracking(1),
_cache[0]
),
_cache[1] || (_cache[1] = _createStaticVNode("<span class=\\"foo\\">foo</span><span class=\\"foo\\">foo</span><span class=\\"foo\\">foo</span><span class=\\"foo\\">foo</span><span class=\\"foo\\">foo</span>", 5))
]))
}"
`;

exports[`stringify static html > escape 1`] = `
"const { toDisplayString: _toDisplayString, normalizeClass: _normalizeClass, createElementVNode: _createElementVNode, createStaticVNode: _createStaticVNode, openBlock: _openBlock, createElementBlock: _createElementBlock } = Vue

Expand Down
10 changes: 10 additions & 0 deletions packages/compiler-dom/__tests__/transforms/stringifyStatic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -525,4 +525,14 @@ describe('stringify static html', () => {

expect(code).toMatchSnapshot()
})

test('eligible content + v-once node', () => {
const { code } = compileWithStringify(
`<div>
<div v-once>{{ msg }}</div>
${repeat(`<span class="foo">foo</span>`, StringifyThresholds.ELEMENT_WITH_BINDING_COUNT)}
</div>`,
)
expect(code).toMatchSnapshot()
})
})
6 changes: 6 additions & 0 deletions packages/compiler-dom/src/transforms/stringifyStatic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
type TextCallNode,
type TransformContext,
createCallExpression,
findDir,
isStaticArgOf,
} from '@vue/compiler-core'
import {
Expand Down Expand Up @@ -213,6 +214,11 @@ function analyzeNode(node: StringifiableNode): [number, number] | false {
return false
}

// v-once nodes should not be stringified
if (node.type === NodeTypes.ELEMENT && findDir(node, 'once', true)) {
return false
}

if (node.type === NodeTypes.TEXT_CALL) {
return [1, 0]
}
Expand Down
Loading