fix(DataViewFilters): avoid JSON.stringify crash on React element fil…#686
Open
aloktomarr wants to merge 1 commit into
Open
Conversation
…ter labels
childrenHash serialized each child's full props via JSON.stringify. When a DataViewCheckboxFilter option label is a React element (e.g. an icon), the props contain React elements whose owner-fiber references are circular, so JSON.stringify threw 'cyclic object value' and the component crashed on render.
Add a replacer that serializes any nested React element as a stable { type, key } descriptor so hashing no longer recurses into circular internals. childrenHash only gates the filterItems memo (which reads filterId/title), so behavior is unchanged. Includes a regression test.
Fixes patternfly/patternfly-react#12536
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.
DataViewFilters hashed its children by running JSON.stringify on each child's full props to produce a childrenHash for change detection. When a DataViewCheckboxFilter option label is a React element (e.g. an icon), those props contain React elements whose internal owner-fiber references are circular, so JSON.stringify throws cyclic object value and the component crashes on render.
This adds a JSON.stringify replacer that serializes any nested React element as a stable { type, key } descriptor instead of recursing into its circular internals. childrenHash only gates the filterItems memo (which reads filterId/title), so change-detection behavior is unchanged; it simply no longer crashes when a label is a component.
Adds a regression test that renders a checkbox filter with a React element option label (created inside a wrapper component so the element has an owner, which is what triggers the cycle). It fails on main and passes with the fix; the full DataViewFilters/DataViewCheckboxFilter suites and snapshots still pass.
Fixes patternfly/patternfly-react#12536