Skip to content

fix: allow bare None for Option props in html! macro#4021

Open
Madoshakalaka wants to merge 1 commit intomasterfrom
fix/none-value-sentinel
Open

fix: allow bare None for Option props in html! macro#4021
Madoshakalaka wants to merge 1 commit intomasterfrom
fix/none-value-sentinel

Conversation

@Madoshakalaka
Copy link
Member

@Madoshakalaka Madoshakalaka commented Feb 28, 2026

Fixes #3747
Unblocks #4020

  • Properties derive: for props whose type is Option<_>, generates an additional {name}_none() setter that assigns Some(None) directly, bypassing IntoPropValue
  • html! macro: detects when a prop value is literally None and routes to the _none setter instead of the normal one

This means None never goes through trait resolution, so it works regardless of how many IntoPropValue<Option<T>> impls exist.

Caveat

If a user passes None to a non-Option prop (e.g. foo: String with foo={None}), the error changes from a type inference failure to no method named foo_none found. It might be a bit cryptic to the user but both are compile errors pointing to the correct line, only the message text differs. I think this is acceptible as it is an uncommon mistake.

checklist

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

The html! macro now detects bare `None` and bypasses IntoPropValue,
avoiding type inference ambiguity when multiple Option<X> -> Option<Y>
impls exist. Fixes #3747.
@Madoshakalaka Madoshakalaka added the A-yew-macro Area: The yew-macro crate label Feb 28, 2026
@github-actions
Copy link

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

https://yew-rs-api--pr4021-fix-none-value-senti-m40zxj84.web.app

(expires Sat, 07 Mar 2026 22:36:07 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

@github-actions
Copy link

Benchmark - core

Yew Master

vnode           fastest       │ slowest       │ median        │ mean          │ samples │ iters
╰─ vnode_clone  2.403 ns      │ 3.681 ns      │ 2.407 ns      │ 2.714 ns      │ 100     │ 1000000000

Pull Request

vnode           fastest       │ slowest       │ median        │ mean          │ samples │ iters
╰─ vnode_clone  2.403 ns      │ 3.653 ns      │ 2.407 ns      │ 2.491 ns      │ 100     │ 1000000000

@github-actions
Copy link

Size Comparison

Details
examples master (KB) pull request (KB) diff (KB) diff (%)
async_clock 100.197 100.197 0 0.000%
boids 168.081 168.081 0 0.000%
communication_child_to_parent 93.469 93.469 0 0.000%
communication_grandchild_with_grandparent 105.248 105.248 0 0.000%
communication_grandparent_to_grandchild 101.606 101.606 0 0.000%
communication_parent_to_child 90.899 90.899 0 0.000%
contexts 105.149 105.149 0 0.000%
counter 86.282 86.282 0 0.000%
counter_functional 88.273 88.273 0 0.000%
dyn_create_destroy_apps 90.323 90.323 0 0.000%
file_upload 99.346 99.346 0 0.000%
function_delayed_input 94.373 94.373 0 0.000%
function_memory_game 172.935 172.935 0 0.000%
function_router 405.536 405.536 0 0.000%
function_todomvc 164.148 164.148 0 0.000%
futures 235.159 235.159 0 0.000%
game_of_life 104.718 104.718 0 0.000%
immutable 255.688 255.688 0 0.000%
inner_html 80.803 80.803 0 0.000%
js_callback 109.376 109.376 0 0.000%
keyed_list 179.725 179.725 0 0.000%
mount_point 84.145 84.145 0 0.000%
nested_list 113.057 113.057 0 0.000%
node_refs 91.526 91.526 0 0.000%
password_strength 1728.825 1728.825 0 0.000%
portals 93.032 93.032 0 0.000%
router 376.132 376.132 0 0.000%
suspense 113.454 113.454 0 0.000%
timer 88.634 88.634 0 0.000%
timer_functional 98.874 98.874 0 0.000%
todomvc 142.088 142.088 0 0.000%
two_apps 86.146 86.146 0 0.000%
web_worker_fib 136.219 136.219 0 0.000%
web_worker_prime 187.441 187.441 0 0.000%
webgl 83.222 83.222 0 0.000%

✅ None of the examples has changed their size significantly.

@github-actions
Copy link

Benchmark - SSR

Yew Master

Details
Benchmark Round Min (ms) Max (ms) Mean (ms) Standard Deviation
Baseline 10 291.102 292.513 291.433 0.422
Hello World 10 463.162 469.128 464.943 1.689
Function Router 10 32421.639 32815.794 32619.656 133.329
Concurrent Task 10 1005.877 1007.855 1006.866 0.621
Many Providers 10 1052.043 1096.928 1071.351 15.299

Pull Request

Details
Benchmark Round Min (ms) Max (ms) Mean (ms) Standard Deviation
Baseline 10 291.026 292.446 291.448 0.504
Hello World 10 477.192 501.938 482.455 7.229
Function Router 10 33778.071 34626.689 34216.423 236.237
Concurrent Task 10 1005.909 1007.497 1007.066 0.500
Many Providers 10 1097.093 1136.013 1117.441 14.690

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.

props of type Option<T> cannot use None

1 participant