Synphonyte / leptos-use

Collection of essential Leptos utilities inspired by React-Use / VueUse / SolidJS-USE
https://leptos-use.rs/
Apache License 2.0
309 stars 66 forks source link

use_color_mode Panicking with cookie enabled #170

Closed R2rho closed 1 week ago

R2rho commented 1 week ago

I'm getting a server side panic when using cookie_enabled(true) on use_color_mode. The panic occurs in

leptos_reactive-0.6.14\src\signal.rs:462:21

Tracing the panic took me to this line using get_untracked():

    if cookie_enabled {
        let _ = sync_signal_with_options(
            (cookie, set_cookie),
            (store, set_store),
            SyncSignalOptions::with_transforms(
                move |cookie: &Option<ColorMode>| {
                    cookie.clone().unwrap_or_else(|| store.get_untracked()) // <-- panicking with message: "already mutably borrowed: BorrowError"
                },
                move |store: &ColorMode| Some(store.clone()),
            ),
        );
    }

I tried changing it locally to :

cookie.clone().unwrap_or_else(|| store.try_get_untracked().unwrap_or_default())

But still got the panic at leptos_reactive-0.6.14\src\signal.rs:490:21. I unfortunately don't know enough about the internals of leptos_reactive to understand why this is panicking or why the mutable borrow is failing.

Steps to reproduce: Run the ssr example, it fails on startup with cargo leptos watch

https://github.com/synphonyte/leptos-use/tree/main/examples/ssr
maccesch commented 1 week ago

what version of leptos-use are you using?

maccesch commented 1 week ago

never mind, I can reproduce it.