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

immer maximum call stack size exceeded #925

Closed
pixfirewall opened this issue Mar 15, 2021 · 5 comments
Closed

immer maximum call stack size exceeded #925

pixfirewall opened this issue Mar 15, 2021 · 5 comments

Comments

@pixfirewall
Copy link

i faced with "maximum call stack size exceeded" with createSlice when i want to update state with a very deeply nested object.
i don’t have this issue when i use pure redux
because the object it very deep, immer face this issue for immutability check
is there any solution to turn of immer for particular action?

image

@markerikson
Copy link
Collaborator

This actually has nothing to do with Immer. It's the immutable-state-invariant middleware that RTK uses to catch mutations.

Just how deeply nested is your state?

If you really need to, you can turn off the mutation check:

https://redux-toolkit.js.org/api/getDefaultMiddleware#customizing-the-included-middleware

@pixfirewall
Copy link
Author

my object is google map

@markerikson
Copy link
Collaborator

Ah, that's the problem. You're trying to put non-serializable values with circular references into the Redux store, which you should not be doing:

https://redux.js.org/style-guide/style-guide#do-not-put-non-serializable-values-in-state-or-actions

That's causing the immutability middleware to infinitely recurse through that object.

If you stop putting that Google Map object into the Redux store, you'll stop getting this error.

@paztis
Copy link

paztis commented Feb 5, 2025

reopening this as I face same issues (I try to store dereferences JSONSchema)
I really want to enable the mutation and I don't understand why it fails.

I already disable serializableCheck as of course it is not serializable.
But immer is able to detect circularity and avoid this crash.

this is their problematic code:

function trackProperties(isImmutable, ignorePaths = [], obj, path = "", checkedObjects = /* @__PURE__ */ new Set()) {
  const tracked = {
    value: obj
  };
  if (!isImmutable(obj) && !checkedObjects.has(obj)) {
    checkedObjects.add(obj);
    tracked.children = {};
    for (const key in obj) {
      const childPath = path ? path + "." + key : key;
      if (ignorePaths.length && ignorePaths.indexOf(childPath) !== -1) {
        continue;
      }
      tracked.children[key] = trackProperties(isImmutable, ignorePaths, obj[key], childPath);
    }
  }
  return tracked;
}

They have a checkedObjects param to detect this, but it seems not to work.
Can this be actively followed ?

Disabling the mutation is not an option for me. I just want to avoid people to modify the data from the the UI part

@paztis
Copy link

paztis commented Feb 5, 2025

oh wait there's an error in your code in fact
I just open another defect: #4843

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