Skip to content

feat: while, break/continue/return, and preamble statements in html!#4124

Merged
Madoshakalaka merged 9 commits intomasterfrom
break-continue
Apr 25, 2026
Merged

feat: while, break/continue/return, and preamble statements in html!#4124
Madoshakalaka merged 9 commits intomasterfrom
break-continue

Conversation

@Madoshakalaka
Copy link
Copy Markdown
Member

@Madoshakalaka Madoshakalaka commented Apr 9, 2026

Description

a spiritual followup of #4118

Checklist

  • I have reviewed my own code
  • I have added tests

@Madoshakalaka Madoshakalaka added the A-yew-macro Area: The yew-macro crate label Apr 9, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 9, 2026

Visit the preview URL for this PR (updated for commit b9fe62a):

https://yew-rs--pr4124-break-continue-4gv5tjtr.web.app

(expires Sat, 02 May 2026 09:37:09 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 9, 2026

Size Comparison

Details
examples master (KB) pull request (KB) diff (KB) diff (%)
actix_ssr_router 613.717 613.692 -0.024 -0.004%
async_clock 100.489 100.489 0 0.000%
axum_ssr_router 613.714 613.691 -0.022 -0.004%
boids 164.208 164.208 0 0.000%
communication_child_to_parent 93.909 93.909 0 0.000%
communication_grandchild_with_grandparent 105.905 105.905 0 0.000%
communication_grandparent_to_grandchild 102.261 102.261 0 0.000%
communication_parent_to_child 91.339 91.339 0 0.000%
contexts 106.146 106.146 0 0.000%
counter 86.170 86.170 0 0.000%
counter_functional 88.189 88.189 0 0.000%
dyn_create_destroy_apps 90.057 90.057 0 0.000%
file_upload 99.685 99.685 0 0.000%
function_delayed_input 94.799 94.799 0 0.000%
function_memory_game 169.966 169.966 0 0.000%
function_router 399.582 399.577 -0.005 -0.001%
function_todomvc 164.630 164.685 +0.055 +0.033%
futures 235.142 235.142 0 0.000%
game_of_life 100.914 100.914 0 0.000%
immutable 258.970 258.970 0 0.000%
inner_html 81.014 81.014 0 0.000%
js_callback 110.026 110.026 0 0.000%
keyed_list 176.375 176.375 0 0.000%
mount_point 84.385 84.385 0 0.000%
nested_list 113.205 113.205 0 0.000%
node_refs 91.905 91.905 0 0.000%
password_strength 1717.887 1717.887 0 0.000%
portals 93.553 93.553 0 0.000%
router 366.317 366.298 -0.020 -0.005%
suspense 113.876 113.876 0 0.000%
timer 88.755 88.755 0 0.000%
timer_functional 99.213 99.213 0 0.000%
todomvc 141.765 141.765 0 0.000%
two_apps 86.372 86.372 0 0.000%
web_worker_fib 136.687 136.687 0 0.000%
web_worker_prime 185.072 185.072 0 0.000%
webgl 83.159 83.159 0 0.000%

✅ None of the examples has changed their size significantly.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 9, 2026

Benchmark - SSR

Yew Master

Details
Benchmark Round Min (ms) Max (ms) Mean (ms) Standard Deviation
Baseline 10 310.884 311.352 311.125 0.139
Hello World 10 481.075 487.410 484.695 1.660
Function Router 10 31332.545 32010.326 31637.217 188.405
Concurrent Task 10 1005.037 1007.345 1006.775 0.722
Many Providers 10 1040.235 1074.210 1056.306 11.784

Pull Request

Details
Benchmark Round Min (ms) Max (ms) Mean (ms) Standard Deviation
Baseline 10 310.932 311.449 311.075 0.159
Hello World 10 465.695 470.929 467.868 1.936
Function Router 10 38543.741 42478.258 40826.262 1142.338
Concurrent Task 10 1005.234 1007.396 1006.792 0.714
Many Providers 10 1049.239 1111.614 1069.082 17.980

# Conflicts:
#	packages/yew-macro/tests/html_macro/for-fail.stderr
@Madoshakalaka Madoshakalaka changed the title feat: support break and continue in for loops feat: while loops, break and continue support Apr 21, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 21, 2026

Benchmark - core

Yew Master

vnode           fastest       │ slowest       │ median        │ mean          │ samples │ iters
╰─ vnode_clone  2.458 ns      │ 2.539 ns      │ 2.461 ns      │ 2.465 ns      │ 100     │ 1000000000

Pull Request

vnode           fastest       │ slowest       │ median        │ mean          │ samples │ iters
╰─ vnode_clone  2.458 ns      │ 2.498 ns      │ 2.461 ns      │ 2.463 ns      │ 100     │ 1000000000

Our MSRV is 1.85+ but users might stay on edition 2021 for various
reasons

This change wraps break/continue in Into::into(...) triggered the never-type
fallback in editions before 2024, where unconstrained ! falls back to
(), producing "(): Into<VNode> is not satisfied" on edition 2021 users.
Emit the keyword directly as a statement instead so the generated code
is edition-agnostic.
@Madoshakalaka Madoshakalaka marked this pull request as ready for review April 21, 2026 09:34
github-actions[bot]
github-actions Bot previously approved these changes Apr 21, 2026
Comment thread packages/yew-macro/src/html_tree/html_while.rs Outdated
Comment thread packages/yew-macro/src/html_tree/html_while.rs Outdated
github-actions[bot]
github-actions Bot previously approved these changes Apr 21, 2026
As a consequence, labeled `break 'outer` and `continue 'outer` work for
targeting loops defined in the surrounding Rust code, crossing the
macro boundary.

`stmts_have_divergent` detects top-level `break`/`continue`/`return`
and emits `#![allow(unreachable_code)]` on an inner expression block
(stable Rust rejects inner attributes directly in if-branch and
match-arm positions).

Docs: extended the `for`/`while` sections in lists.mdx to cover
the broader statement support, labeled break/continue, match-arm
break/continue, and the `<Type>::method(...)` qualified-path
workaround.
github-actions[bot]
github-actions Bot previously approved these changes Apr 21, 2026
github-actions[bot]
github-actions Bot previously approved these changes Apr 22, 2026
@Madoshakalaka Madoshakalaka changed the title feat: while loops, break and continue support feat: while, break/continue/return, and preamble statements in html! Apr 22, 2026
github-actions[bot]
github-actions Bot previously approved these changes Apr 22, 2026
Copy link
Copy Markdown
Member Author

@Madoshakalaka Madoshakalaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've done some external validation on two codebases, one small, one big.

Improvements on the smaller csr only codebase (a 5-user internal web app, Axum + Yew):

before after delta
frontend total LoC 4447 4382 -65 (-1.4%)
html! macro invocations 69 42 -27 (-39%)

files changed: 10 of 18

Improvements on the bigger SSR codebase (also Axum + Yew):

before after delta
total LoC across changed .rs files 16,151 16,047 -104 (-0.6%)
html! macro invocations 196 150 -46 (-23%)

files changed: 16 of 39

Neither app showed any functional regression.

The only rough edge discovered: "imperative preamble loops" are not supported. Patched in b9fe62a. A better support can land in a separate PR.

@Madoshakalaka Madoshakalaka merged commit d4e5e9f into master Apr 25, 2026
42 checks passed
@Madoshakalaka Madoshakalaka deleted the break-continue branch April 25, 2026 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-yew-macro Area: The yew-macro crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants