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

trackProperties method in immutableStateInvariantMiddleware.ts is not correctly managing the circularity #4843

Open
paztis opened this issue Feb 5, 2025 · 3 comments

Comments

@paztis
Copy link

paztis commented Feb 5, 2025

https://github.com/reduxjs/redux-toolkit/blob/master/packages/toolkit/src/immutableStateInvariantMiddleware.ts#L57

function trackProperties(
  isImmutable: IsImmutableFunc,
  ignorePaths: IgnorePaths = [],
  obj: Record<string, any>,
  path: string = '',
  checkedObjects: Set<Record<string, any>> = new Set(),
) {
  const tracked: Partial<TrackedProperty> = { 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 as TrackedProperty
}

recursive call to trackProperties (line 57) is not passing down the checkedObjects argument.
It means all the circularity check you do in your code is totally bypass.

That's why immutable is not working with circular references

@paztis
Copy link
Author

paztis commented Feb 5, 2025

I create a PR to fix this: #4844

@paztis
Copy link
Author

paztis commented Feb 20, 2025

Hi. No approval or reject ?
This problem is important to fix

@markerikson
Copy link
Collaborator

markerikson commented Feb 20, 2025

It's low on the priority list atm - all of us maintainers have been busy with other things the last few weeks. We'll try to take a look when we get a chance!

In the meantime, you could disable the default version of the immutability middleware, paste the modified version into your app, and add that to the store instead.

@aryaemami59 aryaemami59 changed the title trackProperties method in immutableStateInvariantMiddleware.ts is not correctly managing the circularity trackProperties method in immutableStateInvariantMiddleware.ts is not correctly managing the circularity Feb 26, 2025
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