Skip to content

fix(DataViewFilters): avoid JSON.stringify crash on React element fil…#686

Open
aloktomarr wants to merge 1 commit into
patternfly:mainfrom
aloktomarr:fix/data-view-filters-cyclic-children-hash-12536
Open

fix(DataViewFilters): avoid JSON.stringify crash on React element fil…#686
aloktomarr wants to merge 1 commit into
patternfly:mainfrom
aloktomarr:fix/data-view-filters-cyclic-children-hash-12536

Conversation

@aloktomarr

Copy link
Copy Markdown

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

…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug - DataViewFilters - childrenHash from JSON.stringify results in cyclic object value

1 participant