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

Panic / warnings from use_effect on ReadOnlySignal ? #3196

Closed
rogusdev opened this issue Nov 11, 2024 · 2 comments · Fixed by #3201
Closed

Panic / warnings from use_effect on ReadOnlySignal ? #3196

rogusdev opened this issue Nov 11, 2024 · 2 comments · Fixed by #3201
Assignees
Labels
bug Something isn't working core relating to the core implementation of the virtualdom

Comments

@rogusdev
Copy link
Contributor

rogusdev commented Nov 11, 2024

Problem

Using dioxus main with the repro app below, in release mode I encounter a panic (two actually), and in debug mode I get a warning (the same one twice in a row actually). It seems to be related to ReadOnlySignals and their subscriptions, but the context is unclear to me, other than it seems to come from a use_effect I am doing. The panic does not come from my code, it comes from dioxus' ReactiveContext, and then from wasm-bindgen-futures. There is a single line in the use_effect that if removed, the panics go away (it is identified with a comment in the code) -- but the warnings remain (even if the entire use_effect is removed, so perhaps these are actually 2 separate things?...). Thankfully, for the moment, I can remove the panic-ing line in my production application to get unblocked on my end, but this still seems like a bug (or two) that needs fixing.

The context:

I have a tree menu component that has expandable items that are all links to other views with the same tree menu. In debug mode via dx serve I get this warning (twice in a row) whenever clicking the links:

WARN /home/chris/git/dioxus/packages/signals/src/warnings.rs:62 Write on signal at /home/chris/git/dioxus/packages/signals/src/read_only_signal.rs:55:24 happened while a component was running. Writing to signals during a render can cause infinite rerenders when you read the same signal in the component. Consider writing to the signal in an effect, future, or event handler if possible.

This is the warning I mentioned in a different PR for a possibly different bug: #3173 (comment) (but maybe related?)

In release mode dx serve --release I get 2 panics back-to-back when clicking the links -- but only under certain circumstances, explained in Reproduction steps below. First panic:

panicked at /home/chris/git/dioxus/packages/core/src/reactive_context.rs:147:62:
called `Result::unwrap()` on an `Err` value: Dropped(ValueDroppedError)

Stack:

