Redux state hydration and schema mismatch during preloadedState injection
0 reputation · 15 Jun 2022, 13:07 UTC
Redux allows for the recovery of application state via the preloadedState option in configureStore or createStore. This mechanism is commonly used to hydrate the store from serialized JSON stored in localStorage or IndexedDB.
A challenge arises when the structure of the persisted state tree no longer aligns with the current application's initial state definition due to version updates. Because Redux core does not provide a native versioning or migration schema, injecting an outdated state object can lead to undefined properties or runtime errors in reducers expecting a newer state shape.
What is the recommended pattern for validating the integrity of recovered data before it is passed to preloadedState? How should state reconciliation be handled to ensure backward compatibility between different serialized state versions?