Skip to content

Commit f3a5cb7

Browse files
Fix/nextjs hydration errors 12250 (#12251)
* refactor: #12250: replace GenerateId with useSSRSafeId in multiple components - Updated AboutModal, CalendarMonth, CardHeader, Checkbox, DataListCheck, DrawerPanelContent, DualListSelector, DualListSelectorListItem, DualListSelectorListWrapper, DualListSelectorPane, ExpandableSection, FormGroup, InternalFormFieldGroup, JumpLinks, and MenuItem components to use useSSRSafeId for generating unique IDs instead of GenerateId. - This change improves consistency and simplifies ID generation across components. * refactor: replace default ID generation with SSRSafeIds in multiple components - Updated Checkbox, ExpandableSection, FormSelect, Menu, MenuToggle, MenuToggleCheckbox, Modal, Nav, NavExpandable, and Progress components to utilize SSRSafeIds for generating unique IDs. - This change enhances ID management and ensures consistency across components. * fix: restore getDefaultOUIAId for deprecated class components The deprecated Table class component in react-table still requires getDefaultOUIAId which cannot be replaced with hooks. Re-added as a simplified legacy function marked @deprecated. Co-authored-by: Cursor <cursoragent@cursor.com> * refactor: streamline interface definitions across multiple components - improve interface definitions by removing unnecessary line breaks and enhancing readability. - This change maintains consistency in code style across the codebase. * fix: correct prettier formatting and update snapshots Reformatted with Prettier 3.8.1 to match CI and updated snapshot * fix: rebuild dist and update all remaining snapshots * fix: update snapshots for various components - Updated snapshots for CodeEditor, AboutModalBoxCloseButton, AlertActionCloseButton, AlertIcon, ClipboardCopyButton, and others to reflect recent changes in SVG icons and structure. - Ensured consistency in icon rendering across components by replacing placeholder paths with actual SVG elements. * refactor: update useSSRSafeId to utilize useId from React - Replaced the import of React's useId with a direct import from 'react' in the useSSRSafeId helper. - This change simplifies the code and ensures compatibility with the latest React features. * fix(ToolbarLabelGroup): handle window resize events for responsive design - Added a resize event listener to update the viewport width in the ToolbarLabelGroup component. - Ensured proper cleanup of the event listener in componentWillUnmount. - Updated Cypress tests for the Switch component to reflect changes in element visibility and interaction. * fix(FormSelect): update ouiaComponentType to use displayName for improved accessibility - Changed the ouiaComponentType prop in FormSelect to utilize the component's displayName instead of a concatenated string with validation status. * fix(Tooltip): improve aria attribute handling for better accessibility - Updated the logic for modifying the existing aria attribute to use split and filter methods, ensuring that the specified ID is removed correctly. * fix(FormSelect): update snapshot ouiaComponentId format for consistency - Modified the ouiaComponentId in FormSelect snapshots to remove the "default" and validation status, ensuring a uniform format across all instances. * fix(DrawerPanelContent): update class name for no glass modifier to use new format --------- Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 641c888 commit f3a5cb7

File tree

129 files changed

+2639
-2587
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

129 files changed

+2639
-2587
lines changed

packages/react-code-editor/src/components/CodeEditor/__test__/__snapshots__/CodeEditor.test.tsx.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ exports[`Matches snapshot with control buttons enabled 1`] = `
2525
<button
2626
aria-label="Copy code to clipboard"
2727
class="pf-v6-c-button pf-m-plain"
28-
data-ouia-component-id="OUIA-Generated-Button-plain-1"
28+
data-ouia-component-id="OUIA-Generated-Button-plain-:r1:"
2929
data-ouia-component-type="PF6/Button"
3030
data-ouia-safe="true"
3131
type="button"
@@ -67,7 +67,7 @@ exports[`Matches snapshot with control buttons enabled 1`] = `
6767
<button
6868
aria-label="Upload code"
6969
class="pf-v6-c-button pf-m-plain"
70-
data-ouia-component-id="OUIA-Generated-Button-plain-2"
70+
data-ouia-component-id="OUIA-Generated-Button-plain-:r3:"
7171
data-ouia-component-type="PF6/Button"
7272
data-ouia-safe="true"
7373
type="button"
@@ -109,7 +109,7 @@ exports[`Matches snapshot with control buttons enabled 1`] = `
109109
<button
110110
aria-label="Download code"
111111
class="pf-v6-c-button pf-m-plain"
112-
data-ouia-component-id="OUIA-Generated-Button-plain-3"
112+
data-ouia-component-id="OUIA-Generated-Button-plain-:r5:"
113113
data-ouia-component-type="PF6/Button"
114114
data-ouia-safe="true"
115115
type="button"

packages/react-code-editor/src/components/CodeEditor/__test__/__snapshots__/CodeEditorControl.test.tsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ exports[`Matches snapshot 1`] = `
77
>
88
<button
99
class="pf-v6-c-button pf-m-plain"
10-
data-ouia-component-id="OUIA-Generated-Button-plain-1"
10+
data-ouia-component-id="OUIA-Generated-Button-plain-:r1:"
1111
data-ouia-component-type="PF6/Button"
1212
data-ouia-safe="true"
1313
type="button"

packages/react-core/src/components/AboutModal/AboutModal.tsx

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { AboutModalBoxBrand } from './AboutModalBoxBrand';
66
import { AboutModalBoxCloseButton } from './AboutModalBoxCloseButton';
77
import { AboutModalBox } from './AboutModalBox';
88
import { Modal, ModalVariant } from '../Modal';
9-
import { GenerateId } from '../../helpers/GenerateId/GenerateId';
9+
import { useSSRSafeId } from '../../helpers';
1010

1111
export interface AboutModalProps extends React.HTMLProps<HTMLDivElement> {
1212
/** Content rendered inside the about modal */
@@ -56,6 +56,8 @@ export const AboutModal: React.FunctionComponent<AboutModalProps> = ({
5656
disableFocusTrap,
5757
...props
5858
}: AboutModalProps) => {
59+
const ariaLabelledBy = useSSRSafeId('pf-about-modal-title-');
60+
5961
if (brandImageSrc && !brandImageAlt) {
6062
// eslint-disable-next-line no-console
6163
console.error(
@@ -73,35 +75,29 @@ export const AboutModal: React.FunctionComponent<AboutModalProps> = ({
7375
return null;
7476
}
7577
return (
76-
<GenerateId prefix="pf-about-modal-title-">
77-
{(ariaLabelledBy) => (
78-
<Modal
79-
isOpen={isOpen}
80-
variant={ModalVariant.large}
81-
{...(productName && { 'aria-labelledby': ariaLabelledBy })}
82-
aria-label={ariaLabel}
83-
onEscapePress={onClose}
84-
appendTo={appendTo}
85-
disableFocusTrap={disableFocusTrap}
86-
>
87-
<AboutModalBox
88-
style={
89-
backgroundImageSrc
90-
? ({ [backgroundImage.name]: `url(${backgroundImageSrc})` } as React.CSSProperties)
91-
: {}
92-
}
93-
className={css(className)}
94-
>
95-
<AboutModalBoxBrand src={brandImageSrc} alt={brandImageAlt} />
96-
<AboutModalBoxCloseButton aria-label={closeButtonAriaLabel} onClose={onClose} />
97-
{productName && <AboutModalBoxHeader id={ariaLabelledBy} productName={productName} />}
98-
<AboutModalBoxContent trademark={trademark} hasNoContentContainer={hasNoContentContainer} {...props}>
99-
{children}
100-
</AboutModalBoxContent>
101-
</AboutModalBox>
102-
</Modal>
103-
)}
104-
</GenerateId>
78+
<Modal
79+
isOpen={isOpen}
80+
variant={ModalVariant.large}
81+
{...(productName && { 'aria-labelledby': ariaLabelledBy })}
82+
aria-label={ariaLabel}
83+
onEscapePress={onClose}
84+
appendTo={appendTo}
85+
disableFocusTrap={disableFocusTrap}
86+
>
87+
<AboutModalBox
88+
style={
89+
backgroundImageSrc ? ({ [backgroundImage.name]: `url(${backgroundImageSrc})` } as React.CSSProperties) : {}
90+
}
91+
className={css(className)}
92+
>
93+
<AboutModalBoxBrand src={brandImageSrc} alt={brandImageAlt} />
94+
<AboutModalBoxCloseButton aria-label={closeButtonAriaLabel} onClose={onClose} />
95+
{productName && <AboutModalBoxHeader id={ariaLabelledBy} productName={productName} />}
96+
<AboutModalBoxContent trademark={trademark} hasNoContentContainer={hasNoContentContainer} {...props}>
97+
{children}
98+
</AboutModalBoxContent>
99+
</AboutModalBox>
100+
</Modal>
105101
);
106102
};
107103
AboutModal.displayName = 'AboutModal';

packages/react-core/src/components/AboutModal/__tests__/__snapshots__/AboutModalBoxCloseButton.test.tsx.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ exports[`AboutModalBoxCloseButton Test 1`] = `
88
<button
99
aria-label="Close Dialog"
1010
class="pf-v6-c-button pf-m-plain"
11-
data-ouia-component-id="OUIA-Generated-Button-plain-1"
11+
data-ouia-component-id="OUIA-Generated-Button-plain-:r0:"
1212
data-ouia-component-type="PF6/Button"
1313
data-ouia-safe="true"
1414
type="button"
@@ -55,7 +55,7 @@ exports[`AboutModalBoxCloseButton Test close button aria label 1`] = `
5555
<button
5656
aria-label="Klose Daylok"
5757
class="pf-v6-c-button pf-m-plain"
58-
data-ouia-component-id="OUIA-Generated-Button-plain-3"
58+
data-ouia-component-id="OUIA-Generated-Button-plain-:r2:"
5959
data-ouia-component-type="PF6/Button"
6060
data-ouia-safe="true"
6161
type="button"
@@ -102,7 +102,7 @@ exports[`AboutModalBoxCloseButton Test onclose 1`] = `
102102
<button
103103
aria-label="Close Dialog"
104104
class="pf-v6-c-button pf-m-plain"
105-
data-ouia-component-id="OUIA-Generated-Button-plain-2"
105+
data-ouia-component-id="OUIA-Generated-Button-plain-:r1:"
106106
data-ouia-component-type="PF6/Button"
107107
data-ouia-safe="true"
108108
type="button"

packages/react-core/src/components/AboutModal/__tests__/__snapshots__/AboutModalBoxHeader.test.tsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ exports[`AboutModalBoxHeader Test 1`] = `
77
>
88
<h1
99
class="pf-v6-c-title pf-m-4xl"
10-
data-ouia-component-id="OUIA-Generated-Title-1"
10+
data-ouia-component-id="OUIA-Generated-Title-:r0:"
1111
data-ouia-component-type="PF6/Title"
1212
data-ouia-safe="true"
1313
id="id"

packages/react-core/src/components/Alert/__tests__/Generated/__snapshots__/AlertActionCloseButton.test.tsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ exports[`AlertActionCloseButton should match snapshot 1`] = `
55
<button
66
aria-label="Close some label alert: test title"
77
class="pf-v6-c-button pf-m-plain"
8-
data-ouia-component-id="OUIA-Generated-Button-plain-1"
8+
data-ouia-component-id="OUIA-Generated-Button-plain-:r0:"
99
data-ouia-component-type="PF6/Button"
1010
data-ouia-safe="true"
1111
type="button"

packages/react-core/src/components/Alert/__tests__/Generated/__snapshots__/AlertActionLink.test.tsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ exports[`AlertActionLink should match snapshot (auto-generated) 1`] = `
44
<DocumentFragment>
55
<button
66
class="pf-v6-c-button pf-m-link pf-m-inline ''"
7-
data-ouia-component-id="OUIA-Generated-Button-link-1"
7+
data-ouia-component-id="OUIA-Generated-Button-link-:r0:"
88
data-ouia-component-type="PF6/Button"
99
data-ouia-safe="true"
1010
type="button"

packages/react-core/src/components/Breadcrumb/__tests__/__snapshots__/Breadcrumb.test.tsx.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ exports[`Breadcrumb component should render breadcrumb with aria-label 1`] = `
55
<nav
66
aria-label="custom label"
77
class="pf-v6-c-breadcrumb"
8-
data-ouia-component-id="OUIA-Generated-Breadcrumb-3"
8+
data-ouia-component-id="OUIA-Generated-Breadcrumb-:r2:"
99
data-ouia-component-type="PF6/Breadcrumb"
1010
data-ouia-safe="true"
1111
>
@@ -22,7 +22,7 @@ exports[`Breadcrumb component should render breadcrumb with children 1`] = `
2222
<nav
2323
aria-label="Breadcrumb"
2424
class="pf-v6-c-breadcrumb"
25-
data-ouia-component-id="OUIA-Generated-Breadcrumb-4"
25+
data-ouia-component-id="OUIA-Generated-Breadcrumb-:r3:"
2626
data-ouia-component-type="PF6/Breadcrumb"
2727
data-ouia-safe="true"
2828
>
@@ -90,7 +90,7 @@ exports[`Breadcrumb component should render breadcrumb with className 1`] = `
9090
<nav
9191
aria-label="Breadcrumb"
9292
class="pf-v6-c-breadcrumb className"
93-
data-ouia-component-id="OUIA-Generated-Breadcrumb-2"
93+
data-ouia-component-id="OUIA-Generated-Breadcrumb-:r1:"
9494
data-ouia-component-type="PF6/Breadcrumb"
9595
data-ouia-safe="true"
9696
>
@@ -107,7 +107,7 @@ exports[`Breadcrumb component should render default breadcrumb 1`] = `
107107
<nav
108108
aria-label="Breadcrumb"
109109
class="pf-v6-c-breadcrumb"
110-
data-ouia-component-id="OUIA-Generated-Breadcrumb-1"
110+
data-ouia-component-id="OUIA-Generated-Breadcrumb-:r0:"
111111
data-ouia-component-type="PF6/Breadcrumb"
112112
data-ouia-safe="true"
113113
>

packages/react-core/src/components/Button/__tests__/__snapshots__/Button.test.tsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ exports[`Renders basic button 1`] = `
55
<button
66
aria-label="basic button"
77
class="pf-v6-c-button pf-m-primary"
8-
data-ouia-component-id="OUIA-Generated-Button-primary-67"
8+
data-ouia-component-id="OUIA-Generated-Button-primary-:r30:"
99
data-ouia-component-type="PF6/Button"
1010
data-ouia-safe="true"
1111
type="button"

packages/react-core/src/components/CalendarMonth/CalendarMonth.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import AngleLeftIcon from '@patternfly/react-icons/dist/esm/icons/angle-left-ico
88
import AngleRightIcon from '@patternfly/react-icons/dist/esm/icons/angle-right-icon';
99
import { css } from '@patternfly/react-styles';
1010
import styles from '@patternfly/react-styles/css/components/CalendarMonth/calendar-month';
11-
import { getUniqueId } from '../../helpers/util';
11+
import { useSSRSafeId } from '../../helpers';
1212
import { isValidDate } from '../../helpers/datetimeUtils';
1313

1414
export enum Weekday {
@@ -170,7 +170,7 @@ export const CalendarMonth = ({
170170

171171
const [hoveredDate, setHoveredDate] = useState<Date>(undefined);
172172
const focusRef = useRef<HTMLButtonElement>(undefined);
173-
const [hiddenMonthId] = useState(getUniqueId('hidden-month-span'));
173+
const hiddenMonthId = useSSRSafeId('hidden-month-span');
174174
const [shouldFocus, setShouldFocus] = useState(false);
175175

176176
const isValidated = (date: Date) => validators.every((validator) => validator(date));

0 commit comments

Comments
 (0)