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

fix: accounts controller type error #4331

Merged
merged 6 commits into from
May 29, 2024

Conversation

montelaidev
Copy link
Contributor

@montelaidev montelaidev commented May 28, 2024

Explanation

This PR is a temp fix for the type error Type instantiation is excessively deep and possibly infinite. when updating the state.

References

Related to: MetaMask/utils#168

Changelog

@metamask/accounts-controller

  • FIXED: Type error during state update

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've highlighted breaking changes using the "BREAKING" category above as appropriate

* Creates a deep clone of the given object.
* This is to get around error `Type instantiation is excessively deep and possibly infinite.`
*
* @template O,T - The type of the object being cloned.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

Suggested change
* @template O,T - The type of the object being cloned.
* @template I,T - The type of the object being cloned.

Comment on lines 91 to 93
export function deepCloneDraft<I, T>(obj: I): T {
return JSON.parse(JSON.stringify(obj)) as T;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about this solution. I can foresee some problems if the data type has Map, Set, RegExp objects. And also the parse and stringify operations are quite expensive in terms of performance for large objects which is what the error suggests in this case. Lastly, stringify is a bit unpredictable in some cases.

I'd strongly suggest to use another solution for this case.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like on the Snap side, they are using this: https://www.npmjs.com/package/rfdc

So we're gonna use their deepClone (from snaps-utils)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

structuredClone was not available in node 16

ccharly
ccharly previously approved these changes May 29, 2024
@montelaidev montelaidev merged commit 6cbaa1c into main May 29, 2024
147 checks passed
@montelaidev montelaidev deleted the fix/accounts-controller-type-error-in-update branch May 29, 2024 09:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants