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

Rerender fails when rendering an iterable with None elements inside #2393

Open
ochrons opened this issue May 5, 2024 · 0 comments
Open

Rerender fails when rendering an iterable with None elements inside #2393

ochrons opened this issue May 5, 2024 · 0 comments

Comments

@ochrons
Copy link

ochrons commented May 5, 2024

Problem

When rendering a list of components again with a different list, where the first list contains some None (ie. empty nodes), there is a panic:

panicked at /home/ochrons/.cargo/registry/src/index.crates.io-6f17d22bba15001f/dioxus-core-0.5.1/src/diff/node.rs:142:49:
called `Option::unwrap()` on a `None` value

$core::option::unwrap_failed::hb5bacfb0dd292085    @    Zhef_bg.wasm:0x513587
$dioxus_core::diff::node::<impl dioxus_core::nodes::VNode>::find_last_element::h2fbafeb25fa6485a    @    Zhef_bg.wasm:0x24a677
$dioxus_core::diff::iterator::<impl dioxus_core::virtual_dom::VirtualDom>::create_and_insert_after::hdf1b487b5c58bd2e    @    Zhef_bg.wasm:0x48288f
$dioxus_core::diff::iterator::<impl dioxus_core::virtual_dom::VirtualDom>::diff_non_keyed_children::h825ddb6722191889    @    Zhef_bg.wasm:0x236220
$dioxus_core::diff::iterator::<impl dioxus_core::virtual_dom::VirtualDom>::diff_non_empty_fragment::h9f386364ef278952    @    Zhef_bg.wasm:0x2588a3
$dioxus_core::diff::node::<impl dioxus_core::nodes::VNode>::diff_dynamic_node::hccca532b469dca0c    @    Zhef_bg.wasm:0x19bbcf
$dioxus_core::diff::node::<impl dioxus_core::nodes::VNode>::diff_node::{{closure}}::he12ecb157d0a2bc4    @    Zhef_bg.wasm:0x4e38

I'm rendering a li with changing number of children

let description: impl Iterator<Item = Option<VNode>>
...
rsx! {
    li { {description} }
}

some of the items in the iterator are None. The generated HTML looks like

<li data-node-hydration="103"><!--node-id104-->Shape <!--#--><!--node-id105--> into <!--#--></li>

if I replace the empty nodes with some valid rsx (empty string), this problem doesn't occur and then the HTML looks like

<li data-node-hydration="118">
<!--node-id119-->Shape <!--#--><!--node-id120--><!--node-id121--> into <!--#--><!--node-id122--><!--node-id123--><!--#-->
</li>

Expected behavior

Shouldn't panic, but render the new list of items correctly.

Screenshots

If applicable, add screenshots to help explain your problem.

Environment:

  • Dioxus version: 0.5.1
  • Rust version: 1.78
  • OS info: Win11 WSL2
  • App platform: fullstack
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant