Skip to content

fix(fast-build): render ?attr boolean bindings correctly in Rust renderer#7360

Merged
janechu merged 5 commits intomainfrom
users/janechu/fix-boolean-attribute-rust-render
Apr 1, 2026
Merged

fix(fast-build): render ?attr boolean bindings correctly in Rust renderer#7360
janechu merged 5 commits intomainfrom
users/janechu/fix-boolean-attribute-rust-render

Conversation

@janechu
Copy link
Copy Markdown
Collaborator

@janechu janechu commented Apr 1, 2026

Pull Request

📖 Description

Before: <input ?disabled="" data-fe-c-0-1>
After (truthy): <input disabled data-fe-c-0-1>
After (falsy): <input data-fe-c-0-1>

Root cause: resolve_attribute_bindings_in_tag in attribute.rs was treating all {{expr}} attribute values as string replacements. It had no awareness of the ? prefix convention used by FAST to mark boolean attributes.

Fix: Before replacing a {{expr}} binding, the function now checks whether the accumulated output ends with ?name=" — indicating a boolean binding. If so, it:

  1. Strips the ?name=" prefix from the output
  2. Evaluates the expression as a boolean using the existing expression::evaluate
  3. Emits the bare attribute name if truthy, or nothing if falsy

📑 Test Plan

Six new tests were added to tests/hydration.rs covering:

  • ?attr="{{expr}}" with a truthy value → bare attribute rendered
  • ?attr="{{expr}}" with a falsy value → attribute omitted
  • Comparison expression: ?disabled="{{a == b}}" (both matching and non-matching)

All 127 Rust tests pass (cargo test in crates/microsoft-fast-build).

✅ Checklist

General

  • I have included a change request file using $ npm run change
  • I have added tests for my changes.
  • I have tested my changes.
  • I have updated the project documentation to reflect my changes.
  • I have read the CONTRIBUTING documentation and followed the standards for this project.

⏭ Next Steps

The WASM artifacts in packages/fast-build/wasm/ need to be rebuilt from this crate fix (npm run build:wasm -w @microsoft/fast-build) before the fix is available to JavaScript consumers.

…erer

When a template attribute has the FAST boolean binding prefix `?`
the attribute as `?disabled=""` instead of evaluating the expression.

Fix: in `resolve_attribute_bindings_in_tag`, detect the `?name="{{expr}}"`
pattern by checking whether the accumulated output ends with `?name="`
before a `{{` is found. When detected:
- Evaluate the expression as a boolean using the existing `expression::evaluate`
- If truthy: emit the bare attribute name (e.g. `disabled`)
- If falsy: emit nothing (attribute is omitted)

Add six hydration tests covering true/false cases for simple boolean

Co-authored-by: Copilot <[email protected]>
janechu and others added 4 commits March 31, 2026 21:08
- README.md: add 'Boolean Attribute Bindings' section under Template Syntax
  explaining the ?attr="{{expr}}" convention and its rendered output
- README.md: update attribute binding markers example to include ?attr cases
- DESIGN.md: expand step 3 of 'Attribute binding markers' to describe the
  three resolution strategies: boolean (?attr), value ({{expr}}), and
  single-brace passthrough ({expr})

Co-authored-by: Copilot <[email protected]>
@janechu janechu merged commit 591266a into main Apr 1, 2026
14 checks passed
@janechu janechu deleted the users/janechu/fix-boolean-attribute-rust-render branch April 1, 2026 17:22
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