__wbg_get_imports/imports.wbg.__wbg_new_abda76e883ba8a5f/<@http://localhost:8080/assets/dioxus/demo2.js:392:21
logError@http://localhost:8080/assets/dioxus/demo2.js:241:18
__wbg_get_imports/imports.wbg.__wbg_new_abda76e883ba8a5f@http://localhost:8080/assets/dioxus/demo2.js:391:66
demo2-8e0046f438d56e3b.wasm.console_error_panic_hook::hook::h4548cbe81c0e9b7e@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[578]:0x67cb7
demo2-8e0046f438d56e3b.wasm.core::ops::function::Fn::call::h909969a68f80df5b@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[2495]:0xa56a3
demo2-8e0046f438d56e3b.wasm.std::panicking::rust_panic_with_hook::h6731baa78621a747@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[956]:0x896b6
demo2-8e0046f438d56e3b.wasm.std::panicking::begin_panic_handler::{{closure}}::hb6cd8464ed39ae71@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[1153]:0x92e4c
demo2-8e0046f438d56e3b.wasm.std::sys_common::backtrace::__rust_end_short_backtrace::hbdf3ddeb21a1e747@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[2490]:0xa5677
demo2-8e0046f438d56e3b.wasm.rust_begin_unwind@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[1622]:0x9f381
demo2-8e0046f438d56e3b.wasm.core::panicking::panic_fmt::h5c7ce52813e94bcd@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[1676]:0xa0073
demo2-8e0046f438d56e3b.wasm.core::result::unwrap_failed::h4ed86702351a3017@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[1257]:0x96c58
demo2-8e0046f438d56e3b.wasm.dioxus_core::reactive_context::ReactiveContext::clear_subscribers::h2ab5ee23433423fc@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[414]:0x4e03d
demo2-8e0046f438d56e3b.wasm.core::ops::function::FnOnce::call_once{{vtable.shim}}::hf552881a2025cbfe@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[1431]:0x9b86d
demo2-8e0046f438d56e3b.wasm.dioxus_core::virtual_dom::VirtualDom::poll_tasks::h9cfa2ed97f0f6c4c@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[247]:0x16b3e
demo2-8e0046f438d56e3b.wasm.dioxus_core::virtual_dom::VirtualDom::process_events::hf08c276613408e47@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[473]:0x5856f
demo2-8e0046f438d56e3b.wasm.<futures_util::future::future::fuse::Fuse<Fut> as core::future::future::Future>::poll::hac0d4ba5a26185d4@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[284]:0x2b9c3
demo2-8e0046f438d56e3b.wasm.dioxus_web::run::{{closure}}::{{closure}}::{{closure}}::h25b19aaccbebccc0@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[1770]:0xa1519
demo2-8e0046f438d56e3b.wasm.<futures_util::future::poll_fn::PollFn<F> as core::future::future::Future>::poll::h8422edb69cf558c1@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[923]:0x877c9
demo2-8e0046f438d56e3b.wasm.dioxus_web::launch::launch_virtual_dom::{{closure}}::hf3737deb975f0031@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[475]:0x58b67
demo2-8e0046f438d56e3b.wasm.wasm_bindgen_futures::queue::QueueState::run_all::h7d9132dd99889989@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[637]:0x6f292
demo2-8e0046f438d56e3b.wasm.wasm_bindgen_futures::queue::Queue::new::{{closure}}::hbd0c17c08f58ef19@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[1888]:0xa27d5
demo2-8e0046f438d56e3b.wasm.<dyn core::ops::function::FnMut<(A,)>+Output = R as wasm_bindgen::closure::WasmClosure>::describe::invoke::he47f03527abc9bfa@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[1887]:0xa27c7
__wbg_adapter_57@http://localhost:8080/assets/dioxus/demo2.js:286:10
real@http://localhost:8080/assets/dioxus/demo2.js:224:20
VoidFunction*__wbg_get_imports/imports.wbg.__wbg_queueMicrotask_c5419c06eab41e73/<@http://localhost:8080/assets/dioxus/demo2.js:584:23
logError@http://localhost:8080/assets/dioxus/demo2.js:241:18
__wbg_get_imports/imports.wbg.__wbg_queueMicrotask_c5419c06eab41e73@http://localhost:8080/assets/dioxus/demo2.js:583:77
demo2-8e0046f438d56e3b.wasm.wasm_bindgen_futures::queue::Queue::schedule_task::h821f83eb5f7e7e63@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[1064]:0x8ed26
demo2-8e0046f438d56e3b.wasm.wasm_bindgen_futures::task::singlethread::Task::into_raw_waker::raw_wake::h86c70dd49434758e@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[1169]:0x9382b
demo2-8e0046f438d56e3b.wasm.futures_core::task::__internal::atomic_waker::AtomicWaker::wake::h8de1cd0b5c729b3c@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[1584]:0x9e974
demo2-8e0046f438d56e3b.wasm.dioxus_core::reactive_context::ReactiveContext::new_for_scope::{{closure}}::ha3ff213d0e9b160f@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[570]:0x66cce
demo2-8e0046f438d56e3b.wasm.dioxus_core::reactive_context::ReactiveContext::mark_dirty::h34e77ea34bb2c7a2@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[961]:0x89b11
demo2-8e0046f438d56e3b.wasm.dioxus_router::contexts::router::RouterContext::change_route::hdfee564ef807ef90@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[299]:0x3157a
demo2-8e0046f438d56e3b.wasm.dioxus_router::contexts::router::RouterContext::push_any::h2eea6d4cc0393079@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[649]:0x708ee
demo2-8e0046f438d56e3b.wasm.dioxus_core::events::Callback<Args,Ret>::new::{{closure}}::hebd3909b5bc9c9ff@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[491]:0x5b410
demo2-8e0046f438d56e3b.wasm.dioxus_core::events::Callback<Args,Ret>::call::h0486a4a496ee56b4@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[746]:0x7a47f
demo2-8e0046f438d56e3b.wasm.dioxus_core::events::Callback<Args,Ret>::leak::{{closure}}::h0281c5afd1516b4e@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[628]:0x6e11d
demo2-8e0046f438d56e3b.wasm.dioxus_core::runtime::Runtime::with_scope_on_stack::hde8e7f89aef6f194@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[926]:0x87a62
demo2-8e0046f438d56e3b.wasm.dioxus_core::events::Callback<Args,Ret>::call::haa490a1f049d579c@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[559]:0x6546f
demo2-8e0046f438d56e3b.wasm.dioxus_core::runtime::Runtime::handle_event::h25942720f1c3db8c@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[237]:0xcb36
demo2-8e0046f438d56e3b.wasm.dioxus_web::dom::WebsysDom::new::{{closure}}::hb9539bc451d374f6@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[341]:0x3de3a
demo2-8e0046f438d56e3b.wasm.<dyn core::ops::function::FnMut<(&A,)>+Output = R as wasm_bindgen::closure::WasmClosure>::describe::invoke::hf06d3e17e0deca53@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[1639]:0x9f7ad
__wbg_adapter_51@http://localhost:8080/assets/dioxus/demo2.js:271:14
real@http://localhost:8080/assets/dioxus/demo2.js:224:20
EventListener.handleEvent*createListener@http://localhost:8080/assets/dioxus/snippets/dioxus-interpreter-js-d20e126dfa95ef37/inline0.js:2:2051
run@http://localhost:8080/assets/dioxus/snippets/dioxus-interpreter-js-d20e126dfa95ef37/inline0.js:152:18
__wbg_get_imports/imports.wbg.__wbg_run_eaeb4cfa2f7014ad/<@http://localhost:8080/assets/dioxus/demo2.js:615:25
logError@http://localhost:8080/assets/dioxus/demo2.js:241:18
__wbg_get_imports/imports.wbg.__wbg_run_eaeb4cfa2f7014ad@http://localhost:8080/assets/dioxus/demo2.js:614:66
demo2-8e0046f438d56e3b.wasm.dioxus_interpreter_js::unified_bindings::Interpreter::flush::h93b4d26c1a57abb2@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[453]:0x55076
demo2-8e0046f438d56e3b.wasm.dioxus_web::mutations::<impl dioxus_web::dom::WebsysDom>::flush_edits::h8c789f1ff95bef97@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[805]:0x7f322
demo2-8e0046f438d56e3b.wasm.dioxus_web::launch::launch_virtual_dom::{{closure}}::hf3737deb975f0031@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[475]:0x58a97
demo2-8e0046f438d56e3b.wasm.wasm_bindgen_futures::queue::QueueState::run_all::h7d9132dd99889989@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[637]:0x6f292
demo2-8e0046f438d56e3b.wasm.wasm_bindgen_futures::queue::Queue::new::{{closure}}::hbd0c17c08f58ef19@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[1888]:0xa27d5
demo2-8e0046f438d56e3b.wasm.<dyn core::ops::function::FnMut<(A,)>+Output = R as wasm_bindgen::closure::WasmClosure>::describe::invoke::he47f03527abc9bfa@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[1887]:0xa27c7
__wbg_adapter_57@http://localhost:8080/assets/dioxus/demo2.js:286:10
real@http://localhost:8080/assets/dioxus/demo2.js:224:20
VoidFunction*__wbg_get_imports/imports.wbg.__wbg_queueMicrotask_c5419c06eab41e73/<@http://localhost:8080/assets/dioxus/demo2.js:584:23
logError@http://localhost:8080/assets/dioxus/demo2.js:241:18
__wbg_get_imports/imports.wbg.__wbg_queueMicrotask_c5419c06eab41e73@http://localhost:8080/assets/dioxus/demo2.js:583:77
demo2-8e0046f438d56e3b.wasm.wasm_bindgen_futures::queue::Queue::schedule_task::h821f83eb5f7e7e63@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[1064]:0x8ed26
demo2-8e0046f438d56e3b.wasm.wasm_bindgen_futures::task::singlethread::Task::spawn::h0b08115bd32594cb@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[1437]:0x9bb10
demo2-8e0046f438d56e3b.wasm.dioxus_web::launch::launch::ha998ef21ff8d1f28@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[419]:0x4ef5e
demo2-8e0046f438d56e3b.wasm.dioxus::launch::launch::hfec61e95285d10a5@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[1524]:0x9d800
demo2-8e0046f438d56e3b.wasm.demo2::main::hb5fe6fce38e439fb@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[1661]:0x9fcc0
demo2-8e0046f438d56e3b.wasm.std::sys_common::backtrace::__rust_begin_short_backtrace::he91b5282dc55fce9@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[2494]:0xa569b
demo2-8e0046f438d56e3b.wasm.std::rt::lang_start::{{closure}}::haf0eb5d5b3d0b538@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[2281]:0xa4c89
demo2-8e0046f438d56e3b.wasm.std::rt::lang_start_internal::hec97bf45d8a61427@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[895]:0x85beb
demo2-8e0046f438d56e3b.wasm.main@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[1746]:0xa1030
demo2-8e0046f438d56e3b.wasm.@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[2279]:0xa4c6d
__wbg_finalize_init@http://localhost:8080/assets/dioxus/demo2.js:1569:10
__wbg_init@http://localhost:8080/assets/dioxus/demo2.js:1621:12
async*@http://localhost:8080/view/3:15:9

