From 43c11cb04d7b7323742c01f8f4d4666e1ba4c87b Mon Sep 17 00:00:00 2001 From: mackwang Date: Tue, 12 May 2026 10:44:55 +0800 Subject: [PATCH] fix(react): treat valueless boolean attrs as true in codegen When compiling templates for React/RN, attributes written without a value (e.g. ) 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 --- packages/webpack-plugin/lib/template-compiler/gen-node-react.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/webpack-plugin/lib/template-compiler/gen-node-react.js b/packages/webpack-plugin/lib/template-compiler/gen-node-react.js index 1f0a2a2afa..afd999f93b 100644 --- a/packages/webpack-plugin/lib/template-compiler/gen-node-react.js +++ b/packages/webpack-plugin/lib/template-compiler/gen-node-react.js @@ -90,7 +90,7 @@ function genNode (node, isRoot = false) { if (node.attrsList.length) { const attrs = [] node.attrsList && node.attrsList.forEach(({ name, value }) => { - const attrExp = attrExpMap[name] ? attrExpMap[name] : s(value) + const attrExp = attrExpMap[name] ? attrExpMap[name] : (value === undefined ? 'true' : s(value)) attrs.push(`${mapAttrName(name)}: ${attrExp}`) }) exp += `, { ${attrs.join(', ')} }`