diff --git a/src/Portal.tsx b/src/Portal.tsx index 3678b74..2a2a9ec 100644 --- a/src/Portal.tsx +++ b/src/Portal.tsx @@ -91,8 +91,17 @@ const Portal = React.forwardRef((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; + + // Avoid cascading updates when the target container is unchanged + if (prev === nextContainer) { + return prev; + } + + return nextContainer; + }); + }, [getContainer]); const [defaultContainer, queueCreate] = useDom( mergedRender && !innerContainer,