Second panic:

panicked at /home/chris/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wasm-bindgen-futures-0.4.45/src/task/singlethread.rs:102:37:
already borrowed: BorrowMutError

Stack:

__wbg_get_imports/imports.wbg.__wbg_new_abda76e883ba8a5f/<@http://localhost:8080/assets/dioxus/demo2.js:392:21
logError@http://localhost:8080/assets/dioxus/demo2.js:241:18
__wbg_get_imports/imports.wbg.__wbg_new_abda76e883ba8a5f@http://localhost:8080/assets/dioxus/demo2.js:391:66
demo2-8e0046f438d56e3b.wasm.console_error_panic_hook::hook::h4548cbe81c0e9b7e@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[578]:0x67cb7
demo2-8e0046f438d56e3b.wasm.core::ops::function::Fn::call::h909969a68f80df5b@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[2495]:0xa56a3
demo2-8e0046f438d56e3b.wasm.std::panicking::rust_panic_with_hook::h6731baa78621a747@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[956]:0x896b6
demo2-8e0046f438d56e3b.wasm.std::panicking::begin_panic_handler::{{closure}}::hb6cd8464ed39ae71@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[1153]:0x92e4c
demo2-8e0046f438d56e3b.wasm.std::sys_common::backtrace::__rust_end_short_backtrace::hbdf3ddeb21a1e747@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[2490]:0xa5677
demo2-8e0046f438d56e3b.wasm.rust_begin_unwind@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[1622]:0x9f381
demo2-8e0046f438d56e3b.wasm.core::panicking::panic_fmt::h5c7ce52813e94bcd@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[1676]:0xa0073
demo2-8e0046f438d56e3b.wasm.core::cell::panic_already_borrowed::h18b8189a0fdd8b58@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[1472]:0x9c727
demo2-8e0046f438d56e3b.wasm.wasm_bindgen_futures::queue::QueueState::run_all::h7d9132dd99889989@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[637]:0x6f39a
demo2-8e0046f438d56e3b.wasm.wasm_bindgen_futures::queue::Queue::new::{{closure}}::hbd0c17c08f58ef19@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[1888]:0xa27d5
demo2-8e0046f438d56e3b.wasm.<dyn core::ops::function::FnMut<(A,)>+Output = R as wasm_bindgen::closure::WasmClosure>::describe::invoke::he47f03527abc9bfa@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[1887]:0xa27c7
__wbg_adapter_57@http://localhost:8080/assets/dioxus/demo2.js:286:10
real@http://localhost:8080/assets/dioxus/demo2.js:224:20
VoidFunction*__wbg_get_imports/imports.wbg.__wbg_queueMicrotask_c5419c06eab41e73/<@http://localhost:8080/assets/dioxus/demo2.js:584:23
logError@http://localhost:8080/assets/dioxus/demo2.js:241:18
__wbg_get_imports/imports.wbg.__wbg_queueMicrotask_c5419c06eab41e73@http://localhost:8080/assets/dioxus/demo2.js:583:77
demo2-8e0046f438d56e3b.wasm.wasm_bindgen_futures::queue::Queue::schedule_task::h821f83eb5f7e7e63@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[1064]:0x8ed26
demo2-8e0046f438d56e3b.wasm.wasm_bindgen_futures::task::singlethread::Task::into_raw_waker::raw_wake_by_ref::h3c72079056b757e3@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[1615]:0x9f1a7
demo2-8e0046f438d56e3b.wasm.dioxus_web::run::{{closure}}::{{closure}}::{{closure}}::h5bf8b81daab6f321@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[1176]:0x93cdd
demo2-8e0046f438d56e3b.wasm.<futures_util::future::poll_fn::PollFn<F> as core::future::future::Future>::poll::h8422edb69cf558c1@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[923]:0x877c9
demo2-8e0046f438d56e3b.wasm.dioxus_web::launch::launch_virtual_dom::{{closure}}::hf3737deb975f0031@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[475]:0x58b67
demo2-8e0046f438d56e3b.wasm.wasm_bindgen_futures::queue::QueueState::run_all::h7d9132dd99889989@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[637]:0x6f292
demo2-8e0046f438d56e3b.wasm.wasm_bindgen_futures::queue::Queue::new::{{closure}}::hbd0c17c08f58ef19@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[1888]:0xa27d5
demo2-8e0046f438d56e3b.wasm.<dyn core::ops::function::FnMut<(A,)>+Output = R as wasm_bindgen::closure::WasmClosure>::describe::invoke::he47f03527abc9bfa@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[1887]:0xa27c7
__wbg_adapter_57@http://localhost:8080/assets/dioxus/demo2.js:286:10
real@http://localhost:8080/assets/dioxus/demo2.js:224:20
VoidFunction*__wbg_get_imports/imports.wbg.__wbg_queueMicrotask_c5419c06eab41e73/<@http://localhost:8080/assets/dioxus/demo2.js:584:23
logError@http://localhost:8080/assets/dioxus/demo2.js:241:18
__wbg_get_imports/imports.wbg.__wbg_queueMicrotask_c5419c06eab41e73@http://localhost:8080/assets/dioxus/demo2.js:583:77
demo2-8e0046f438d56e3b.wasm.wasm_bindgen_futures::queue::Queue::schedule_task::h821f83eb5f7e7e63@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[1064]:0x8ed26
demo2-8e0046f438d56e3b.wasm.wasm_bindgen_futures::task::singlethread::Task::into_raw_waker::raw_wake::h86c70dd49434758e@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[1169]:0x9382b
demo2-8e0046f438d56e3b.wasm.futures_core::task::__internal::atomic_waker::AtomicWaker::wake::h8de1cd0b5c729b3c@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[1584]:0x9e974
demo2-8e0046f438d56e3b.wasm.dioxus_core::reactive_context::ReactiveContext::new_for_scope::{{closure}}::ha3ff213d0e9b160f@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[570]:0x66cce
demo2-8e0046f438d56e3b.wasm.dioxus_core::reactive_context::ReactiveContext::mark_dirty::h34e77ea34bb2c7a2@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[961]:0x89b11
demo2-8e0046f438d56e3b.wasm.dioxus_router::contexts::router::RouterContext::change_route::hdfee564ef807ef90@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[299]:0x3157a
demo2-8e0046f438d56e3b.wasm.dioxus_router::contexts::router::RouterContext::push_any::h2eea6d4cc0393079@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[649]:0x708ee
demo2-8e0046f438d56e3b.wasm.dioxus_core::events::Callback<Args,Ret>::new::{{closure}}::hebd3909b5bc9c9ff@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[491]:0x5b410
demo2-8e0046f438d56e3b.wasm.dioxus_core::events::Callback<Args,Ret>::call::h0486a4a496ee56b4@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[746]:0x7a47f
demo2-8e0046f438d56e3b.wasm.dioxus_core::events::Callback<Args,Ret>::leak::{{closure}}::h0281c5afd1516b4e@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[628]:0x6e11d
demo2-8e0046f438d56e3b.wasm.dioxus_core::runtime::Runtime::with_scope_on_stack::hde8e7f89aef6f194@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[926]:0x87a62
demo2-8e0046f438d56e3b.wasm.dioxus_core::events::Callback<Args,Ret>::call::haa490a1f049d579c@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[559]:0x6546f
demo2-8e0046f438d56e3b.wasm.dioxus_core::runtime::Runtime::handle_event::h25942720f1c3db8c@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[237]:0xcb36
demo2-8e0046f438d56e3b.wasm.dioxus_web::dom::WebsysDom::new::{{closure}}::hb9539bc451d374f6@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[341]:0x3de3a
demo2-8e0046f438d56e3b.wasm.<dyn core::ops::function::FnMut<(&A,)>+Output = R as wasm_bindgen::closure::WasmClosure>::describe::invoke::hf06d3e17e0deca53@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[1639]:0x9f7ad
__wbg_adapter_51@http://localhost:8080/assets/dioxus/demo2.js:271:14
real@http://localhost:8080/assets/dioxus/demo2.js:224:20
EventListener.handleEvent*createListener@http://localhost:8080/assets/dioxus/snippets/dioxus-interpreter-js-d20e126dfa95ef37/inline0.js:2:2051
run@http://localhost:8080/assets/dioxus/snippets/dioxus-interpreter-js-d20e126dfa95ef37/inline0.js:152:18
__wbg_get_imports/imports.wbg.__wbg_run_eaeb4cfa2f7014ad/<@http://localhost:8080/assets/dioxus/demo2.js:615:25
logError@http://localhost:8080/assets/dioxus/demo2.js:241:18
__wbg_get_imports/imports.wbg.__wbg_run_eaeb4cfa2f7014ad@http://localhost:8080/assets/dioxus/demo2.js:614:66
demo2-8e0046f438d56e3b.wasm.dioxus_interpreter_js::unified_bindings::Interpreter::flush::h93b4d26c1a57abb2@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[453]:0x55076
demo2-8e0046f438d56e3b.wasm.dioxus_web::mutations::<impl dioxus_web::dom::WebsysDom>::flush_edits::h8c789f1ff95bef97@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[805]:0x7f322
demo2-8e0046f438d56e3b.wasm.dioxus_web::launch::launch_virtual_dom::{{closure}}::hf3737deb975f0031@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[475]:0x58a97
demo2-8e0046f438d56e3b.wasm.wasm_bindgen_futures::queue::QueueState::run_all::h7d9132dd99889989@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[637]:0x6f292
demo2-8e0046f438d56e3b.wasm.wasm_bindgen_futures::queue::Queue::new::{{closure}}::hbd0c17c08f58ef19@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[1888]:0xa27d5
demo2-8e0046f438d56e3b.wasm.<dyn core::ops::function::FnMut<(A,)>+Output = R as wasm_bindgen::closure::WasmClosure>::describe::invoke::he47f03527abc9bfa@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[1887]:0xa27c7
__wbg_adapter_57@http://localhost:8080/assets/dioxus/demo2.js:286:10
real@http://localhost:8080/assets/dioxus/demo2.js:224:20
VoidFunction*__wbg_get_imports/imports.wbg.__wbg_queueMicrotask_c5419c06eab41e73/<@http://localhost:8080/assets/dioxus/demo2.js:584:23
logError@http://localhost:8080/assets/dioxus/demo2.js:241:18
__wbg_get_imports/imports.wbg.__wbg_queueMicrotask_c5419c06eab41e73@http://localhost:8080/assets/dioxus/demo2.js:583:77
demo2-8e0046f438d56e3b.wasm.wasm_bindgen_futures::queue::Queue::schedule_task::h821f83eb5f7e7e63@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[1064]:0x8ed26
demo2-8e0046f438d56e3b.wasm.wasm_bindgen_futures::task::singlethread::Task::spawn::h0b08115bd32594cb@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[1437]:0x9bb10
demo2-8e0046f438d56e3b.wasm.dioxus_web::launch::launch::ha998ef21ff8d1f28@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[419]:0x4ef5e
demo2-8e0046f438d56e3b.wasm.dioxus::launch::launch::hfec61e95285d10a5@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[1524]:0x9d800
demo2-8e0046f438d56e3b.wasm.demo2::main::hb5fe6fce38e439fb@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[1661]:0x9fcc0
demo2-8e0046f438d56e3b.wasm.std::sys_common::backtrace::__rust_begin_short_backtrace::he91b5282dc55fce9@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[2494]:0xa569b
demo2-8e0046f438d56e3b.wasm.std::rt::lang_start::{{closure}}::haf0eb5d5b3d0b538@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[2281]:0xa4c89
demo2-8e0046f438d56e3b.wasm.std::rt::lang_start_internal::hec97bf45d8a61427@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[895]:0x85beb
demo2-8e0046f438d56e3b.wasm.main@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[1746]:0xa1030
demo2-8e0046f438d56e3b.wasm.@http://localhost:8080/assets/dioxus/demo2_bg.wasm:wasm-function[2279]:0xa4c6d
__wbg_finalize_init@http://localhost:8080/assets/dioxus/demo2.js:1569:10
__wbg_init@http://localhost:8080/assets/dioxus/demo2.js:1621:12
async*@http://localhost:8080/view/3:15:9

