Skip to content

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

Merged
Madoshakalaka merged 2 commits intomasterfrom
feat/children-renderer-into-prop-value
Apr 4, 2026
Merged

feat: add IntoPropValue<ChildrenRenderer<VNode>> for string-like types#4095
Madoshakalaka merged 2 commits intomasterfrom
feat/children-renderer-into-prop-value

Conversation

@Madoshakalaka
Copy link
Copy Markdown
Member

@Madoshakalaka Madoshakalaka commented Mar 31, 2026

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

github-actions Bot commented Mar 31, 2026

Benchmark - core

Yew Master

vnode           fastest       │ slowest       │ median        │ mean          │ samples │ iters
╰─ vnode_clone  2.094 ns      │ 3.354 ns      │ 2.096 ns      │ 2.123 ns      │ 100     │ 1000000000

Pull Request

vnode           fastest       │ slowest       │ median        │ mean          │ samples │ iters
╰─ vnode_clone  2.093 ns      │ 2.154 ns      │ 2.098 ns      │ 2.101 ns      │ 100     │ 1000000000

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 31, 2026

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

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

(expires Sat, 11 Apr 2026 08:13:36 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 31, 2026

Size Comparison

Details
examples master (KB) pull request (KB) diff (KB) diff (%)
async_clock 100.818 100.817 -0.001 -0.001%
boids 168.450 168.471 +0.021 +0.012%
communication_child_to_parent 94.076 94.097 +0.021 +0.022%
communication_grandchild_with_grandparent 105.913 105.920 +0.007 +0.006%
communication_grandparent_to_grandchild 102.256 102.276 +0.021 +0.020%
communication_parent_to_child 91.486 91.507 +0.021 +0.022%
contexts 105.977 105.976 -0.001 -0.001%
counter 86.798 86.818 +0.021 +0.024%
counter_functional 88.834 88.854 +0.021 +0.023%
dyn_create_destroy_apps 90.713 90.733 +0.021 +0.023%
file_upload 99.812 99.832 +0.021 +0.021%
function_delayed_input 94.814 94.813 -0.001 -0.001%
function_memory_game 173.667 173.688 +0.021 +0.012%
function_router 397.257 397.109 -0.147 -0.037%
function_todomvc 164.956 164.923 -0.033 -0.020%
futures 235.551 235.551 0 0.000%
game_of_life 105.099 105.053 -0.046 -0.044%
immutable 259.626 259.783 +0.157 +0.061%
inner_html 81.341 81.341 0 0.000%
js_callback 109.956 109.977 +0.021 +0.019%
keyed_list 180.408 180.429 +0.021 +0.011%
mount_point 84.714 84.713 -0.001 -0.001%
nested_list 113.657 113.634 -0.023 -0.021%
node_refs 92.089 92.085 -0.004 -0.004%
password_strength 1719.252 1719.265 +0.013 +0.001%
portals 93.558 93.571 +0.014 +0.015%
router 367.981 367.994 +0.013 +0.003%
suspense 113.965 113.959 -0.006 -0.005%
timer 88.943 88.964 +0.021 +0.023%
timer_functional 99.369 99.346 -0.023 -0.024%
todomvc 142.661 142.639 -0.022 -0.016%
two_apps 86.711 86.688 -0.022 -0.026%
web_worker_fib 136.460 136.480 +0.021 +0.015%
web_worker_prime 187.644 187.644 0 0.000%
webgl 83.485 83.485 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[bot]
github-actions Bot previously approved these changes Mar 31, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 31, 2026

Benchmark - SSR

Yew Master

Details
Benchmark Round Min (ms) Max (ms) Mean (ms) Standard Deviation
Baseline 10 291.335 291.996 291.566 0.231
Hello World 10 505.151 517.200 508.870 4.400
Function Router 10 31271.977 32420.093 31957.572 332.837
Concurrent Task 10 1005.664 1007.285 1006.588 0.620
Many Providers 10 1140.025 1173.741 1156.154 10.263

Pull Request

Details
Benchmark Round Min (ms) Max (ms) Mean (ms) Standard Deviation
Baseline 10 291.257 296.048 291.978 1.444
Hello World 10 480.293 483.455 481.949 1.134
Function Router 10 31515.193 32149.024 31768.015 170.259
Concurrent Task 10 1005.898 1007.381 1006.836 0.535
Many Providers 10 1091.931 1114.130 1103.549 7.427

@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.

@Madoshakalaka
Copy link
Copy Markdown
Member Author

Added some documentation for the sake of completeness.

@Madoshakalaka Madoshakalaka merged commit 8af333b into master Apr 4, 2026
37 checks passed
@Madoshakalaka Madoshakalaka added the A-yew Area: The main yew crate label Apr 4, 2026
shan-shaji pushed a commit to shan-shaji/yew that referenced this pull request Apr 19, 2026
yewstack#4095)

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

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.

* docs: document string children for ChildrenRenderer<VNode>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-yew Area: The main yew crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Struggling with ways to convert someting into Html.

1 participant