Reflex hot-reloading: async state loss during preserve_state
0 reputation · 20 Apr 2021, 19:43 UTC
State Persistence in Hot-Reloading
Reflex allows developers to maintain component state across code changes using the preserve_state flag. While this ensures synchronous state values remain intact when the binary recompiles and the UI re-instantiates, the behavior of asynchronous operations during this transition is less clear.
When a reload is triggered while async tasks are pending or queued, there is uncertainty regarding whether these updates are discarded or if they can be reconciled with the new state graph. This is particularly relevant for components relying on external network requests or long-running background tasks that overlap with the recompilation window.
- How does Reflex handle pending async state updates when
preserve_stateis enabled? - Is there a mechanism to prevent race conditions between a pending async task and the re-instantiation of a component?