-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
fix trackProperties recursion #4844
base: master
Are you sure you want to change the base?
Conversation
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 6a17ea9:
|
✅ Deploy Preview for redux-starter-kit-docs ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Same problem here, which can be solved with this PR |
passdown the checkedObjects to detect circularity
The stack trace here is particularly odd, given that line 138 seems to be in the middle of a comment?
redux-toolkit/packages/toolkit/src/immutableStateInvariantMiddleware.ts Lines 134 to 150 in 6a17ea9
|
I can reproduce the brokenness from this change locally, although the line numbers are different:
|
It looks like the " state.foo.bar = new Array(10).fill({ value: 'more' }) rather than the Honestly I'm not sure what's going on here, and this is low enough priority that I don't want to get bogged down debugging it atm. |
Just solve it @paztis. Can you try it and modify #4844 ? Problem: I was encountering false-positive mutation detections because my Solution: I fixed the issue by introducing memoization in
This change ensures that each object reference is tracked only once, completely eliminating the false-positive mutation detections. This is the complete code for trackProperties with the problem fixed. @paztis , only have replace and update the PR. function trackProperties(
isImmutable: IsImmutableFunc,
ignorePaths: IgnorePaths = [],
obj: Record<string, any>,
path: string = '',
checkedObjects: WeakMap<any, TrackedProperty> = new WeakMap(),
) {
if (typeof obj !== 'object' || obj === null || isImmutable(obj)) {
return { value: obj, children: {} }
}
if (checkedObjects.has(obj)) {
return checkedObjects.get(obj)!
}
const tracked: TrackedProperty = { value: obj, children: {} }
checkedObjects.set(obj, tracked)
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,
checkedObjects,
)
}
return tracked as TrackedProperty
} |
passdown the checkedObjects to detect circularity