leptos-rs / leptos

Build fast web applications with Rust.
https://leptos.dev
MIT License
15.31k stars 599 forks source link

fix: StoredValue and Resource panic during cleanup #2583

Closed luxalpa closed 1 month ago

luxalpa commented 2 months ago

If the value inside a StoredValue implements the drop trait, and that drop causes another read, update or dispose on another StoredValue, we'd get a cryptic panic with already mutably borrowed: BorrowError. I encountered this issue with a StoredValue<Disposer> with the disposer type returned by as_child_of_current_owner(). Because the Disposer cleans up a reactive sub-scope on Drop, it will try to mutably borrow Runtime::stored_values while it is still mutably borrowed by the function that drops it.

gbj commented 1 month ago

Oh, wow. This is one of those very awkward examples where the scoping of when the BorrowMut handle gets dropped makes a real difference. Nice catch.