feat: add IntoPropValue<ChildrenRenderer<VNode>> for string-like types#4095
feat: add IntoPropValue<ChildrenRenderer<VNode>> for string-like types#4095Madoshakalaka wants to merge 1 commit intomasterfrom
Conversation
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.
Benchmark - coreYew MasterPull Request |
|
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 🌎 |
Size ComparisonDetails
✅ None of the examples has changed their size significantly. |
Benchmark - SSRYew MasterDetails
Pull RequestDetails
|
|
@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. |
|
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. |
Resolves #3443
Description
impl_into_prop_value_via_attr_value!macro to also generateIntoPropValue<ChildrenRenderer<VNode>>, so string-like types (String,&AttrValue,Rc<str>,Cow<'static, str>) can be passed directly as children to components usingchildren: ChildrenpropsIntoPropValue<ChildrenRenderer<VNode>> for AttrValueimpl that is now generated by the macroThis addresses patterns from #3443 that users repeatedly reported as friction:
String/format!()as children:&AttrValueas children:Remaining issues from #3443
Custom types with
From<T> for VNodeorDisplaystill don't work directly in html! blocks - they requireIntoPropValue<VNode>which cannot be blanket-impl'd fromInto<VNode>withoutspecialization(rust-lang/rust#31844). These are tracked as expected-fail tests incustom-type-in-block-fail.rs.Checklist