Skip to content
Open
Changes from 1 commit
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
11 changes: 10 additions & 1 deletion src/Portal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,16 @@ const Portal = React.forwardRef<any, PortalProps>((props, ref) => {
const customizeContainer = getPortalContainer(getContainer);

// Tell component that we check this in effect which is safe to be `null`
setInnerContainer(customizeContainer ?? null);
setInnerContainer((prev) => {
const nextContainer = customizeContainer ?? null;
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

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

The nullish coalescing operator ?? incorrectly converts false to null. When getPortalContainer returns false (which happens when getContainer === false), it should remain false to maintain its semantic meaning. The code distinguishes between false (explicitly disabled portal) and null (container not available).

This will cause issues because:

  1. The state type is ContainerType | false, not including null
  2. Line 138 checks mergedContainer === false to determine inline rendering
  3. Converting false to null breaks this logic

Suggested fix:

setInnerContainer((prev) => {
  const nextContainer = customizeContainer === undefined ? null : customizeContainer;
  
  // Avoid cascading updates when the target container is unchanged
  if (prev === nextContainer) {
    return prev;
  }
  
  return nextContainer;
});
Suggested change
const nextContainer = customizeContainer ?? null;
const nextContainer = customizeContainer === undefined ? null : customizeContainer;

Copilot uses AI. Check for mistakes.
Copy link
Author

Choose a reason for hiding this comment

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

The nullish coalescing operator (??) only converts null or undefined to the right-hand value. It does not convert false to null.

Current code: customizeContainer ?? null
false → stays false
null → stays null
Element → stays Element
undefined → becomes null

Suggested change: customizeContainer === undefined ? null : customizeContainer
false → stays false
null → stays null
Element → stays Element
undefined → becomes null


// Avoid cascading updates when the target container is unchanged
if (prev === nextContainer) {
return prev;
}

return nextContainer;
});
});

const [defaultContainer, queueCreate] = useDom(
Expand Down