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

composeWithDevTools: Infinite recursion when used with enhanced getState #556

Closed
danhart opened this issue Sep 26, 2018 · 2 comments
Closed

Comments

@danhart
Copy link

danhart commented Sep 26, 2018

Here's a very basic, valid, store enhancer that essentially wraps the store's original getState in a new getState function:

const basicStoreEnhancer = (createStore) => (...args) => {
  const store = createStore(...args);

  return {
    ...store,
    getState: () => store.getState(),
  };
};

When used with Redux's compose, this enhancer works perfectly with no impact at all. However, when used within a composeWithDevTools, it results in a RangeError: Maximum call stack size exceeded.

This is because of this line, which mutates the store causing our getState call to become infinitely recursive:

stores[instanceId].getState = store.getState;

It's possible to work around the issue like this:

const basicStoreEnhancer = (createStore) => (...args) => {
  const store = createStore(...args);
  const originalGetState = store.getState;

  return {
    ...store,
    getState: () => originalGetState(),
  };
};

These issues seem relevant:
#248
#551

@zalmoxisus
Copy link
Owner

Thanks for the details and for investigation! That mutation was introduced for enhancers which change the store after our enhancer was applied (as in #133). But I tried now with saga example and it seems unnecessary now, a lot was changed since then.

@zalmoxisus
Copy link
Owner

It should work in 2.16, which will land in a day on Chrome Store. Thanks again for debugging it!

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