Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot conditionally render nodes under root template #254

Closed
jquesada2016 opened this issue Sep 20, 2021 · 5 comments
Closed

Cannot conditionally render nodes under root template #254

jquesada2016 opened this issue Sep 20, 2021 · 5 comments
Labels
C-bug Category: bug, something isn't working

Comments

@jquesada2016
Copy link
Contributor

Describe the bug
Not exactly sure how to word the title, some triage would be appreciated!

Currently, if performing an if/else statement in the root of a template! invocation, an unhandled exception occurs.

To Reproduce
Steps to reproduce the behavior:

use the following code:

use sycamore::{prelude::*, render};

fn main() {
    console_error_panic_hook::set_once();

    render(|| {
        let visibility = Signal::new(true);

        template! {
            button(on:click=cloned!((visibility) => move |_| visibility.set(!*visibility.get()))) {
                "Toggle Visibility"
            }
            (if *visibility.get() {
                template! {
                    h1 {
                        "I AM VISIBILE"
                    }
                }
            } else {
                template! {}
            })
        }
    });
}

Expected behavior
I expect the <h1> tag to be removed from the DOM without panicking nor needing a dummy wrapper node.

Environment

  • Sycamore: v0.6.0
  • Browser: Chromium Edge
  • OS: Windows 10

Additional context
The generated error is the following:
Also note that the error can be avoided by wrapping the if/else expression in a dummy <span> or <div>

Uncaught RuntimeError: unreachable
    at __rust_start_panic (index-fe88caf6e9aa8c54_bg.wasm:0x7b3e4)
    at rust_panic (index-fe88caf6e9aa8c54_bg.wasm:0x78ff0)
    at std::panicking::rust_panic_with_hook::h9852a65ac22b441a (index-fe88caf6e9aa8c54_bg.wasm:0x3d655)
    at std::panicking::begin_panic_handler::{{closure}}::hb262f7ea62636fdc (index-fe88caf6e9aa8c54_bg.wasm:0x54ee9)
    at std::sys_common::backtrace::__rust_end_short_backtrace::hbeb6eae20506157b (index-fe88caf6e9aa8c54_bg.wasm:0x7b0aa)
    at rust_begin_unwind (index-fe88caf6e9aa8c54_bg.wasm:0x74dc5)
    at std::panicking::begin_panic_fmt::h8370a52944002308 (index-fe88caf6e9aa8c54_bg.wasm:0x77cb9)
    at sycamore::utils::render::reconcile_fragments::h173454c6ccadfabc (index-fe88caf6e9aa8c54_bg.wasm:0x1a86)
    at sycamore::utils::render::insert_expression::h78c7671e519664a0 (index-fe88caf6e9aa8c54_bg.wasm:0x5025)
    at sycamore::utils::render::insert_expression::{{closure}}::h9cd3308a5537a912 (index-fe88caf6e9aa8c54_bg.wasm:0x20142)
@jquesada2016 jquesada2016 added the C-bug Category: bug, something isn't working label Sep 20, 2021
@arctic-hen7
Copy link
Contributor

I can replicate this in the Gitpod starter repo, and I'm getting this error above unreachable executed:

panicked at 'node 1 in existing nodes Vec is not a child of parent. node = DomNode(
    "No longer visible.",
)', /workspace/.cargo/registry/src/github.com-1ecc6299db9ec823/sycamore-0.6.0/src/utils/render.rs:240:17

@arctic-hen7
Copy link
Contributor

This seems to be the problematic code.

    // Sanity check: make sure all nodes in a are children of parent.
    #[cfg(debug_assertions)]
    {
        for (i, node) in a.iter().enumerate() {
            if node.parent_node().as_ref() != Some(parent) {
                panic!(
                    "node {} in existing nodes Vec is not a child of parent. node = {:#?}",
                    i, node
                );
            }
        }
    }

@arctic-hen7
Copy link
Contributor

I'm not familiar with this part of the code, so I'll defer to @lukechu10.

@lukechu10
Copy link
Member

Should be fixed by #251
Will create a new release soon.

@lukechu10
Copy link
Member

Fixed in v0.6.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug, something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants