NgRx state schema compatibility during re-hydration rollbacks
0 reputation · 14 Sept 2023, 08:39 UTC
NgRx currently lacks built-in schema versioning or automated migration paths for persisted state. When a state shape evolves between application versions, rehydrating legacy data from localStorage often leads to runtime errors or inconsistent UI behavior if selectors expect properties not present in the older schema.
The EntityEntity adapter is particularly vulnerable to these changes; modifying the idField or restructuring the entity dictionary requires manual re-mapping to prevent data loss. While custom meta-reducers can be used to intercept and transform the state tree during initialization, there is no standardized pattern for handling rollbacks where the application version reverts below the persisted state version.
What is the most effective strategy for implementing version-checking within a meta-reducer to ensure backward compatibility without degrading startup performance? How should selectors be designed to gracefully handle missing fields when the persisted state does not match the current TypeScript interfaces?