Skip to content

composeWithDevTools: Infinite recursion when used with enhanced getState #556

@danhart

Description

@danhart

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions