rt2zz / unstated-persist

19 stars 4 forks source link

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

Open joaovpmamede opened 6 years ago

joaovpmamede commented 6 years ago

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 commented 6 years ago

@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?

JPeer264 commented 6 years ago

Will #5 resolve this issue?

joaovpmamede commented 6 years ago

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.

JPeer264 commented 6 years ago

Do you mean this fixed your issue?

joaovpmamede commented 6 years ago

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.

JPeer264 commented 6 years ago

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).

joaovpmamede commented 6 years ago

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.

JPeer264 commented 6 years ago

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