Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

rehydratedState is not recalculated on UPDATE_ACTION

See original GitHub issue

rehydratedState is defined only on INIT_ACTION. When localStorage is updated and then lazy-module is loaded, UPDATE_ACTION called and old state (rehydratedState from INIT) is used.

if ((action.type === INIT_ACTION || action.type === UPDATE_ACTION) && rehydratedState) { nextState = merge({}, nextState, rehydratedState); }

Use case:

  1. Login => token is saved in localstorage
  2. Reload the page => rehydratedState created with token
  3. Login with different user => new token stored in localstorage (but not synced with rehydratedState!)
  4. Go to lazy loaded page => UPDATE_ACTION, token is overridden with old token from step 2 😦((

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:3
  • Comments:19 (3 by maintainers)

github_iconTop GitHub Comments

rowandhcommented, Oct 10, 2019

If you want to skip all UPDATE_ACTION actions and don’t want to wait for this PR to be merged, there’s a simple way to do it. Replace your local storage sync reducer with a variant of this:

export function localStorageSyncReducer<T, V extends Action = Action> (reducer: ActionReducer<any>): ActionReducer<T, V> {
  return (state, action) => {
    if (action.type === '@ngrx/store/update-reducers')
      return reducer(state, action);

    return localStorageSync({
      rehydrate: true,
      removeOnUndefined: true,
      keys: []
    })(reducer)(state, action)
BovineEnthusiastcommented, Apr 10, 2019

@dimitriy-k Have you forked the project? I don’t see it in your GitHub profile. Make sure you’re not cloning this project but rather made a fork and cloned that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found