framesurge / perseus

A state-driven web development framework for Rust with full support for server-side rendering and static generation.
https://framesurge.sh/perseus/en-US
MIT License
2.15k stars 89 forks source link

Using the builder pattern `input().bind_value(...)` perseus panics #279

Closed dessalines closed 1 year ago

dessalines commented 1 year ago

This issue is reporting a bug in the code of Perseus. Details of the scope will be available in issue labels. The author described their issue as follows:

When using the builder:

.c(input().bind_value(some_reactive_value)) , perseus fails compilation. It works correctly only when using the non-builder !view macro

thread 'main' panicked at 'function not implemented on non-wasm32 targets', /home/xxx/.cargo/registry/src/github.com-1ecc6299db9ec823/wasm-bindgen-0.2.84/src/lib.rs:1007:1

Log file: https://file.io/FIgR9nNZfETQ

The steps to reproduce this issue are as follows:

Try to use the builder pattern .c(input().bind_value(...))

A minimum reproducible example is available at https://file.io/FIgR9nNZfETQ.

Tribble internal data dHJpYmJsZS1yZXBvcnRlZCxDLWJ1ZyxBLWNsaQ==
arctic-hen7 commented 1 year ago

I'm not sure of how that function is implemented within Sycamore, but it looks like it expects web_sys functions to be present. I would recommend using a #[cfg(client)] gate above the .bind_value() call. It won't be particularly ergonomic, but I'm afraid that's the best we can do in Perseus.

@lukechu10 should this function do nothing on the server-side, like bind:value does in the macro?

dessalines commented 1 year ago

For now my workaround is to do:

.c(view! {cx, input(bind:value = name)})

But yes I'm not sure why the builder version has requirements that the view! macro doesn't.

lukechu10 commented 1 year ago

@lukechu10 should this function do nothing on the server-side, like bind:value does in the macro?

Ah yes that would be much better. I'll have to take a look at this.

dessalines commented 1 year ago

Thanks! I'll create an issue referencing this over at sycamore.

arctic-hen7 commented 1 year ago

Since this is now a Sycamore issue, I'll close this here for now.