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

xilem_web: Panic using BoxedView inside HTML element #274

Open
matthunz opened this issue May 5, 2024 · 1 comment · May be fixed by #403
Open

xilem_web: Panic using BoxedView inside HTML element #274

matthunz opened this issue May 5, 2024 · 1 comment · May be fixed by #403

Comments

@matthunz
Copy link
Contributor

matthunz commented May 5, 2024

When trying to use a BoxedView in an html::div I get the following panic:

panicked at C:\Users\matth\.cargo\git\checkouts\xilem-031d790027f85a11\1e37164\crates\xilem_web\src\context.rs:304:14:
Element type has changed, this should never happen!

Reproducible by changing the counter example:

fn btn(
    label: &'static str,
    click_fn: impl Fn(&mut AppState, web_sys::MouseEvent) + 'static,
) ->  BoxedView<AppState> {
    Box::new(el::button(label).on_click(click_fn))
}

fn app_logic(state: &mut AppState) -> impl View<AppState> {
    el::div((
        btn("+1 click", |state, _| state.increment()),
        state.text.clone(),
    ))
}
Stack trace
Stack:

Error
    at imports.wbg.__wbg_new_abda76e883ba8a5f (http://localhost:8080/lookbook-xilem-example-57aa3af25ad35cc9.js:338:21)
    at lookbook_xilem_example-f6a974525f70f53f.wasm.console_error_panic_hook::Error::new::h516a79c7e649e619 (http://localhost:8080/lookbook-xilem-example-57aa3af25ad35cc9_bg.wasm:wasm-function[2255]:0xa99ca)
    at lookbook_xilem_example-f6a974525f70f53f.wasm.console_error_panic_hook::hook_impl::h5e4d6d7771b2c70d (http://localhost:8080/lookbook-xilem-example-57aa3af25ad35cc9_bg.wasm:wasm-function[432]:0x55f76)
    at lookbook_xilem_example-f6a974525f70f53f.wasm.console_error_panic_hook::hook::h99fffc916c6dad72 (http://localhost:8080/lookbook-xilem-example-57aa3af25ad35cc9_bg.wasm:wasm-function[3139]:0xb8210)
    at lookbook_xilem_example-f6a974525f70f53f.wasm.core::ops::function::Fn::call::h97eb8c787f0b3f7f (http://localhost:8080/lookbook-xilem-example-57aa3af25ad35cc9_bg.wasm:wasm-function[2707]:0xb2178)
    at lookbook_xilem_example-f6a974525f70f53f.wasm.std::panicking::rust_panic_with_hook::h0833ff9dc94df5f1 (http://localhost:8080/lookbook-xilem-example-57aa3af25ad35cc9_bg.wasm:wasm-function[1002]:0x7eb17)
    at lookbook_xilem_example-f6a974525f70f53f.wasm.std::panicking::begin_panic_handler::{{closure}}::hc3329d7ae0363c6f (http://localhost:8080/lookbook-xilem-example-57aa3af25ad35cc9_bg.wasm:wasm-function[1373]:0x90226)
    at lookbook_xilem_example-f6a974525f70f53f.wasm.std::sys_common::backtrace::__rust_end_short_backtrace::h4268105044501476 (http://localhost:8080/lookbook-xilem-example-57aa3af25ad35cc9_bg.wasm:wasm-function[3596]:0xbc275)
    at lookbook_xilem_example-f6a974525f70f53f.wasm.rust_begin_unwind (http://localhost:8080/lookbook-xilem-example-57aa3af25ad35cc9_bg.wasm:wasm-function[2830]:0xb4058)
    at lookbook_xilem_example-f6a974525f70f53f.wasm.core::panicking::panic_fmt::h765acaeb0182f5af (http://localhost:8080/lookbook-xilem-example-57aa3af25ad35cc9_bg.wasm:wasm-function[2970]:0xb5f83)


imports.wbg.__wbg_error_f851667af71bcfc6 @ lookbook-xilem-example-57aa3af25ad35cc9.js:332

This looks to be related to Pod::downcast_mut, where the underlying element type is incorrect.
I'm also not using any conditionals or a ViewSequence so this is definitely confusing to me, maybe AnyView is storing the wrong type?

@Philipp-M
Copy link
Contributor

Philipp-M commented May 8, 2024

Hmm this is a tricky one, I think it's this issue: https://stackoverflow.com/questions/73807369/cant-downcast-from-mut-boxdyn-trait-as-mut-dyn-any

I.e. in the ViewSequence impl for impl View is coercing the inner element of the Pod which is already of type Box<dyn AnyNode> as &mut dyn Any (via .as_any_mut()) and then back to Box<dyn AnyNode>

@Philipp-M Philipp-M linked a pull request Jun 18, 2024 that will close this issue
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

Successfully merging a pull request may close this issue.

2 participants