fix: prevent browser freeze when args contain non-serializable values#33834
Open
sonsu-lee wants to merge 2 commits intostorybookjs:nextfrom
Open
fix: prevent browser freeze when args contain non-serializable values#33834sonsu-lee wants to merge 2 commits intostorybookjs:nextfrom
sonsu-lee wants to merge 2 commits intostorybookjs:nextfrom
Conversation
inferType() in inferArgTypes.ts recursively traversed all properties of any object to infer arg types for the Controls panel. When args contained refs (createRef()) pointing to DOM elements, this caused exponential traversal through the DOM tree and React Fiber internals, freezing the browser tab. Add isPlainObject guard to skip non-plain objects (DOM elements, class instances, Map, Set, etc.) and return them as opaque types instead of recursing into their properties. Date, RegExp, and Error are handled separately to avoid false warnings since telejson serializes them safely. Fixes storybookjs#33821
Contributor
📝 WalkthroughWalkthroughAdds detection and handling for non-serializable and non-plain-object values in inferArgTypes and introduces comprehensive unit tests covering Date, RegExp, Error, Map/Set, class instances, DOM-like structures, mutable refs, and null/undefined cases. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes ✨ Finishing touches
No actionable comments were generated in the recent review. 🎉 Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What I did
inferType()ininferArgTypes.tsrecursively traversed all properties of any object to infer arg types for the Controls panel. When args contained refs (createRef()) whose.currentpointed to DOM elements after rendering, this caused exponential traversal through the DOM tree and React Fiber internals, freezing the browser tab.The existing
visitedSet usesnew Set(visited)at each branch for sibling path independence, so the same object reached via different paths is not detected as a cycle — leading to exponential traversal on wide objects like DOM elements (200+ properties each).Added an
isPlainObjectguard so that non-plain objects (DOM elements, class instances,Map,Set, etc.) are returned as opaque types instead of being recursed into.Date,RegExp, andErrorare handled explicitly before this guard to avoid false warnings, since telejson already serializes them safely.Closes #33821, closes #17098, closes #19575, closes #28750, closes #17482, closes #16855
Possibly related: #29381
Checklist for Contributors
Testing
The changes in this PR are covered in the following automated tests:
Manual testing
createRef(), a fetcher object containing React components)Reproduction repo: https://github.com/sonsu-lee/storybook-args-serialize-bug
Documentation
MIGRATION.MD
Summary by CodeRabbit
Bug Fixes
Tests