ignite icon indicating copy to clipboard operation
ignite copied to clipboard

Redux State Mutates unexpectedly

Open chrbradley opened this issue 10 years ago • 10 comments

  • [x] Issue does not already exist /* As far as I can tell */
  • Identify exactly what aspect your issue is about
    • [x] ignite base application

ignite doctor:

Computer
  Platform: darwin

Ignite
  Version: 1.5.0
  Path: /usr/local/bin/ignite

Node
  Version: v5.4.0
  Path: /Users/christopherbradley/.nvm/versions/node/v5.4.0/bin/node

NPM
  Version: 3.10.6
  Path: /usr/local/bin/npm

Yeoman
  Version: 1.8.4

React Native CLI
  Version: 1.0.0

App
  React Native Version: 0.31.0

Something seems to be destroying redux state. I've created a test example demonstrating the issue here: https://github.com/chrbradley/ingiteTestState/tree/add-new-state

In my example I modify the state in the StartUp saga and then MapStateToProps in the TestState component.

You can see that the state is present when the component initially renders, but something modifies the state which triggers a rerender of TestState component.

When the TestState component rerenders, the state is no longer there. Did I miss something when I created the new state object?

chrbradley avatar Aug 31 '16 17:08 chrbradley

Can you turn off the redux persist option and try again? I wonder if that is causing grief. We had some issues with that recently.

skellock avatar Sep 03 '16 22:09 skellock

@chrbradley I would suggest you add your slices of state that you're still developing to the "Blacklist" (line 14 of your index.js (RootReducer) file) This will allow you to modify the state, and store updated values only per your Actions, and not from some previously built slice of state that ReduxPersist is remembering when it compiles as middleware in the createStore( ) function. The blacklist is seen by ReduxPersist and does not "persist" previous instances of state that it finds inside of that array.

TobiahRex avatar Sep 05 '16 23:09 TobiahRex

@skellock You're correct, turning off redux persist fixed the issue. Based on this, I'd speculate that the rehydration is happening too late (after the startup saga fires).

Also when I've used redux persist in the past, I typically see a log event after it dispatches. The logger isn't picking up the rehydration.

Digging into this now.

chrbradley avatar Sep 09 '16 15:09 chrbradley

There's a few issues outstanding with redux persist. Someone suggested moving up to v3 might be the solution? I'll look as well today. Thx dude!

skellock avatar Sep 09 '16 15:09 skellock

image

This is that timing issue. STARTUP is firing before REHYDRATE. 💩

skellock avatar Sep 09 '16 15:09 skellock

What about a simple check.

If rehydrate is on, then call startup on rehydrate

if it's off, call startup right away.

GantMan avatar Sep 09 '16 20:09 GantMan

Firiing the startup action like GantMan said is the solution at the moment and it works for me..

lukabers avatar Sep 17 '16 12:09 lukabers

@lukabers - would love a PR with that change! Mind sharing?

GantMan avatar Sep 17 '16 15:09 GantMan

I'll share on monday! Let me test a bit

lukabers avatar Sep 17 '16 15:09 lukabers

fixed by @lukabers in #379 - will be in next version's release.

GantMan avatar Sep 19 '16 20:09 GantMan