Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store with AsyncStorage storage not rehydrating #244

Closed
JulianKingman opened this issue Dec 31, 2016 · 6 comments
Closed

Store with AsyncStorage storage not rehydrating #244

JulianKingman opened this issue Dec 31, 2016 · 6 comments

Comments

@JulianKingman
Copy link

I have a store that I'm persisting with AsyncStorage, but it doesn't seem to be rehydrating. The callback fires, but getState comes up empty. If I get the values of AsyncStorage, however, I can see that it is being persisted, just not rehydrated. Thoughts?

Store = createStore(reducers, undefined, autoRehydrate());
persistStore(Store, {storage: AsyncStorage}, () => {
  // rehydrated
  console.log(Store.getState());
});
@rt2zz
Copy link
Owner

rt2zz commented Jan 3, 2017

can you add log: true to autoRehydrate:
Store = createStore(reducers, undefined, autoRehydrate({ log: true }));

autoRehydrate will skip rehydration if you handle the action in your reducer. Double check that you are not modifying state in your default action handler in your reducers. The log on autoRehydrate may give us some hints here.

@JulianKingman
Copy link
Author

JulianKingman commented Jan 3, 2017

Good call on the logs, here's what I get from the log, what should I be looking for?

      redux-persist/autoRehydrate: 1 actions were fired before rehydration completed. This can be a symptom of a race
      condition where the rehydrate action may overwrite the previously affected state. Consider running these actions
      after rehydration:

@JulianKingman
Copy link
Author

Re: modifying state, does something like a lodash _.update function qualify?

@JulianKingman
Copy link
Author

BTW, no actions are listed after the above message from redux-persist.

@JulianKingman
Copy link
Author

I 'fixed' this by adding my own reducer. Still unsure why it didn't work. Should I close this? The issue still exists...

  case 'persist/REHYDRATE':
      // only do this if offline
      if(typeof Meteor.ddp === undefined || Meteor.ddp.status === "disconnected"){
        return action.payload;
      }

@rt2zz
Copy link
Owner

rt2zz commented Feb 8, 2017

@JulianKingman sorry for the delay in getting back to you. The log warning you mentioned here: #244 (comment) was actually a false alarm in the debug logic, that has now been fixed.

Yes _.update would result in state being modified and hence autoRehydrate skipping. In this case I think your solution is reasonable.

I am working on a way to make this immutability implementation detail more apparent to consumers, but for now I think things have to be dealt with on a case by case basis.

@rt2zz rt2zz closed this as completed Feb 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants