xstate icon indicating copy to clipboard operation
xstate copied to clipboard

Bug: Meta Data Not Rehydrated when using persist and rehydrate state

Open bogminic opened this issue 2 years ago • 3 comments

Description

I encountered an issue while attempting to save and rehydrate the state using Persisted and Rehydrated State example. It appears that the meta data associated with the state is not rehydrated correctly after the page reloads or when the app is revisited, causing unexpected behavior in the application.

Expected result

When saving to local storage and then rehydrating the state, the meta data should be fully rehydrated along with the rest of the state. This means that the loaded meta data should accurately reflect the state's meta data at the time of saving, and the application should behave as expected without any loss of meta data after rehydration.

Actual result

Upon saving and rehydrating the state using the described process, I noticed that the meta data associated with the state is not correctly rehydrated. Instead, remains an empty object {}, leading to unexpected behavior in my application that relies on accurate meta data.

Reproduction

https://codesandbox.io/s/xstate-meta-bug-zdq29t

Additional context

I hope this information helps in identifying and resolving the issue. Please let me know if you require any additional information or clarification. Thank you for your attention to this matter!

bogminic avatar Jul 28 '23 14:07 bogminic

This is fixed in XState v5 beta: https://codesandbox.io/s/xstate-meta-bug-forked-f2s2l3?file=/src/index.js

If you want, you can try your hand at fixing it in v4. It likely has to do with how the State is JSON-stringified (we're probably forgetting the meta value).

davidkpiano avatar Jul 30 '23 13:07 davidkpiano

Great, thank you for providing the solution! I will bump up the packages to the beta version of XState v5 and test it out. If that resolves the issue, it's excellent news.

As for fixing the issue in XState v4, I will take a look at it as well, but please keep in mind that my time is limited because I take care of :baby: :baby:. So, I will investigate it further only if I have the opportunity and availability.

Once again, thank you for your help and guidance on this matter! I'll keep you updated on my progress if I can find the time to investigate further.

bogminic avatar Jul 31 '23 15:07 bogminic

@bogminic I went ahead and quickly fixed this: #4169

davidkpiano avatar Jul 31 '23 15:07 davidkpiano