Add VNode::html_from_raw
Description
Add method:
impl VNode {
fn from_raw_html(html: &str) -> Self { ... }
}
Fixes #2841
Checklist
- [x] I have reviewed my own code
- [ ] I have added tests
I can't get any tests for this to pass:
#[cfg(all(test, not(target_arch = "wasm32")))]
mod tests {
use super::*;
use crate::html;
#[test]
fn from_raw_html_works() {
let vnode = html! {
<><div>{"c"}</div></>
};
eprintln!("{:#?}", vnode);
let from_raw = VNode::from_raw_html("<div>c</div>");
eprintln!();
eprintln!("{:#?}", from_raw);
assert_eq!(vnode, from_raw);
}
}
Test Output
running 1 test
test virtual_dom::vnode::tests::from_raw_html_works ... FAILED
failures:
---- virtual_dom::vnode::tests::from_raw_html_works stdout ----
VList {
children: [
VTag {
inner: Other {
tag: "div",
children: VList {
children: [
VText { text: "c" },
],
fully_keyed: KnownMissingKeys,
key: None,
},
},
listeners: None,
node_ref: NodeRef { references: None },
attributes: Static(
[],
),
key: None,
},
],
fully_keyed: KnownMissingKeys,
key: None,
}
VList {
children: [
VTag {
inner: Other {
tag: "div",
children: VList {
children: [
VText { text: "c" },
],
fully_keyed: KnownMissingKeys,
key: None,
},
},
listeners: None,
node_ref: NodeRef { references: None },
attributes: Static(
[],
),
key: None,
},
],
fully_keyed: KnownMissingKeys,
key: None,
}
thread 'virtual_dom::vnode::tests::from_raw_html_works' panicked at 'assertion failed: `(left == right)`
left: `VList { children: [VTag { inner: Other { tag: "div", children: VList { children: [VText { text: "c" }], fully_keyed: KnownMissingKeys, key: None } }, listeners: None, node_ref: NodeRef { references: None }, attributes: Static([]), key: None }], fully_keyed: KnownMissingKeys, key: None }`,
right: `VList { children: [VTag { inner: Other { tag: "div", children: VList { children: [VText { text: "c" }], fully_keyed: KnownMissingKeys, key: None } }, listeners: None, node_ref: NodeRef { references: None }, attributes: Static([]), key: None }], fully_keyed: KnownMissingKeys, key: None }`', packages/yew/src/virtual_dom/vnode.rs:288:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
I don't understand why exactly this test fails
Benchmark - SSR
Yew Master
| Benchmark | Round | Min (ms) | Max (ms) | Mean (ms) | Standard Deviation |
|---|---|---|---|---|---|
| Baseline | 10 | 371.549 | 372.557 | 371.751 | 0.292 |
| Hello World | 10 | 707.307 | 716.183 | 709.373 | 2.887 |
| Function Router | 10 | 2344.654 | 2380.579 | 2361.433 | 9.339 |
| Concurrent Task | 10 | 1007.340 | 1009.305 | 1008.532 | 0.636 |
Pull Request
| Benchmark | Round | Min (ms) | Max (ms) | Mean (ms) | Standard Deviation |
|---|---|---|---|---|---|
| Baseline | 10 | 393.117 | 393.747 | 393.393 | 0.204 |
| Hello World | 10 | 709.091 | 722.206 | 714.874 | 4.073 |
| Function Router | 10 | 2332.463 | 2365.355 | 2349.607 | 9.417 |
| Concurrent Task | 10 | 1007.499 | 1009.495 | 1008.602 | 0.549 |
Size Comparison
| examples | master (KB) | pull request (KB) | diff (KB) | diff (%) |
|---|---|---|---|---|
| async_clock | 106.139 | 108.607 | +2.469 | +2.326% |
| boids | 170.366 | 172.852 | +2.485 | +1.459% |
| communication_child_to_parent | 90.027 | 92.507 | +2.479 | +2.754% |
| communication_grandchild_with_grandparent | 104.879 | 107.219 | +2.340 | +2.231% |
| communication_grandparent_to_grandchild | 100.744 | 103.092 | +2.348 | +2.330% |
| communication_parent_to_child | 87.134 | 89.614 | +2.480 | +2.847% |
| contexts | 107.358 | 109.881 | +2.522 | +2.350% |
| counter | 85.050 | 87.520 | +2.470 | +2.904% |
| counter_functional | 85.522 | 88.000 | +2.478 | +2.897% |
| dyn_create_destroy_apps | 87.882 | 90.355 | +2.474 | +2.815% |
| file_upload | 99.645 | 102.067 | +2.423 | +2.431% |
| function_memory_game | 162.865 | 165.333 | +2.468 | +1.515% |
| function_router | 347.254 | 349.764 | +2.510 | +0.723% |
| function_todomvc | 157.658 | 160.150 | +2.492 | +1.581% |
| futures | 221.943 | 224.211 | +2.268 | +1.022% |
| game_of_life | 104.550 | 107.018 | +2.468 | +2.360% |
| immutable | 180.990 | 184.614 | +3.624 | +2.002% |
| inner_html | 81.913 | 84.126 | +2.213 | +2.702% |
| js_callback | 110.877 | 113.428 | +2.551 | +2.301% |
| keyed_list | 195.523 | 198.045 | +2.521 | +1.290% |
| mount_point | 84.658 | 87.130 | +2.472 | +2.920% |
| nested_list | 111.624 | 114.168 | +2.544 | +2.279% |
| node_refs | 92.534 | 95.009 | +2.475 | +2.674% |
| password_strength | 1546.897 | 1549.191 | +2.294 | +0.148% |
| portals | 95.945 | 98.518 | +2.572 | +2.681% |
| router | 317.068 | 319.561 | +2.492 | +0.786% |
| simple_ssr | 151.578 | 154.110 | +2.532 | +1.671% |
| ssr_router | 392.338 | 394.761 | +2.423 | +0.618% |
| suspense | 108.617 | 111.172 | +2.555 | +2.352% |
| timer | 87.913 | 90.381 | +2.468 | +2.807% |
| todomvc | 138.961 | 141.444 | +2.483 | +1.787% |
| two_apps | 85.714 | 88.190 | +2.477 | +2.889% |
| web_worker_fib | 152.032 | 154.515 | +2.482 | +1.633% |
| webgl | 84.350 | 86.846 | +2.496 | +2.959% |
⚠️ The following examples have changed their size significantly:
| examples | master (KB) | pull request (KB) | diff (KB) | diff (%) |
|---|---|---|---|---|
| async_clock | 106.139 | 108.607 | +2.469 | +2.326% |
| boids | 170.366 | 172.852 | +2.485 | +1.459% |
| communication_child_to_parent | 90.027 | 92.507 | +2.479 | +2.754% |
| communication_grandchild_with_grandparent | 104.879 | 107.219 | +2.340 | +2.231% |
| communication_grandparent_to_grandchild | 100.744 | 103.092 | +2.348 | +2.330% |
| communication_parent_to_child | 87.134 | 89.614 | +2.480 | +2.847% |
| contexts | 107.358 | 109.881 | +2.522 | +2.350% |
| counter | 85.050 | 87.520 | +2.470 | +2.904% |
| counter_functional | 85.522 | 88.000 | +2.478 | +2.897% |
| dyn_create_destroy_apps | 87.882 | 90.355 | +2.474 | +2.815% |
| file_upload | 99.645 | 102.067 | +2.423 | +2.431% |
| function_memory_game | 162.865 | 165.333 | +2.468 | +1.515% |
| function_todomvc | 157.658 | 160.150 | +2.492 | +1.581% |
| futures | 221.943 | 224.211 | +2.268 | +1.022% |
| game_of_life | 104.550 | 107.018 | +2.468 | +2.360% |
| immutable | 180.990 | 184.614 | +3.624 | +2.002% |
| inner_html | 81.913 | 84.126 | +2.213 | +2.702% |
| js_callback | 110.877 | 113.428 | +2.551 | +2.301% |
| keyed_list | 195.523 | 198.045 | +2.521 | +1.290% |
| mount_point | 84.658 | 87.130 | +2.472 | +2.920% |
| nested_list | 111.624 | 114.168 | +2.544 | +2.279% |
| node_refs | 92.534 | 95.009 | +2.475 | +2.674% |
| portals | 95.945 | 98.518 | +2.572 | +2.681% |
| simple_ssr | 151.578 | 154.110 | +2.532 | +1.671% |
| suspense | 108.617 | 111.172 | +2.555 | +2.352% |
| timer | 87.913 | 90.381 | +2.468 | +2.807% |
| todomvc | 138.961 | 141.444 | +2.483 | +1.787% |
| two_apps | 85.714 | 88.190 | +2.477 | +2.889% |
| web_worker_fib | 152.032 | 154.515 | +2.482 | +1.633% |
| webgl | 84.350 | 86.846 | +2.496 | +2.959% |
Visit the preview URL for this PR (updated for commit 4850d52):
https://yew-rs-api--pr2842-html-from-raw-v3ysmy42.web.app
(expires Sun, 13 Nov 2022 16:20:14 GMT)
🔥 via Firebase Hosting GitHub Action 🌎
I ran twiggy and couldn't find why the example sizes have increased
>> twiggy diff dist-master/counter_functional-e727bce1d90867ec_bg.wasm dist/counter_functional-68f055d125afbdf4_bg.wasm
Delta Bytes │ Item
─────────────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
+4888 ┊ yew::dom_bundle::blist::<impl yew::dom_bundle::traits::Reconcilable for yew::virtual_dom::vlist::VList>::reconcile::h3b49db0a1910a2e4
-4887 ┊ yew::dom_bundle::blist::<impl yew::dom_bundle::traits::Reconcilable for yew::virtual_dom::vlist::VList>::reconcile::hcec22fdf4efde7ed
+4654 ┊ yew::dom_bundle::subtree_root::SubtreeData::add_listener::he60c74cb9c491716
-4654 ┊ yew::dom_bundle::subtree_root::SubtreeData::add_listener::hfb123d1e19ace6ab
-3487 ┊ yew::dom_bundle::btag::<impl yew::dom_bundle::traits::Reconcilable for yew::virtual_dom::vtag::VTag>::reconcile_node::hc9aed8af95781db4
+3487 ┊ yew::dom_bundle::btag::<impl yew::dom_bundle::traits::Reconcilable for yew::virtual_dom::vtag::VTag>::reconcile_node::hcc8a910b8f9c3cf2
+2552 ┊ yew::dom_bundle::bnode::<impl yew::dom_bundle::traits::Reconcilable for yew::virtual_dom::vnode::VNode>::reconcile_node::hb83ae633db34963b
-2432 ┊ yew::dom_bundle::bnode::<impl yew::dom_bundle::traits::Reconcilable for yew::virtual_dom::vnode::VNode>::reconcile_node::haa9882c26c7d6dae
-2128 ┊ <yew::html::component::lifecycle::CompStateInner<COMP> as yew::html::component::lifecycle::Stateful>::view::h4a5156692d8a5084
+2127 ┊ <yew::html::component::lifecycle::CompStateInner<COMP> as yew::html::component::lifecycle::Stateful>::view::ha408f976479b440a
-1707 ┊ yew::dom_bundle::btag::<impl yew::dom_bundle::traits::Reconcilable for yew::virtual_dom::vtag::VTag>::attach::ha04af1b849a7f344
+1707 ┊ yew::dom_bundle::btag::<impl yew::dom_bundle::traits::Reconcilable for yew::virtual_dom::vtag::VTag>::attach::hbafa97d9203417fd
-1547 ┊ <yew::html::component::lifecycle::RenderRunner as yew::scheduler::Runnable>::run::h71f8f501bc6997ba
+1547 ┊ <yew::html::component::lifecycle::RenderRunner as yew::scheduler::Runnable>::run::h9059b47824a820c3
-1378 ┊ <yew::dom_bundle::subtree_root::EventDescriptor as core::clone::Clone>::clone::h8c0f4d5bac6e7c5b
+1378 ┊ <yew::dom_bundle::subtree_root::EventDescriptor as core::clone::Clone>::clone::heee1eba6baa66bb0
+1365 ┊ yew::dom_bundle::subtree_root::SubtreeData::add_listener::{{closure}}::h5485b2fea9c87858
-1365 ┊ yew::dom_bundle::subtree_root::SubtreeData::add_listener::{{closure}}::h859eaacd84003540
+1356 ┊ yew::dom_bundle::braw::<impl yew::dom_bundle::traits::Reconcilable for yew::virtual_dom::vraw::VRaw>::attach::h942a92bf9964c21b
+1214 ┊ yew::scheduler::TopologicalQueue::push::h4a53d3f11591026b
+1831 ┊ ... and 677 more.
+4521 ┊ Σ [697 Total Rows]
I have no idea what's causing the binary size increase. Perhaps it's the additional web-sys feature? Twiggy also doesn't show anything useful
Clippy errors will be fixed in #2881
Sorry, it took me so long to get back to this. Should be all good to go now
I couldn't figure out anything regarding size increase. If I had to guess, maybe it's because yew now enables more web-sys features? Not quite sure. 2KB isn't much, especially with how .wasm files compress.
I'm going to go ahead and merge this