Repro app:

#![allow(non_snake_case)]

use dioxus::prelude::*;
use dioxus_logger::tracing::Level;

#[derive(Clone, Routable, Debug, PartialEq)]
enum Route {
    #[route("/")]
    Home {},
    #[route("/view/:id")]
    View { id: u32 },
}

fn main() {
    // Init logger
    dioxus_logger::init(Level::INFO).expect("failed to init logger");
    dioxus::launch(App);
}

fn App() -> Element {
    rsx! {
        Router::<Route> {}
    }
}

#[derive(Debug, PartialEq, Clone)]
pub struct Contents {
    pub id: u32,
    pub children: Vec<Contents>,
}

impl Contents {
    pub fn trail_for<T>(&self, needle_id: u32, grab: fn(&Self) -> T) -> Option<Vec<T>> {
        if self.id == needle_id {
            Some(vec![grab(self)])
        } else {
            for child in &self.children {
                if let Some(mut vec) = child.trail_for(needle_id, grab) {
                    vec.push(grab(self));
                    return Some(vec);
                }
            }
            None
        }
    }

    pub fn trail_ids_for(&self, needle_id: u32) -> Option<Vec<u32>> {
        self.trail_for(needle_id, |contents| contents.id)
    }
}

#[component]
fn Home() -> Element {
    rsx! {
        div {
            "Home"
        }

        Nav {
            id: None,
        }
    }
}

