unstated-persist icon indicating copy to clipboard operation
unstated-persist copied to clipboard

_persist_version is never set when instantiating the Container (React Native)

Open joaovpmamede opened this issue 7 years ago • 8 comments

When instantiating a PersistContainer there's nothing in storage (AsyncStorage in React Native) for that key, therefore serialState is null which makes the code to run without setting the state with _persist_version (this.state would be whatever is set on the container or empty).

After and during the rehydration phase the check for incomingState._persist_version !== config.version returns true and the saved state on AsyncStorage is never set on the container again (this happens because it never saved that property in the first place).

I think the issue is here. Shouldn't _persist_version be set by default on state?

joaovpmamede avatar Aug 23 '18 11:08 joaovpmamede

@rt2zz could you take a look at this issue? I'm not sure but I think because of this isBootstrapped does not work either.

Also is it possible to publish a new package?

joaovpmamede avatar Oct 10 '18 11:10 joaovpmamede

Will #5 resolve this issue?

JPeer264 avatar Oct 16 '18 08:10 JPeer264

Not sure it will I guess that is another issue (that I also have).

Anyway this was fixed on the last PR, which by mistake fixed (hopefully) two things at the same time - the typo on isBootstrapped and this issue.

joaovpmamede avatar Oct 17 '18 07:10 joaovpmamede

Do you mean this fixed your issue?

JPeer264 avatar Oct 17 '18 08:10 JPeer264

Yup, that else there fixed it.

But now I'm having the exact same on as you do. So your PR would be very much welcome.

Btw and this is not related to this issue but how do you install/run your fork on an app? The lib is under packages and I can't seem to find a solution to use my local version (with yarn link) or a fork from github.

joaovpmamede avatar Oct 17 '18 08:10 joaovpmamede

npm link works just fine for me atm. I just run npm link in the ./packages/unstated-persist folder and npm link unstated-persist in my project.

I haven't tried to install it directly from GitHub yet, as currently I am the only one who is working on it (might be just achievable with more steps, as it is in the subfolder).

JPeer264 avatar Oct 17 '18 08:10 JPeer264

Not sure why it doesn't work for me, I get:

error: bundling failed: Error: Unable to resolve module `react` from `/Users/joaomamede/Desktop/unstated-persist/packages/unstated-persist/node_modules/unstated/lib/unstated.js`: Module `react` does not exist in the Haste module map

Tried linking react inside unstated-persist but didn't work either.

joaovpmamede avatar Oct 17 '18 14:10 joaovpmamede

Ok that is weird. I don't have a solution for that unfortunately.

JPeer264 avatar Oct 20 '18 05:10 JPeer264