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
9 changes: 7 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 thread
coderabbitai[bot] marked this conversation as resolved.
/** 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 Expand Up @@ -272,6 +275,8 @@ class Page extends Component<PageProps, PageState> {
groupProps,
breadcrumbProps,
isContentFilled,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
mainRef,
...rest
} = this.props;
const { mobileView, mobileIsSidebarOpen, desktopIsSidebarOpen, width, height } = this.state;
Expand Down
Loading