#[component]
fn View(id: ReadOnlySignal<u32>) -> Element {
    rsx! {
        div {
            "{id()}"
        }

        Nav {
            id: Some(id()),
        }
    }
}

#[component]
fn Nav(id: ReadOnlySignal<Option<u32>>) -> Element {
    let contents = Contents {
        id: 0,
        children: Vec::from([
            Contents {
                id: 1,
                children: Vec::from([
                    Contents {
                        id: 12,
                        children: Vec::from([
                            Contents {
                                id: 122,
                                children: Vec::new()
                            },
                            Contents {
                                id: 123,
                                children: Vec::new()
                            }
                        ])
                    },
                    Contents {
                        id: 13,
                        children: Vec::new()
                    }
                ])
            },
            Contents {
                id: 2,
                children: Vec::from([
                    Contents {
                        id: 21,
                        children: Vec::new()
                    },
                    Contents {
                        id: 23,
                        children: Vec::new()
                    }
                ])
            },
            Contents {
                id: 3,
                children: Vec::from([
                    Contents {
                        id: 31,
                        children: Vec::new()
                    },
                    Contents {
                        id: 32,
                        children: Vec::new()
                    }
                ])
            },
        ])
    };

    let trail_ids = if let Some(id) = id() {
        if let Some(mut trail_ids) = contents.trail_ids_for(id) {
            trail_ids.pop(); // remove root for list iteration checks
            trail_ids
        } else {
            Vec::new()
        }
    } else {
        Vec::new()
    };

    rsx! {
        div {
            "Nav:"
        }

        MenuList {
            id,
            contents,
            trail_ids,
        }
    }
}

