Redux Toolkit preloadedState limits during state shape evolution
0 reputation · 24 Oct 2022, 18:33 UTC
State Hydration and Schema Mismatches
When using configureStore in Redux Toolkit, the preloadedState property allows for the injection of recovered data from a serialized snapshot during store initialization. This mechanism is essential for restoring application state from persistent storage.
A challenge arises when the application's reducer logic or state shape evolves between the time the state was persisted and the time it is restored. Because preloadedState is merged into the store, there is a risk of hydrating the store with stale data structures that no longer align with the current reducer definitions.
Given that Redux does not natively provide a versioning or migration layer for preloaded state, the responsibility for data verification falls on the implementation logic.
- How can state versioning be integrated into the hydration process to prevent incompatible snapshots from being loaded?
- What are the recommended patterns for validating the integrity of
preloadedStatebefore it is passed to the store?