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
52 changes: 44 additions & 8 deletions frontend/public/components/utils/resource-log.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -812,20 +812,56 @@ export const ResourceLog: FC<ResourceLogProps> = ({

// Workaround for upstream PF LogViewer bug: scrollIntoView({ inline: 'center' }) propagates
// to all scrollable ancestors, shifting the page layout when searching with wrap lines disabled.
// Reset scrollLeft on .pf-v6-c-drawer__main to prevent the page shift.
// Reset scrollLeft on all scrollable ancestor containers to prevent the page shift.
// https://github.com/patternfly/react-log-viewer/issues/106
useEffect(() => {
const drawerMain = fullscreenRef.current?.closest('.pf-v6-c-drawer__main');
if (!drawerMain) {
if (!fullscreenRef.current) {
return;
}
const resetScroll = () => {
if (drawerMain.scrollLeft !== 0) {
drawerMain.scrollLeft = 0;

// Find all scrollable ancestor containers that could be affected
const scrollableAncestors: HTMLElement[] = [];
let element = fullscreenRef.current.parentElement;

while (element) {
const computedStyle = window.getComputedStyle(element);
const overflowX = computedStyle.overflowX;

// Check if this element can scroll horizontally
if (overflowX === 'auto' || overflowX === 'scroll') {
scrollableAncestors.push(element);
}

// Also explicitly include known PatternFly containers
if (
element.classList.contains('pf-v6-c-drawer__main') ||
element.classList.contains('pf-v6-c-page__main') ||
element.classList.contains('pf-v6-c-page__main-container')
) {
scrollableAncestors.push(element);
}

element = element.parentElement;
}

const resetScroll = () => {
scrollableAncestors.forEach((container) => {
if (container.scrollLeft !== 0) {
container.scrollLeft = 0;
}
});
};

// Attach scroll listeners to all identified containers
scrollableAncestors.forEach((container) => {
container.addEventListener('scroll', resetScroll);
});

return () => {
scrollableAncestors.forEach((container) => {
container.removeEventListener('scroll', resetScroll);
});
};
drawerMain.addEventListener('scroll', resetScroll);
return () => drawerMain.removeEventListener('scroll', resetScroll);
}, [fullscreenRef]);

return (
Expand Down