#[component]
fn MenuList(
    id: ReadOnlySignal<Option<u32>>,
    contents: Contents,
    trail_ids: Vec<u32>,
) -> Element {
    rsx! {
        ul {
            class: "pl-3",

            if let Some(next_trail_id) = trail_ids.pop() {
                {
                    contents.children.into_iter().map(|contents|
                        if next_trail_id == contents.id {
                            rsx! {
                                MenuItem {
                                    id,
                                    contents,
                                    trail_ids: trail_ids.clone(),
                                    is_trail: true,
                                }
                            }
                        } else {
                            rsx! {
                                MenuItem {
                                    id,
                                    contents,
                                    trail_ids: Vec::new(),
                                    is_trail: false,
                                }
                            }
                        }
                    )
                }
            } else {
                for contents in contents.children {
                    MenuItem {
                        id,
                        contents,
                        trail_ids: Vec::new(),
                        is_trail: false,
                    }
                }
            }
        }
    }
}

#[component]
fn MenuItem(
    id: ReadOnlySignal<Option<u32>>,
    contents: Contents,
    trail_ids: Vec<u32>,
    is_trail: ReadOnlySignal<bool>,
) -> Element {
    let mut opened = use_signal(|| is_trail());

    use_effect(move || {
        let _ = id(); // IF YOU REMOVE THIS THE PANIC GOES AWAY
        opened.set(is_trail());
    });

    rsx! {
        li {
            key: "{contents.id}",

            div {
                Link {
                    to: Route::View { id: contents.id },
                    "{contents.id}"
                }

                if contents.children.len() > 0 {
                    if opened() {
                        div {
                            class: "cursor-pointer hover:underline",
                            onclick: move |_| opened.set(false),

                            "-"
                        }
                    } else {
                        div {
                            class: "cursor-pointer hover:underline",
                            onclick: move |_| opened.set(true),

                            "+"
                        }
                    }
                }
            }

            if opened() {
                MenuList {
                    id,
                    contents,
                    trail_ids,
                }
            }
        }
    }
}

