Skip to content

fix: Default to OwnerDocument for Portal Container#214

Merged
NathanZlion merged 5 commits intomainfrom
dev-v3-natidere-iframe-fix
May 4, 2026
Merged

fix: Default to OwnerDocument for Portal Container#214
NathanZlion merged 5 commits intomainfrom
dev-v3-natidere-iframe-fix

Conversation

@NathanZlion
Copy link
Copy Markdown
Member

When container is not provided the Portal is created in the top most document of the window resulting in broken experience with out components when used in an iframe. Instead of fixing each case of Portal use fixing the issue here by making default behavior to go for the owner document for portal div creation.

Issue #, if available:

Description of changes:

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@NathanZlion NathanZlion requested a review from a team as a code owner April 28, 2026 16:36
@NathanZlion NathanZlion requested review from amanabiy and removed request for a team April 28, 2026 16:36
@NathanZlion NathanZlion marked this pull request as draft April 28, 2026 16:36
@NathanZlion NathanZlion requested review from a team and jperals and removed request for a team April 28, 2026 16:37
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 28, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.90%. Comparing base (0a8e78e) to head (886e464).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #214   +/-   ##
=======================================
  Coverage   98.90%   98.90%           
=======================================
  Files          44       44           
  Lines        1185     1190    +5     
  Branches      319      321    +2     
=======================================
+ Hits         1172     1177    +5     
  Misses         12       12           
  Partials        1        1           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread src/internal/portal/index.tsx Outdated
}, [container, getContainer, removeContainer]);

return activeContainer && createPortal(children, activeContainer);
if (!activeContainer) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why was this condition added?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Portal needs to which document to append to and React doesn't give us that because it hasn't mounted yet. So we see activeContainer is not there and we render the hidden span which mounts, then ownerDocument is read then we create the real container.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

OK. Can we add a comment explaining that?

Different question: what is the reason of the second part which was added to the condition, && typeof document !== 'undefined'?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Comment added,

Copy link
Copy Markdown
Member Author

@NathanZlion NathanZlion May 4, 2026

Choose a reason for hiding this comment

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

The typeof document !== 'undefined' is for SSR. We had SSR tests that were failing. Old portal returned null if no active document present so it was okay. Now we return the span but if it's on the SSR side we shouldn't until browser renders and document gets defined.

@NathanZlion NathanZlion marked this pull request as ready for review April 29, 2026 15:15
@NathanZlion NathanZlion requested review from jperals and removed request for amanabiy April 30, 2026 09:08
@NathanZlion NathanZlion enabled auto-merge May 4, 2026 13:27
@NathanZlion NathanZlion added this pull request to the merge queue May 4, 2026
Merged via the queue into main with commit a3a9cc2 May 4, 2026
114 of 116 checks passed
@NathanZlion NathanZlion deleted the dev-v3-natidere-iframe-fix branch May 4, 2026 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants