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

app.version is not stored at first use #9

Closed
alexstrat opened this issue Nov 3, 2016 · 4 comments
Closed

app.version is not stored at first use #9

alexstrat opened this issue Nov 3, 2016 · 4 comments

Comments

@alexstrat
Copy link

I tried adding redux-persist-migrate to my stack.
Since it was the first time I used the lib, the app key was never in the initial state. As a consequence, upon persist/REHYDRATE reducement in redux-persist's defaultStateReconciler, the app key of the inboundState (containing the version) is simply ditched out because of this line:

// if initialState does not have key, skip auto rehydration
if (!state.hasOwnProperty(key)) return

It is easy to workaround this, for instance by adding a dummy app reducer, but it was not obvious to find. Since, I guess, it is a problem encountered by any new comer, shouldn't the workaround be part of the doc?

@giordy
Copy link

giordy commented Jan 12, 2017

Yes, just wasted 2 hours in fact because of this. I confirm this problem.
In my opinion this is a major show stopper.
I confirm that I added a dummy reducer to work it around.

@StevePotter
Copy link

StevePotter commented Mar 30, 2017

@giordy any chance you can post your placeholder reducer for others to use? Mine (used Flow types):

type SchemaState = {
  version?: number
}
const initialState: SchemaState = {}
const schemaVersion = (state: SchemaState = initialState) => state
export default schemaVersion

and in root reducer:

const rootReducer = combineReducers({
  schema
})

Of course, my 'app version' is 'schema'.

A good fix would be a custom state reconciler, or simply to require this extra reducer in the readme.

@giordy
Copy link

giordy commented Apr 24, 2017

@StevePotter this is essentially what I did.

const REDUCERS = {
    reducer1,
    reducer2,
    ... // other reducers
};

// apply the fake reducer that maps migrations
REDUCERS[REDUCER_KEY] = (state={}) => state;

export default combineReducers(REDUCERS);

where REDUCER_KEY is the identifier used to map the state version ('app' in the example given in the README)

IanVS added a commit to IanVS/redux-persist-migrate that referenced this issue May 3, 2017
@pavoni
Copy link

pavoni commented May 8, 2017

Just followed the same path myself.

Would be great if someone could merge the fix from @IanVS.

@rt2zz rt2zz closed this as completed in 033d818 Aug 30, 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

4 participants