Skip to content

fix(compiler-dom): leave out boolean attributes with falsy constant values when stringifying - #15910

Open
lprnmns wants to merge 1 commit into
vuejs:mainfrom
lprnmns:fix/stringify-falsy-boolean-attrs
Open

lprnmns wants to merge 1 commit into
vuejs:mainfrom
lprnmns:fix/stringify-falsy-boolean-attrs

Conversation

@lprnmns

@lprnmns lprnmns commented Oct 17, 2026 •

Copy link
Copy Markdown

When a static subtree gets stringified, a constant binding on a boolean attribute is only left out if its source is exactly false (#6568), or if it is hidden with a number. Any other falsy constant is printed as the attribute's value:

<input :disabled="0">  <!-- stringified as <input disabled="0"> -->
<input :checked="!1">  <!-- stringified as <input checked="false"> -->

A boolean attribute is on whenever it is present, so these inputs end up disabled/checked. At runtime and in SSR (includeBooleanAttr), the same bindings leave the attribute out. So the result depends on whether the surrounding markup reaches the stringify thresholds. I found this by rendering random static templates with and without stringification in jsdom and comparing the DOM. For example, :disabled="0" on a <textarea> came out disabled only when stringified.

This applies the existing hidden check to every boolean attribute and every falsy constant (0, -0, !1, 1 > 2, ...), using includeBooleanAttr like the runtime does.

The new stringifyStatic.spec.ts cases fail without the change. vitest run for compiler-dom/core/sfc and server-renderer (1651 tests), tsc --noEmit, ESLint and Prettier pass.

Summary by CodeRabbit

  • Bug Fixes
    • Static HTML output now correctly omits boolean attributes, including disabled, checked, and hidden, when their bound values are false.

@coderabbitai

coderabbitai Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2bbd2a69-f26c-4c37-9405-4fda39659b47
📥 Commits

Reviewing files that changed from the base of the PR and between bf5f0dd and be13568.

📒 Files selected for processing: 2
  • packages/compiler-dom/__tests__/transforms/stringifyStatic.spec.ts
  • packages/compiler-dom/src/transforms/stringifyStatic.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

📝 Walkthrough

Static stringification now omits constant false values for boolean attributes and hidden. Tests cover disabled and checked with four falsy expressions.

Changes: Static stringification

Layer / File(s) Summary
Omit false boolean attributes
packages/compiler-dom/src/transforms/stringifyStatic.ts, packages/compiler-dom/__tests__/transforms/stringifyStatic.spec.ts
The omission check now covers boolean attributes and hidden when includeBooleanAttr returns false. Tests verify that four falsy expressions produce repeated <input> elements without disabled or checked.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Suggested reviewers: chirokas

Merge Risk: ⚪ Minimal · up to be135

Static rendering omits false boolean attributes while preserving empty-string and string-valued hidden attributes, consistent with runtime behavior. No merge-blocking risk is established.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: omitting boolean attributes when constant values are falsy during static stringification.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant