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
8 changes: 5 additions & 3 deletions frontend/public/components/utils/resource-log.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ const LogControls: FC<LogControlsProps> = ({
const [isLogTypeOpen, setIsLogTypeOpen] = useState(false);
const [isOptionsOpen, setIsOptionsOpen] = useState(false);

const toolbarId = `resource-log-toolbar-${resource?.metadata?.name || 'unknown'}`;

const logTypes: Array<LogType> = [
{ type: LOG_TYPE_CURRENT, text: t('Current log') },
{ type: LOG_TYPE_PREVIOUS, text: t('Previous log') },
Expand Down Expand Up @@ -272,7 +274,7 @@ const LogControls: FC<LogControlsProps> = ({
onOpenChange={(isOpen) => setIsLogTypeOpen(isOpen)}
isOpen={isLogTypeOpen}
popperProps={{
appendTo: 'inline', // needed for fullscreen
appendTo: isFullscreen ? () => document.getElementById(toolbarId) : undefined,
}}
Comment on lines +277 to 278
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Prevent null popper container in fullscreen append path.

At Line 277 and Line 361, document.getElementById(toolbarId) can return null during rapid unmount/remount transitions. Add a safe fallback container to avoid intermittent crashes.

Proposed fix
+  const getPopperContainer = useCallback(
+    () => document.getElementById(toolbarId) ?? document.body,
+    [toolbarId],
+  );
...
         popperProps={{
-          appendTo: isFullscreen ? () => document.getElementById(toolbarId) : undefined,
+          appendTo: isFullscreen ? getPopperContainer : undefined,
         }}
...
       popperProps={{
-        appendTo: isFullscreen ? () => document.getElementById(toolbarId) : undefined,
+        appendTo: isFullscreen ? getPopperContainer : undefined,
       }}

Also applies to: 361-362

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@frontend/public/components/utils/resource-log.tsx` around lines 277 - 278,
The appendTo callback can return null when document.getElementById(toolbarId) is
not found during rapid transitions; update the appendTo for the fullscreen path
to return a non-null fallback (e.g., document.body or a created fallback
element) so Popper never receives null. Specifically modify the appendTo that
currently uses () => document.getElementById(toolbarId) (and the similar
occurrence around the toolbarId use at the other location) to check for a found
element and fallback to document.body (or a persistent container) before
returning.

>
<SelectList>
Expand Down Expand Up @@ -356,7 +358,7 @@ const LogControls: FC<LogControlsProps> = ({
onOpenChange={setIsOptionsOpen}
isOpen={isOptionsOpen}
popperProps={{
appendTo: 'inline', // needed for fullscreen
appendTo: isFullscreen ? () => document.getElementById(toolbarId) : undefined,
}}
>
<SelectList>
Expand Down Expand Up @@ -412,7 +414,7 @@ const LogControls: FC<LogControlsProps> = ({
));

return (
<Toolbar data-test="resource-log-toolbar">
<Toolbar data-test="resource-log-toolbar" id={toolbarId}>
<ToolbarContent>
<ToolbarGroup className="pf-v6-u-display-flex pf-v6-u-flex-direction-column pf-v6-u-flex-direction-row-on-md pf-v6-u-w-100">
<ToolbarGroup align={{ default: 'alignStart' }}>
Expand Down