feat: first-class match, let bindings, and bare nodes in html! control flow#4118
Draft
Madoshakalaka wants to merge 13 commits intomasterfrom
Draft
feat: first-class match, let bindings, and bare nodes in html! control flow#4118Madoshakalaka wants to merge 13 commits intomasterfrom
Madoshakalaka wants to merge 13 commits intomasterfrom
Conversation
…bodies to html! macro
match and let bindings in for bodies to html! macromatch and let bindings in for bodies to html! macro
|
Visit the preview URL for this PR (updated for commit 78dc29c): https://yew-rs--pr4118-feat-html-match-and-y4khdt3h.web.app (expires Mon, 13 Apr 2026 09:29:15 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 |
Size ComparisonDetails
✅ None of the examples has changed their size significantly. |
Benchmark - SSRYew MasterDetails
Pull RequestDetails
|
Member
Author
|
a preliminary application to the examples totals a net reduction of ~60 lines (122 insertions and 184 deletions). |
Madoshakalaka
commented
Apr 6, 2026
…ch arms Allow `=> "text",` and `=> format!(...),` in html! match arms without requiring braces, matching natural Rust match syntax.
Extend HtmlRootBraced to parse let-stmts and bare literals/expressions, bringing if/else bodies to parity with match arms and for-loop bodies.
match and let bindings in for bodies to html! macro7bd1d40 to
81b0df8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Add first-class
matchexpression support andletbindings inforloop bodies to thehtml!macro.First-class
match:Previously,
matchrequired a block wrapper and nestedhtml!calls per arm:Now
matchworks directly, following the same pattern as the existingif/elsesupport, with let binding allowed:As shown above, match arms with a single element doesn't require braces:
Note, even the commas are omittable but due to users' familarity with Rust match statements, I have preserved the commas in code examples for now.
letbindings inforbodies:Previously,
letbindings insideforloops required a nested block with an innerhtml!call:Now
letbindings can appear directly before html children:letbindings must appear before any html children (not interleaved). This avoids parsing ambiguity sinceletis not a valid start for anyHtmlTreevariant. The bindings are emitted inside theIterator::for_eachclosure, scoped to each iteration.If statements let-binding and bare return node support
This now just works:
Note:
Both worked on master:
however, only the first of the two below worked:
I consider this a bug, which is fixed now.
Multi-children arms, multi-children for-loop bodies, and multi-children if-else bodies
Example:
we now deny patterns containing unnecessarily nested html! macros
Patterns like this are now denied with a suggestion to remove the
<></>:Patterns like this are denied wit a suggestion to remove the inner
html!:Emitting a warning could have been more forgiving. Sadly it's only possible on nightly.
Checklist