Skip to content

feat: add IntoPropValue<ChildrenRenderer<VNode>> for string-like types#4095

Open
Madoshakalaka wants to merge 1 commit intomasterfrom
feat/children-renderer-into-prop-value
Open

feat: add IntoPropValue<ChildrenRenderer<VNode>> for string-like types#4095
Madoshakalaka wants to merge 1 commit intomasterfrom
feat/children-renderer-into-prop-value

Conversation

@Madoshakalaka
Copy link
Copy Markdown
Member

Resolves #3443

Description

  • Extend the impl_into_prop_value_via_attr_value! macro to also generate IntoPropValue<ChildrenRenderer<VNode>>, so string-like types (String, &AttrValue, Rc<str>, Cow<'static, str>) can be passed directly as children to components using children: Children props
  • Remove the standalone IntoPropValue<ChildrenRenderer<VNode>> for AttrValue impl that is now generated by the macro

This addresses patterns from #3443 that users repeatedly reported as friction:

String / format!() as children:

// Previously required `.into()` or `Html::from()`; now works directly
html! { <Text>{ format!("Hello {}", name) }</Text> }

&AttrValue as children:

// Previously required `{&*props.text}` workaround; now works directly
html! { <Text>{&props.text}</Text> }

Remaining issues from #3443

Custom types with From<T> for VNode or Display still don't work directly in html! blocks - they require IntoPropValue<VNode> which cannot be blanket-impl'd from Into<VNode> without specialization (rust-lang/rust#31844). These are tracked as expected-fail tests in custom-type-in-block-fail.rs.

Checklist

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

String, &AttrValue, Rc<str>, and Cow<'static, str> can now be used
directly as children of components with `children: Children` props,
without requiring an explicit `.into()` call.
@github-actions
Copy link
Copy Markdown

Benchmark - core

Yew Master

vnode           fastest       │ slowest       │ median        │ mean          │ samples │ iters
╰─ vnode_clone  2.155 ns      │ 3.417 ns      │ 2.16 ns       │ 2.29 ns       │ 100     │ 1000000000

Pull Request

vnode           fastest       │ slowest       │ median        │ mean          │ samples │ iters
╰─ vnode_clone  2.126 ns      │ 3.374 ns      │ 2.129 ns      │ 2.156 ns      │ 100     │ 1000000000

@github-actions
Copy link
Copy Markdown

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

https://yew-rs-api--pr4095-feat-children-render-gfpri0eh.web.app

(expires Tue, 07 Apr 2026 06:15:53 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

@github-actions
Copy link
Copy Markdown

Size Comparison

Details
examples master (KB) pull request (KB) diff (KB) diff (%)
async_clock 100.819 100.818 -0.001 -0.001%
boids 168.447 168.468 +0.021 +0.012%
communication_child_to_parent 94.073 94.094 +0.021 +0.022%
communication_grandchild_with_grandparent 105.919 105.926 +0.007 +0.006%
communication_grandparent_to_grandchild 102.261 102.281 +0.021 +0.020%
communication_parent_to_child 91.483 91.504 +0.021 +0.022%
contexts 105.975 105.974 -0.001 -0.001%
counter 86.797 86.817 +0.021 +0.024%
counter_functional 88.832 88.853 +0.021 +0.023%
dyn_create_destroy_apps 90.714 90.734 +0.021 +0.023%
file_upload 99.811 99.831 +0.021 +0.021%
function_delayed_input 94.805 94.804 -0.001 -0.001%
function_memory_game 173.670 173.690 +0.021 +0.012%
function_router 394.755 394.607 -0.147 -0.037%
function_todomvc 164.958 164.925 -0.033 -0.020%
futures 235.550 235.550 0 0.000%
game_of_life 105.098 105.052 -0.046 -0.044%
immutable 259.579 259.736 +0.157 +0.061%
inner_html 81.340 81.340 0 0.000%
js_callback 109.959 109.979 +0.021 +0.019%
keyed_list 180.406 180.427 +0.021 +0.011%
mount_point 84.713 84.712 -0.001 -0.001%
nested_list 113.658 113.635 -0.023 -0.021%
node_refs 92.084 92.080 -0.004 -0.004%
password_strength 1719.253 1719.266 +0.013 +0.001%
portals 93.558 93.571 +0.014 +0.015%
router 365.401 365.414 +0.013 +0.003%
suspense 113.961 113.955 -0.006 -0.005%
timer 88.942 88.963 +0.021 +0.023%
timer_functional 99.371 99.348 -0.023 -0.024%
todomvc 142.660 142.638 -0.022 -0.016%
two_apps 86.710 86.688 -0.022 -0.026%
web_worker_fib 136.458 136.479 +0.021 +0.015%
web_worker_prime 187.639 187.639 0 0.000%
webgl 83.486 83.486 0 0.000%

✅ None of the examples has changed their size significantly.

@Madoshakalaka Madoshakalaka marked this pull request as ready for review March 31, 2026 06:29
@github-actions
Copy link
Copy Markdown

Benchmark - SSR

Yew Master

Details
Benchmark Round Min (ms) Max (ms) Mean (ms) Standard Deviation
Baseline 10 310.865 311.214 311.056 0.123
Hello World 10 479.489 494.015 482.761 4.185
Function Router 10 34249.301 35549.800 34917.320 397.068
Concurrent Task 10 1005.366 1007.303 1006.616 0.527
Many Providers 10 1085.669 1133.132 1106.075 16.657

Pull Request

Details
Benchmark Round Min (ms) Max (ms) Mean (ms) Standard Deviation
Baseline 10 310.746 311.956 311.113 0.346
Hello World 10 466.514 469.610 468.670 1.006
Function Router 10 34884.417 38416.807 36093.801 1053.567
Concurrent Task 10 1005.438 1007.486 1006.586 0.684
Many Providers 10 1100.334 1129.514 1110.731 8.478

@Madoshakalaka
Copy link
Copy Markdown
Member Author

Madoshakalaka commented Mar 31, 2026

@dandedotdev @cecton @futursolo @ranile

This PR is a bit late to the party but I'm still mentioning some relevant people from the (very long) issue. I believe this PR suffices to close the issue but I'm open to suggestions or different opinions.

@Madoshakalaka
Copy link
Copy Markdown
Member Author

I also surveyed all examples and website pages for any refactor opportunities enabled by this PR. Sadly there is none.

I believe it's OK because using string-like types as children is natural for users (and perhaps LLMs) (otherwise nobody would have "Struggled to convert something to HTML" as the issue titled said, which shows this is a natural pattern people had written without thinking (and failed to compile at that time)) and this will just be an invisible yet real user experience improvement.

That said, suggestions welcome on documentation approaches.

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.

Struggling with ways to convert someting into Html.

1 participant