diff --git a/src/compiler/code_generator.ts b/src/compiler/code_generator.ts
index d7f54ac4..1013d13f 100644
--- a/src/compiler/code_generator.ts
+++ b/src/compiler/code_generator.ts
@@ -584,8 +584,12 @@ export class CodeGenerator {
expr = compileExpr(ast.attrs[key]);
if (attrName && isProp(ast.tag, attrName)) {
// we force a new string or new boolean to bypass the equality check in blockdom when patching same value
- const C = attrName === "value" ? "String" : "Boolean";
- expr = `new ${C}(${expr})`;
+ if (attrName === "value") {
+ // When the expression is falsy, fall back to an empty string
+ expr = `new String((${expr}) || "")`;
+ } else {
+ expr = `new Boolean(${expr})`;
+ }
}
const idx = block!.insertData(expr, "attr");
if (key === "t-att") {
diff --git a/tests/compiler/__snapshots__/attributes.test.ts.snap b/tests/compiler/__snapshots__/attributes.test.ts.snap
index 4738f181..c536cefd 100644
--- a/tests/compiler/__snapshots__/attributes.test.ts.snap
+++ b/tests/compiler/__snapshots__/attributes.test.ts.snap
@@ -708,6 +708,20 @@ exports[`attributes updating classes (with obj notation) 1`] = `
}"
`;
+exports[`attributes updating property with falsy value 1`] = `
+"function anonymous(app, bdom, helpers
+) {
+ let { text, createBlock, list, multi, html, toggler, comment } = bdom;
+
+ let block1 = createBlock(\`\`);
+
+ return function template(ctx, node, key = \\"\\") {
+ let attr1 = new String((ctx['v']) || \\"\\");
+ return block1([attr1]);
+ }
+}"
+`;
+
exports[`attributes various escapes 1`] = `
"function anonymous(app, bdom, helpers
) {
@@ -773,7 +787,7 @@ exports[`special cases for some specific html attributes/properties input with t
let block1 = createBlock(\`\`);
return function template(ctx, node, key = \\"\\") {
- let attr1 = new String(ctx['v']);
+ let attr1 = new String((ctx['v']) || \\"\\");
return block1([attr1]);
}
}"
@@ -787,7 +801,7 @@ exports[`special cases for some specific html attributes/properties input with t
let block1 = createBlock(\`\`);
return function template(ctx, node, key = \\"\\") {
- let attr1 = new String(ctx['v']);
+ let attr1 = new String((ctx['v']) || \\"\\");
return block1([attr1]);
}
}"
@@ -815,7 +829,7 @@ exports[`special cases for some specific html attributes/properties select with
let block1 = createBlock(\`\`);
return function template(ctx, node, key = \\"\\") {
- let attr1 = new String(ctx['value']);
+ let attr1 = new String((ctx['value']) || \\"\\");
return block1([attr1]);
}
}"
@@ -829,7 +843,7 @@ exports[`special cases for some specific html attributes/properties textarea wit
let block1 = createBlock(\`