-
Notifications
You must be signed in to change notification settings - Fork 332
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: decycle potentially cyclic structures before serializing #634
Conversation
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 79dacdd:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice change–we could definitely reuse these dev warnings in our other frontend libraries (and abstract them more).
434f276
to
5db5cdb
Compare
Co-authored-by: François Chalifour <[email protected]>
I've added a ticket for this in the backlog. It could be an onboarding task if we don't get to do it before. |
This introduces a
decycle
utility to replace cyclic references in objects before serializing them withJSON.stringify
.It uses a slightly modified version of Crockford's cycle.js, which MDN recommends. This works better than
JSON.stringify
'sreplacer
, because the latter walks every node in the object, making it difficult to preserve non-circular structures like the following:Whenever a circular reference is met, it's replaced with
[Circular]
(à la Jest).If sources contain complex objects (e.g., VNodes with SVGs), decycling could have a negative impact on performance. I've therefore introduced a change to
invariant
, making it acceptmessage
in the form of a function to execute only when the condition isn't met.fixes #618