Skip to content

Commit 43c11cb

Browse files
mackwang112claude
andcommitted
fix(react): treat valueless boolean attrs as true in codegen
When compiling templates for React/RN, attributes written without a value (e.g. <scroll-view scroll-y>) had their value parsed as undefined, which JSON.stringify silently drops. Now such attributes correctly emit `true` in the generated render function, matching miniprogram boolean-attribute semantics. Attributes with an explicit value (e.g. scroll-y="{{undefined}}") are unchanged. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent db3f675 commit 43c11cb

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

packages/webpack-plugin/lib/template-compiler/gen-node-react.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ function genNode (node, isRoot = false) {
9090
if (node.attrsList.length) {
9191
const attrs = []
9292
node.attrsList && node.attrsList.forEach(({ name, value }) => {
93-
const attrExp = attrExpMap[name] ? attrExpMap[name] : s(value)
93+
const attrExp = attrExpMap[name] ? attrExpMap[name] : (value === undefined ? 'true' : s(value))
9494
attrs.push(`${mapAttrName(name)}: ${attrExp}`)
9595
})
9696
exp += `, { ${attrs.join(', ')} }`

0 commit comments

Comments
 (0)