Skip to content

Commit

Permalink
Fix missing needs_ctx check in top-level dyn node
Browse files Browse the repository at this point in the history
  • Loading branch information
lukechu10 committed Mar 13, 2022
1 parent 1d5f164 commit 9fdff59
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
12 changes: 4 additions & 8 deletions examples/transitions/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,10 @@ fn App<G: Html>(ctx: Scope) -> View<G> {
button(on:click=move |_| update(Tab::Three)) { "Three" }
Suspense {
fallback: view! { ctx, p { "Loading..." } },
children: Children::new(ctx, move |ctx| {
view! { ctx,
({
let tab = *tab.get();
view! { ctx, Child(tab) }
})
}
}),
({
let tab = *tab.get();
view! { ctx, Child(tab) }
})
}
}
}
Expand Down
21 changes: 14 additions & 7 deletions packages/sycamore-macro/src/view/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,19 @@ impl Codegen {
ViewNode::Text(Text { value }) => quote! {
::sycamore::view::View::new_node(::sycamore::generic_node::GenericNode::text_node(#value))
},
ViewNode::Dyn(Dyn { value }) => {
quote! {
::sycamore::view::View::new_dyn(#ctx, move ||
::sycamore::view::IntoView::create(&(#value))
)
ViewNode::Dyn(d @ Dyn { value }) => {
let needs_ctx = d.needs_ctx(&ctx.to_string());
match needs_ctx {
true => quote! {
::sycamore::view::View::new_dyn_scoped(#ctx, move |#ctx|
::sycamore::view::IntoView::create(&(#value))
)
},
false => quote! {
::sycamore::view::View::new_dyn(#ctx, move ||
::sycamore::view::IntoView::create(&(#value))
)
},
}
}
}
Expand Down Expand Up @@ -481,8 +489,7 @@ impl Codegen {
let view_root = self.view_root(children);
props_quoted.extend(quote! {
.children(
::sycamore::component::Children::new(#ctx, move |__ctx| {
let __ctx: &Scope = &__ctx;
::sycamore::component::Children::new(#ctx, move |#ctx| {
#view_root
})
)
Expand Down

0 comments on commit 9fdff59

Please sign in to comment.