Skip to content

Commit

Permalink
Remove component NodeRef (#2783)
Browse files Browse the repository at this point in the history
* don't attach noderef to components, add test case

* remove node_ref from VNode and VComp

* fmt & macro tests

* remove uneeded test & todo

this test is done at compile time. there's no node_ref field so it can't be set

* feature soundness & clippy

* add marker field, in an attempt to reduce bundle size

* Update migration guide
  • Loading branch information
hamza1311 committed Jul 20, 2022
1 parent 924792c commit 544990a
Show file tree
Hide file tree
Showing 11 changed files with 279 additions and 241 deletions.
8 changes: 3 additions & 5 deletions examples/nested_list/src/list.rs
@@ -1,6 +1,6 @@
use std::rc::Rc;

use yew::html::{ChildrenRenderer, NodeRef};
use yew::html::ChildrenRenderer;
use yew::prelude::*;
use yew::virtual_dom::{VChild, VComp};

Expand Down Expand Up @@ -46,10 +46,8 @@ where
impl From<ListVariant> for Html {
fn from(variant: ListVariant) -> Html {
match variant.props {
Variants::Header(props) => {
VComp::new::<ListHeader>(props, NodeRef::default(), None).into()
}
Variants::Item(props) => VComp::new::<ListItem>(props, NodeRef::default(), None).into(),
Variants::Header(props) => VComp::new::<ListHeader>(props, None).into(),
Variants::Item(props) => VComp::new::<ListItem>(props, None).into(),
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions packages/yew-macro/src/html_tree/html_component.rs
Expand Up @@ -106,7 +106,6 @@ impl ToTokens for HtmlComponent {
Some(quote! { ::yew::html::ChildrenRenderer::new(#children) })
};
let build_props = props.build_properties_tokens(&props_ty, children_renderer);
let node_ref = props.special().wrap_node_ref_attr();
let key = props.special().wrap_key_attr();
let use_close_tag = close
.as_ref()
Expand All @@ -122,7 +121,7 @@ impl ToTokens for HtmlComponent {
{
#use_close_tag
let __yew_props = #build_props;
::yew::virtual_dom::VChild::<#ty>::new(__yew_props, #node_ref, #key)
::yew::virtual_dom::VChild::<#ty>::new(__yew_props, #key)
}
});
}
Expand Down
16 changes: 16 additions & 0 deletions packages/yew-macro/tests/html_macro/component-fail.rs
Expand Up @@ -65,6 +65,20 @@ fn compile_fail() {
html! { <Child value=1 ref={()} ..props ref={()} /> };
html! { <Child ref={()} ref={()} value=1 with props /> };
html! { <Child ref={()} ref={()} value=1 ..props /> };
html! { <Child with props r#ref={()} r#ref={()} /> };
html! { <Child ..props r#ref={()} r#ref={()} /> };
html! { <Child with props r#ref={()} r#ref={()} value=1 /> };
html! { <Child ..props r#ref={()} r#ref={()} value=1 /> };
html! { <Child with props r#ref={()} value=1 r#ref={()} /> };
html! { <Child ..props r#ref={()} value=1 r#ref={()} /> };
html! { <Child with props value=1 r#ref={()} r#ref={()} /> };
html! { <Child ..props value=1 r#ref={()} r#ref={()} /> };
html! { <Child value=1 with props r#ref={()} r#ref={()} /> };
html! { <Child value=1 ..props r#ref={()} r#ref={()} /> };
html! { <Child value=1 r#ref={()} with props r#ref={()} /> };
html! { <Child value=1 r#ref={()} ..props r#ref={()} /> };
html! { <Child r#ref={()} r#ref={()} value=1 with props /> };
html! { <Child r#ref={()} r#ref={()} value=1 ..props /> };
html! { <Child ..blah /> };
html! { <Child value=1 ..props /> };
html! { <Child .. props value=1 /> };
Expand All @@ -79,6 +93,8 @@ fn compile_fail() {
html! { <Child int=1 string={3} /> };
html! { <Child int=1 ref={()} /> };
html! { <Child int=1 ref={()} ref={()} /> };
html! { <Child int=1 r#ref={()} /> };
html! { <Child int=1 r#ref={()} r#ref={()} /> };
html! { <Child int=0u32 /> };
html! { <Child string="abc" /> };
html! { </Child> };
Expand Down

0 comments on commit 544990a

Please sign in to comment.