Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions packages/react-core/src/components/Page/Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ export interface PageProps extends React.HTMLProps<HTMLDivElement> {
horizontalSubnav?: React.ReactNode;
/** Accessible label, can be used to name main section */
mainAriaLabel?: string;
/** Reference for the main section of the page */
mainRef?: React.RefObject<HTMLDivElement>;
Comment on lines +100 to +101

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Prevent mainRef from leaking onto the outer DOM element.

Because mainRef is not destructured in render, it remains in ...rest and is spread onto the page’s outer <div>, causing an invalid custom DOM prop/warning. Remove it from rest while using it as the main element’s ref.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/react-core/src/components/Page/Page.tsx` around lines 100 - 101,
Update the Page component’s render/destructuring logic to explicitly extract
mainRef from the props before collecting ...rest, then continue applying mainRef
to the main section ref. Ensure mainRef is excluded from the outer div’s spread
props while preserving all other rest properties.

/** Flag indicating if the horizontal sub navigation should be in a group */
isHorizontalSubnavGrouped?: boolean;
/** Flag indicating if the breadcrumb should be in a group */
Expand Down Expand Up @@ -132,9 +134,10 @@ class Page extends Component<PageProps, PageState> {
onNotificationDrawerExpand: () => null,
mainComponent: 'main',
getBreakpoint,
getVerticalBreakpoint
getVerticalBreakpoint,
mainRef: undefined
};
mainRef = createRef<HTMLDivElement>();
mainRef = this.props?.mainRef ? this.props.mainRef : createRef<HTMLDivElement>();
Comment on lines +137 to +140

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Resolve mainRef from current props, not once at construction.

The field initializer permanently captures the initial prop. If a caller supplies or replaces mainRef after mount, the component continues using the old ref; its mousedown/touch listeners are also attached to the wrong element. Keep a stable internal fallback, resolve the current prop during rendering/lifecycle updates, and rebind listeners when the ref identity changes.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/react-core/src/components/Page/Page.tsx` around lines 137 - 140,
Update the Page component’s mainRef handling so the constructor or field
initializer only creates a stable internal fallback, while rendering and
lifecycle logic resolve this.props.mainRef on each update. Track the effective
ref identity and rebind mousedown/touch listeners whenever it changes, ensuring
listeners are removed from the previous element and attached to the current one.

pageRef = createRef<HTMLDivElement>();
observer: any = () => {};

Expand Down
Loading