Hi all!!!
I'm having some issue in my application (both android and iOS Simulator) where the store is never persisted after app restart (I need to persist some facebook login/token data).
I tried to generate a new app and ended up with the same.
I could reproduce the problem in StartupSaga.js where state.weather.temperature is always null. I'm not sure that I'm doing something wrong, maybe some permission?
Platform: darwin
Ignite
Version: 1.5.0
Path: /Users/fernandomorais/.nvm/versions/node/v6.3.1/bin/ignite
Node
Version: v6.3.1
Path: /Users/fernandomorais/.nvm/versions/node/v6.3.1/bin/node
NPM
Version: 3.10.3
Path: /Users/fernandomorais/.nvm/versions/node/v6.3.1/bin/npm
Yeoman
Version: 1.8.4
React Native CLI
Version: 1.0.0
App
React Native Version: 0.31.0
@FernandoMorais - I just created a new project and the rehydration is working just fine for me!
One thing, though! The API seems to be failing now :( Looks like openweathermap.org has changed their API. That might be the issue, now that API should be returning a 502. Can you verify using reactotron?
I am also having issues with redux-persist.
Ignite: 1.5.0
RN: React Native 0.31.0
Os: Windows 10
Device: Genymotion Android simulator (galaxy S6)
I generated the other day from scratch with a relatively unchanged App source tree. I started adding some auth0 login logic and started passing my oauth token into my loginSuccess creator and expecting it to be redux-persist stored automatically for me. (I removed login and have a clean redux-persist blacklist).
I added some console.log logging to ImmutablePersistenceTransform for anything "in" or "out" and never saw any logging activity.
I added logging to RehydrationService.updateReducers and it is calling persistStore(...) but when I have added a callback to that (e.g., persistStore(store, config, () => { console.log('done') }), I _never_ see a "done" message that rehydration is complete. And additionally, no logging within the following code regaring AsyncStorage testing of reducerVersion is ever display (like the code is never called/run)
So,... I ended up following some of the "delay rendering until hydration is complete" from the redux-persist docs. In that setup, in my index.android.js, I call persistStore like above and the "done" message is display ... rehydration completes. In this configuration, rehydration and subsequent "in" and "out" serialization console.log statements get displayed ... meaning that automatic store persistence works.
for extra information here is my post to the chatroom....
bradrust @bradrust
I have looked at room history and perhaps my question is like someone before with a new ignite "default generated code" question where is appears redux-persist is not storing any store/state automatically. I have removed 'login' from blacklist. In RehydrationServices, I have some console.log logging where I see the call to persistStore.
In that call to persistStore, it is always passing an empty store {} which I assume should have been filled by autoRehydrate.
I have logging in the AsyncStorage around setting the reducerVersion. But I never see that output. Anyway,... just not sure how my store is supposed to get automatically persisted when it changes.
bradrust @bradrust 12:53
Adding some info... if I delay dispatch of "Actions.startup()" until after I call persistStore from index.android.js (which is how redux-persist docs suggest to delay rendering until hydration is complete), then it does appear to hydrate and it does automagically store new store/state data.
Hi @GantMan! I've got the API erro too, so I changed the code to return a fixed value....
I'm facing the same problem that @bradrust described, looks like the startup action is cleaning things up before rehydration process finish.
I tried to use redux-action-buffer, but didn't work. :(
Hi guys!!! After some tests and @bradrust clarification I've figure out how to solve this issue!!!
Changing the way we call the startup action things got working!
original:
Root.js - line 19
*this is causing startup being called before rehydration
change to:
RehydrationServices.js - line 12
// Begin a fresh store
persistStore(store, config, ()=> {
console.log('rehydration completed!!!!', store.getState())
const { dispatch } = store
dispatch(Actions.startup())
})
I'll run more tests...
I moved my dispatch(Actions.startup()) over to RehydrationServices as you have above (and removed the dispatch from Root.js.
However, the callback isn't ever called. I never see a "rehydration completed" message or a dispatched startup action. I could be doing something wrong.
Hi guys!
@bradrust it seams to be an Android problem here! On iOS simulator everything works fine... When I go to Android AsyncStorage do not fire setItem, getItem or getAllKeys callbacks!
@GantMan could you help us?
Is there some aditional setup for android that we've missed?
Good news!!!
@bradrust, try increasing the reducerVersion... Here I've changed to a new value and everything started to work on Android too...
Hey guys, sorry for the delay, been a busy week for me :)
That's awesome to hear @FernandoMorais ! We're about to fix/touchup how our Redux Sagas work. We've come up with a really amazing and fancy method to make Sagas feel more succinct, while keeping Redux clean. The issue was discussed quite a bit in ticket #158
When @skellock does this update - and I hope to help - we'll address this issue.
As for bumping the reducerVersion, that means your stored data was overwriting your initial data, and you needed to enforce a clean (without resetting the simulator). If anyone is confused on this, please see @fvonhoven 's excellent blog article: https://shift.infinite.red/shipping-persistant-reducers-7341691232b1#.u0zq46rx9
I'm glad everything is working! I'll remember to ping you two in the PR that is coming so you can see our restructure of the Reducer/Saga setup.
@bradrust - if bumping your reducer version works, let me know and I'll close this ticket 馃憤
Here is what I can report and it's to the best of my javascript and react-native abilities (which aren't that great).
From a very naive react-native view, it appears that something isn't initialized or primed outside of the React.Component RNBase. If the redux-persist ecosystem is called from "const store = configureStore()" then it just does seem to start/init.... for me on Android simulator(s).
Thanks for the feedback @GantMan!
Something I did and you should look is that after v3 of redux-pesist they quit using buffers, which makes actions execute before rehydration... I've added the redux-action-buffer and things got the right execution flow.
@bradrust Do you have the same problem on iOS?
I am also having issues with redux-persist.
Ignite: 1.5.0
RN: React Native 0.31.0
Os: Windows 10
What is the end solution. State is never persisted. How to fix this?
Hello, good to know this isn't just something happening to me. I am running into the same issues. I have tried changing the reducer version to see if it would log out the purging of the store, and it did not. The state also does not persist like issues above.
Tested both on Android Nexus 6P emulator and Galaxy S6 physical device.
It appears this might be a bug in the redux-persist version that we are using. We may need to make a an upgrade to the existing npm module and code.
If anyone figures that out before internal, please PR it.
same here, a combination of @FernandoMorais and @bradrust seems to fix it for now, at least until i fully test. I also had to add a startup state value, so that i dont render my root app until rehydration is complete
Everything is working here... After some changes I ended up with:
"ramda": "~0.21.0",
"react": "~15.2.1",
"react-native": "~0.30.0",
"react-native-router-flux": "~3.35.0",
"react-redux": "~4.4.5",
"redux": "~3.5.2",
"redux-action-buffer": "~1.0.1",
"redux-logger": "~2.6.1",
"redux-persist": "~3.2.2",
"redux-saga": "~0.10.5",
"reduxsauce": "~0.1.0",
"seamless-immutable": "~6.1.1"
The breaking changing was to introduce redux-action-buffer....
Using it I could keep the startup action at componentWillMount() and nothing changed on Store.
@GantMan, would you like me to do a PR with this solution?
I'm using it with success on both android and ios.
@skellock thoughts?
@FernandoMorais
Can you explain better this solution??
Should I only change dependencies?
Thanks
Same happens to me. Startup is called before rehydration
Waiting for response from the masters =)
@fvonhoven : You have more experience in this area than I do. Do you recommend we upgrade?
I am having the same issue.. Startup running before rehydration, which is causing issues.
I'll test to see if this was fixed in #339 or not.
Hi,
It鈥檚 not very clear on what the solution was from this thread. Can somebody please post the solution to the problem here?
It looks to me like the create can only happen once. We used to purge in a separate part of logic, but then after this commit https://github.com/infinitered/ignite/pull/339/files
We only call once, and it depends if it should purge or not.
Most helpful comment
Same happens to me. Startup is called before rehydration
Waiting for response from the masters =)