hydrostack / hydro

Hydro brings stateful and reactive components to ASP.NET Core without writing JavaScript
https://usehydro.dev
MIT License
692 stars 16 forks source link

Persist components' state across hot page reloads #1

Open kjeske opened 11 months ago

kjeske commented 11 months ago

When using built-in ASP.NET Core mechanism for hot reloading pages after changing source code, the whole page is being reloaded, therefore all the components loose their state. It's inconvenient when working on some places deep down the component hierarchy that resets every time.

Possible solution would be to add a custom hot-reload mechanism that will send messages via web sockets stream. As a response, browser could send a request to the back-end for the new version of current page, but additionally all the state would be sent together with that request.

To do:

taublast commented 1 month ago

Could add a property bool IsPersistent to the HydroComponent class, so that every persistent component will save its props marked with [Parameter] attribute to cookies after every rendering, then upon a new Mount (it is triggered upon HotReload right?) will restore values from cookies.

Could be totally done from code-behind without changing hydro.js. Doesn't keep all the state though.. Well, just an idea. Can be interesting for not only HotReload, like navigating through pages and automatically having all previous parameters restored from last usage.