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

Incomplete states on rehydration and lost pieces of state #110

Closed
moniuch opened this issue Jan 11, 2019 · 3 comments
Closed

Incomplete states on rehydration and lost pieces of state #110

moniuch opened this issue Jan 11, 2019 · 3 comments

Comments

@moniuch
Copy link

moniuch commented Jan 11, 2019

On 6.0.0 now and I still have the problems with the shape of the state after rehydration.

My state looks like so:

{
  app: {
    language: string;
    deliveryParams: {
      deliveryType: number;
      deliveryZip: string;
    },
    viewParams: any;
    locationInfo: any;
  };
  orders: {  // lazy loaded
    orderTokens: string[];
    currentId: string;
    lastViewedId: string[];
  };
  feature2: {...};  // lazy loaded
  feature3: {...};  //lazy loaded
}

What I want to keep in local storage is:

  • from the app slice: language, deliveryParams (prefereably just deliveryZip, but let's simplify)
  • from the orders slice: orderTokens and lastViewedId

So I have the keys specified as follows:

keys: [
  { 'app': ['language', 'deliveryParams'] },
  { 'orders': ['orderTokens', 'lastViewedId'] },
],

which is saved to local storage just fine, I can see two records in Dev Tools/Application/LocalStorage, but when I manually delete app from there and refresh the page, the orders part also gets lost.

Even more sadly, in the Redux DevTools I cannot see a single action where the state would be complete - and include for example app.viewParams. This is why I believe my comment is still valid - we should:

  1. First let an undefined state to go through reducer - which does not happen.
  2. Apply local storage data on top of that

(The code in that comment of course is simplified and does mutation, so please consider it pseudo-code)

The problems described above are with the solution applied

So I consider #65 still open.

@moniuch moniuch changed the title Incomplete states, and lost state pieces Incomplete states and lost state pieces Jan 11, 2019
@moniuch moniuch changed the title Incomplete states and lost state pieces Incomplete states and lost piecez of state Jan 11, 2019
@moniuch moniuch changed the title Incomplete states and lost piecez of state Incomplete states and lost piecs of state Jan 11, 2019
@moniuch moniuch changed the title Incomplete states and lost piecs of state Incomplete states and lost pieces of state Jan 11, 2019
@moniuch moniuch changed the title Incomplete states and lost pieces of state Incomplete states on rehydration and lost pieces of state Jan 11, 2019
@dstj
Copy link

dstj commented Jan 11, 2019

I have the same problem with 6.0.0 too. When refreshing the browser (i.e. F5), the state in the localStorage is back to the initial value. It works with 5.1.1. My config is pretty simple:

export function localStorageSyncReducer(reducer: ActionReducer<State>): ActionReducer<State> {
	return localStorageSync({ keys: [{ auth: ['status'] } ], rehydrate: true })(reducer);
}

@dstj
Copy link

dstj commented Jan 23, 2019

Seems fixed with the merge of #114 (and release of 7.0.0)

@BBlackwo
Copy link
Collaborator

Going to close this issue as it was fixed with 7.0.0 as commented above.

For anyone interested, there's now a mergeReducer config if the default deep merge does not work in your use case.

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

3 participants