mirror of
https://github.com/leptos-rs/leptos
synced 2024-11-10 23:04:24 +00:00
Better errors on renderer bugs (fixes issue #112)
This commit is contained in:
parent
0cbab3ef87
commit
6ddef3018f
2 changed files with 20 additions and 6 deletions
|
@ -140,3 +140,15 @@ macro_rules! is_dev {
|
|||
cfg!(debug_assertions)
|
||||
};
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub fn __leptos_renderer_error(expected: &'static str, location: &'static str) -> web_sys::Node {
|
||||
cfg_if! {
|
||||
if #[cfg(debug_assertions)] {
|
||||
panic!("Yikes! Something went wrong while Leptos was trying to traverse the DOM to set up the reactive system.\n\nThe renderer expected {expected:?} as {location} and couldn't get it.\n\nThis is almost certainly a bug in the framework, not your application. Please open an issue on GitHub and provide example code if possible.\n\nIn the meantime, these bugs are often related to <Component/>s or {{block}}s when they are siblings of each other. Try wrapping those in a <span> or <div> for now. Sorry for the pain!")
|
||||
} else {
|
||||
_ = expected;
|
||||
panic!("Renderer error. You can find a more detailed error message if you compile in debug mode.".to_string())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -309,14 +309,14 @@ fn element_to_tokens(
|
|||
quote_spanned! {
|
||||
span => let #this_el_ident = #debug_name;
|
||||
//log::debug!("next_sibling ({})", #debug_name);
|
||||
let #this_el_ident = #prev_sib.next_sibling().unwrap_throw();
|
||||
let #this_el_ident = #prev_sib.next_sibling().unwrap_or_else(|| ::leptos::__leptos_renderer_error(#debug_name, "nextSibling"));
|
||||
//log::debug!("=> got {}", #this_el_ident.node_name());
|
||||
}
|
||||
} else {
|
||||
quote_spanned! {
|
||||
span => let #this_el_ident = #debug_name;
|
||||
//log::debug!("first_child ({})", #debug_name);
|
||||
let #this_el_ident = #parent.first_child().unwrap_throw();
|
||||
let #this_el_ident = #parent.first_child().unwrap_or_else(|| ::leptos::__leptos_renderer_error(#debug_name, "firstChild"));
|
||||
//log::debug!("=> got {}", #this_el_ident.node_name());
|
||||
}
|
||||
};
|
||||
|
@ -738,13 +738,13 @@ fn block_to_tokens(
|
|||
let location = if let Some(sibling) = &prev_sib {
|
||||
quote_spanned! {
|
||||
span => //log::debug!("-> next sibling");
|
||||
let #name = #sibling.next_sibling().unwrap_throw();
|
||||
let #name = #sibling.next_sibling().unwrap_or_else(|| ::leptos::__leptos_renderer_error("{block}", "nextSibling"));
|
||||
//log::debug!("\tnext sibling = {}", #name.node_name());
|
||||
}
|
||||
} else {
|
||||
quote_spanned! {
|
||||
span => //log::debug!("\\|/ first child on {}", #parent.node_name());
|
||||
let #name = #parent.first_child().unwrap_throw();
|
||||
let #name = #parent.first_child().unwrap_or_else(|| ::leptos::__leptos_renderer_error("{block}", "firstChild"));
|
||||
//log::debug!("\tfirst child = {}", #name.node_name());
|
||||
}
|
||||
};
|
||||
|
@ -860,6 +860,8 @@ fn component_to_tokens(
|
|||
mode: Mode,
|
||||
is_first_child: bool,
|
||||
) -> PrevSibChange {
|
||||
let component_name = ident_from_tag_name(&node.name);
|
||||
let component_name = format!("<{component_name}/>");
|
||||
let create_component = create_component(cx, node, mode);
|
||||
let span = node.name.span();
|
||||
|
||||
|
@ -896,13 +898,13 @@ fn component_to_tokens(
|
|||
let starts_at = if let Some(prev_sib) = prev_sib {
|
||||
quote::quote! {{
|
||||
//log::debug!("starts_at = next_sibling");
|
||||
#prev_sib.next_sibling().unwrap_throw()
|
||||
#prev_sib.next_sibling().unwrap_or_else(|| ::leptos::__leptos_renderer_error(#component_name, "nextSibling"))
|
||||
//log::debug!("ok starts_at");
|
||||
}}
|
||||
} else {
|
||||
quote::quote! {{
|
||||
//log::debug!("starts_at first_child");
|
||||
#parent.first_child().unwrap_throw()
|
||||
#parent.first_child().unwrap_or_else(|| ::leptos::__leptos_renderer_error(#component_name, "firstChild"))
|
||||
//log::debug!("starts_at ok");
|
||||
}}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue