Skip to content

Commit f6d9926

Browse files
authoredOct 11, 2024··
fix(compiler-dom): avoid stringify option with null value (#12096)
close #12093
1 parent 7ad289e commit f6d9926

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed
 

‎packages/compiler-dom/__tests__/transforms/__snapshots__/stringifyStatic.spec.ts.snap

+17
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,23 @@ return function render(_ctx, _cache) {
3232
}"
3333
`;
3434

35+
exports[`stringify static html > should bail for <option> elements with null values 1`] = `
36+
"const { createElementVNode: _createElementVNode, openBlock: _openBlock, createElementBlock: _createElementBlock } = Vue
37+
38+
return function render(_ctx, _cache) {
39+
return (_openBlock(), _createElementBlock("div", null, _cache[0] || (_cache[0] = [
40+
_createElementVNode("select", null, [
41+
_createElementVNode("option", { value: null }),
42+
_createElementVNode("option", { value: "1" }),
43+
_createElementVNode("option", { value: "1" }),
44+
_createElementVNode("option", { value: "1" }),
45+
_createElementVNode("option", { value: "1" }),
46+
_createElementVNode("option", { value: "1" })
47+
], -1 /* HOISTED */)
48+
])))
49+
}"
50+
`;
51+
3552
exports[`stringify static html > should bail for <option> elements with number values 1`] = `
3653
"const { createElementVNode: _createElementVNode, openBlock: _openBlock, createElementBlock: _createElementBlock } = Vue
3754

‎packages/compiler-dom/__tests__/transforms/stringifyStatic.spec.ts

+11
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,17 @@ describe('stringify static html', () => {
470470
expect(code).toMatchSnapshot()
471471
})
472472

473+
test('should bail for <option> elements with null values', () => {
474+
const { ast, code } = compileWithStringify(
475+
`<div><select><option :value="null" />${repeat(
476+
`<option value="1" />`,
477+
StringifyThresholds.ELEMENT_WITH_BINDING_COUNT,
478+
)}</select></div>`,
479+
)
480+
expect(ast.cached).toMatchObject([cachedArrayBailedMatcher()])
481+
expect(code).toMatchSnapshot()
482+
})
483+
473484
test('eligible content (elements > 20) + non-eligible content', () => {
474485
const { code } = compileWithStringify(
475486
`<div>${repeat(

‎packages/compiler-dom/src/transforms/stringifyStatic.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,7 @@ function analyzeNode(node: StringifiableNode): [number, number] | false {
261261
isOptionTag &&
262262
isStaticArgOf(p.arg, 'value') &&
263263
p.exp &&
264-
p.exp.ast &&
265-
p.exp.ast.type !== 'StringLiteral'
264+
!p.exp.isStatic
266265
) {
267266
return bail()
268267
}

0 commit comments

Comments
 (0)
Please sign in to comment.