Steps To Reproduce

  • Using the app above, run it in release mode with dx serve --release, then open http://localhost:8080 and click on 2, to open its view
  • From 2, click on 3, you will get the panics
  • Reload (still on 3), click on 2, no panic
  • Reload or don't (still on 2), click on 1, no panic
  • Reload or don't (still on 1), click on 3, panic again
  • ... it only panics when clicking on a lower link, not the higher ones, which is weird

Expected behavior

Don't panic

And I'd like the warnings to go away in debug mode as well as those seem very suspicious, whether related to the panics or not.

Environment:

  • Dioxus version: main
  • App platform: web

Questionnaire
I'm interested in fixing this myself but don't know where to start

Thanks

@rogusdev
Copy link
Contributor Author

rogusdev commented Nov 12, 2024

In case it was not clear from reading things over: the line that needs to be commented out is intended to have a meaningful impact, and I do want that functionality to work. Specifically, after hitting the plus button to expand all the children for each item, when a link is clicked, I want all the other items children to be closed. Without that line, they all stay open (except the one moved off of). With that line on, in debug mode, it works correctly to close/hide the other items' children, which is behavior I certainly want in release mode -- without panics or warnings ;)

@ealmloff
Copy link
Member

ealmloff commented Nov 12, 2024

Looking at the logs, I think the panic is caused by the effect trying to rerun after the component has been dropped. We try to prevent that by making sure a scope exists at the slot before running the component, but the reproduction causes the same slot to be reallocated in the same frame. This is a similar issue to #2488 and can be fixed by switching from index ids to generational indexes or just removing any queued effects as we remove the scope

@ealmloff ealmloff added bug Something isn't working core relating to the core implementation of the virtualdom labels Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working core relating to the core implementation of the virtualdom
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants