Skip to content

UI: Close non-modal form popups on iframe press - #83778

Closed
mirka wants to merge 16 commits into
trunkfrom
fix-form-iframe-dismissal
Closed

mirka wants to merge 16 commits into
trunkfrom
fix-form-iframe-dismissal

Conversation

@mirka

@mirka mirka commented Sep 29, 2026 •

Copy link
Copy Markdown
Member

What?

Follow up to #83509

Non-modal Select, Combobox, and Autocomplete popups close when a user clicks or taps inside a same-origin iframe outside the popup, while the iframe receives that interaction. This also covers SelectControl with modal={ false } and searchable controls built on Combobox.

Why?

Base UI listens for outside presses in the popup document. Pointer events inside an iframe do not reach that document. The existing bridge handles Menu and Popover, but form roots need Base UI to report dismissal through their normal onOpenChange path.

How?

useIframePressListeners shares iframe event observation between the two adapters. useIframeDismissalWithCloseAction preserves the existing Menu and Popover behavior by calling their close action. useIframeOutsidePressForwarding forwards pointer, compatibility mouse-down, and click events to the containing iframe element in the trigger document, allowing Base UI to dismiss form popups with its normal outside-press reason. Forwarding the compatibility mouse-down event preserves Select dismissal for touch taps. Both adapters share the popup containment check from #83870.

This fix covers form compositions whose trigger and popup share a document. Compositions split across documents are outside this PR's scope.

Like the existing bridge, this one discovers its trigger from an opening interaction. Popups opened only through defaultOpen or an external open change are a separate follow-up.

Testing Instructions

  1. Render a non-modal Select, Combobox, or Autocomplete next to a same-origin iframe containing a button. Open the popup and click the iframe button. The popup should close on the first click and the button should receive it once.
  2. Repeat with touch input. Open a non-modal popup and tap the iframe button. The popup should close, and the button should receive the tap once. Also check SelectControl with modal={ false }.
  3. Repeat with a default modal SelectControl. Its backdrop should close the popup and consume the first click.
  4. Click an iframe contained inside an open popup. The popup should stay open.

Screenshots or screencast

The iframe button receives all three mouse clicks in each recording. Before this fix, the popups stay open. After this fix, they close.

Before fix

iframe-dismissal-before.mp4

After fix

iframe-dismissal-after.mp4

@mirka mirka added the [Type] Bug An existing feature does not function as intended label Sep 29, 2026
@mirka mirka self-assigned this Sep 29, 2026
@github-actions github-actions Bot added the [Package] UI /packages/ui label Sep 29, 2026
@github-actions

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

🎉 Props

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: mirka <0mirka00@git.wordpress.org>
Co-authored-by: ciampo <mciampini@git.wordpress.org>
Co-authored-by: jsnajdr <jsnajdr@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Updated as activity occurs, without notifying anyone named here. Add the props-bot label to refresh.

📦 Bundle size

Size Change: +6.88 kB (+0.08%)

Total Size: 8.66 MB

📦 View Changed
Filename Size Change
build/modules/workflow/index.min.js 89.6 kB +1.31 kB (+1.48%)
build/scripts/block-editor/index.min.js 598 kB +694 B (+0.12%)
build/scripts/block-library/index.min.js 443 kB +1.39 kB (+0.31%)
build/scripts/components/index.min.js 357 kB +107 B (+0.03%)
build/scripts/edit-site/index.min.js 397 kB +71 B (+0.02%)
build/scripts/editor/index.min.js 652 kB +812 B (+0.12%)
build/scripts/format-library/index.min.js 90.4 kB +1.2 kB (+1.35%)
build/scripts/media-utils/index.min.js 238 kB +73 B (+0.03%)
build/scripts/widgets/index.min.js 71.5 kB +1.23 kB (+1.75%)

From d342f9c, not the current head. Run

⚡ Performance

Show the results

Client side metrics exclude the server response time.

front-end-block-theme

Metric ca3af13 trunk % Change
timeToFirstByte 49.25 ms +7.31% -3.65% 49.45 ms +2.73% -4.45% -0.4%
largestContentfulPaint 88 ms +4.55% -6.82% 84 ms +7.14% -4.76% 4.76%
lcpMinusTtfb 36.9 ms +13.55% -10.57% 34.6 ms +19.08% -4.34% 6.65%
wpBeforeTemplate 24.87 ms +9.89% -3.74% 24.62 ms +7.19% -2.56% 1.02%
wpTemplate 20.42 ms +6.27% -5.88% 20.31 ms +4.97% -5.02% 0.54%
wpTotal 45.43 ms +7.51% -4.16% 45.52 ms +3.1% -4.35% -0.2%
wpMemoryUsage 7.61 MB +0% -0% 7.57 MB +0% -0% 0.46%
wpDbQueries 17 +0% -0% 17 +0% -0% 0%

front-end-classic-theme

Metric ca3af13 trunk % Change
timeToFirstByte 36.35 ms +3.71% -1.93% 40.85 ms +4.16% -3.92% -11.02%
largestContentfulPaint 84 ms +0% -2.38% 92 ms +4.35% -0% -8.7%
lcpMinusTtfb 47.5 ms +1.47% -5.26% 52.8 ms +1.61% -1.42% -10.04%
wpBeforeTemplate 21.65 ms +3.37% -1.76% 21.64 ms +4.81% -1.25% 0.05%
wpTemplate 11.74 ms +3.66% -2.64% 15.83 ms +4.99% -6.25% -25.84%
wpTotal 33.4 ms +3.68% -2.31% 37.64 ms +4.28% -4.06% -11.26%
wpMemoryUsage 6.16 MB +0% -0% 6.23 MB +0% -0% -1.21%
wpDbQueries 10 +0% -0% 14 +0% -0% -28.57%

media-processing

Metric ca3af13 trunk % Change
mediaProcessingJpeg 395.59 ms +1.82% -0.29% 397.22 ms +0.47% -0.45% -0.41%
mediaProcessingAvif 5781.78 ms +0.13% -0.12% 5795.77 ms +0.05% -0.17% -0.24%
mediaProcessingJpegToAvif 3961.35 ms +0.32% -0.12% 3958.18 ms +0.17% -0.08% 0.08%

media-upload

Metric ca3af13 trunk % Change
jpegUploadProcessing 1445.83 ms +36.84% -1.35% 1439.2 ms +0.6% -1.77% 0.46%
pngUploadProcessing 214.92 ms +5.17% -3.5% 225.99 ms +5.12% -4.62% -4.9%
largeJpegUploadProcessing 1432.15 ms +1.47% -1.21% 1435.96 ms +1.6% -1.26% -0.27%
multipleImageUploadProcessing 1586.24 ms +9.9% -1.26% 1579.36 ms +8.15% -0.38% 0.44%

post-editor

Metric ca3af13 trunk % Change
serverResponse 408.45 ms +6.25% -6.06% 409.08 ms +4.43% -10% -0.15%
firstPaint 457.15 ms +13.37% -32.84% 270.16 ms +84.53% -19.35% 69.21%
domContentLoaded 1158.93 ms +2.9% -1.67% 1203.18 ms +1.17% -3.89% -3.68%
loaded 1160.18 ms +2.91% -1.65% 1204.57 ms +1.17% -3.89% -3.69%
firstContentfulPaint 521.6 ms +1.46% -3.4% 527.28 ms +3.97% -3.75% -1.08%
firstBlock 3427.76 ms +0.9% -1.63% 3416.65 ms +1.23% -0.63% 0.33%
type 19.06 ms +6.09% -4.93% 20.18 ms +0.59% -0.99% -5.55%
typeWithoutInspector 18.58 ms +4.04% -4.36% 18.95 ms +3.8% -2.32% -1.95%
typeWithTopToolbar 25.56 ms +7.04% -6.26% 25.83 ms +3.6% -5.73% -1.05%
typeContainer 8.77 ms +12.66% -8.55% 9.54 ms +1.05% -3.46% -8.07%
focus 118.46 ms +4.62% -5.13% 124.74 ms +7.09% -1.31% -5.03%
firstFocus 226.44 ms +0% -0% 246.3 ms +0% -0% -8.06%
selectAll 554.91 ms +3.67% -1.43% 562.13 ms +2.39% -2.24% -1.28%
listViewOpen 73.63 ms +3.41% -1.83% 76.1 ms +6.28% -3.67% -3.25%
inserterOpen 40.33 ms +15.15% -6.15% 42.57 ms +7.12% -11.53% -5.26%
inserterHover 13.39 ms +9.78% -8.74% 13.62 ms +8.66% -11.45% -1.69%
inserterSearch 8.52 ms +7.86% -6.22% 9.01 ms +4.99% -3.77% -5.44%
loadPatterns 628.4 ms +2.12% -4.01% 704.17 ms +5.54% -6.19% -10.76%
wpTotal 396.96 ms +6.06% -6.04% 397.62 ms +4.57% -10.13% -0.17%
wpMemoryUsage 13.29 MB +0% -0% 13.26 MB +0% -0% 0.28%
wpDbQueries 54 +0% -1.85% 54 +0% -1.85% 0%

site-editor

Metric ca3af13 trunk % Change
serverResponse 477.82 ms +2.17% -3.35% 509.9 ms +5.92% -5.06% -6.29%
firstPaint 248.7 ms +11.91% -5.13% 240.31 ms +13.96% -2.47% 3.49%
domContentLoaded 1307.81 ms +1.4% -0.46% 1281.95 ms +1.21% -0.82% 2.02%
loaded 1309.28 ms +1.4% -0.47% 1283.32 ms +1.21% -0.83% 2.02%
firstContentfulPaint 543.89 ms +5.92% -3.99% 537.17 ms +1.1% -0.85% 1.25%
firstBlock 4775.04 ms +0.9% -1.05% 4758.35 ms +0.41% -1% 0.35%
type 19.7 ms +0.86% -3.35% 18.12 ms +3.48% -1.88% 8.72%
navigate 123.4 ms +10.81% -3.35% 133.42 ms +6.38% -6.03% -7.51%
loadPatterns 1360.99 ms +6.17% -4.04% 1374.86 ms +4.83% -6.98% -1.01%
loadPages 1028.01 ms +1.26% -0.73% 1016.47 ms +1.26% -1.36% 1.14%
wpTotal 468.06 ms +2.11% -3.47% 499.75 ms +6.03% -5.12% -6.34%
wpMemoryUsage 12.35 MB +0% -0% 12.32 MB +0% -0% 0.3%
wpDbQueries 43 +2.33% -0% 43 +2.33% -0% 0%

From d342f9c, not the current head. Run

@mirka
mirka marked this pull request as ready for review October 14, 2026 09:03
@mirka
mirka requested a review from a team as a code owner October 14, 2026 09:03

@ciampo ciampo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we leave another comment on the open Base UI issue covering this gap with these form-control cases?

@mirka
mirka enabled auto-merge (squash) October 15, 2026 06:03
@mirka
mirka disabled auto-merge October 15, 2026 06:06
@mirka
mirka requested a review from ciampo October 15, 2026 06:07
@mirka
mirka requested a review from ciampo October 15, 2026 16:13
@mirka

mirka commented Oct 15, 2026

Copy link
Copy Markdown
Member Author

There is so much to work around and we haven't even squashed all the known limitations yet. I really hope this is addressed upstream 😅

@ciampo

ciampo commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

Should we consider opening a PR upstream?

Comment on lines +95 to +104
( event: Event ) => {
const eventTarget = event.target as Node | null;
if (
trigger &&
popup &&
getNodeDocument( eventTarget ) !== popup.ownerDocument &&
! trigger.contains( eventTarget ) &&
! isInsideCurrentPopup( event, trigger )
) {
dispatchOutsidePress( event, popup.ownerDocument );

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

When two popups stay open in different documents, their bridges keep sending events back to each other. Could we mark events created by a bridge so other bridges don't forward them again?

Reproduction and evidence kindly provided by my agent
  1. Render two non-modal Selects with triggers in the parent document and popups portaled into separate same-origin iframes.
  2. Have the first Select cancel close requests through eventDetails.cancel().
  3. Open both Selects through their triggers.
  4. Clear the observation counters, then click a button in a third same-origin iframe.

Chromium reported 43 forwarded pointerdown events, 23 close callbacks for the first Select, and 21 for the second. The probe uses the actual pinned Select components and native browser clicks. These counts were collected without a recursion cutoff.

Disposable probe and failure output.

@jsnajdr

jsnajdr commented Oct 19, 2026

Copy link
Copy Markdown
Member

This PR, as well as the existing useIframeDismissalBridge, attempts an universal solution that works for all possible cases, without any limitations, and is automated: you don't need to setup anything extra, the hooks setup the iframe mutation observers and all the event handlers automatically.

What if we did something more minimal: the essence of the patch is that we listen for events inside the iframe document, and forward them to the outer iframe element. Let's take the one offending iframe, the editor canvas, and setup the forwarding there. Manually, outside the ui library, inside the <Iframe> component. How big part of the problem does that solve?

Does it cause any new issues? If we indiscriminately forward the needed events (pointerdown, click, ...) and there is a popup inside the iframe, the clicking inside the popup will cause also a click event outside the popup, and may self-close it. Is that a real issue? Does it happen in practice?

@jsnajdr

jsnajdr commented Oct 21, 2026

Copy link
Copy Markdown
Member

Let's take the one offending iframe, the editor canvas, and setup the forwarding there.

Implemented the idea here: #85263. Let's see if it really works.

@mirka

mirka commented Oct 23, 2026

Copy link
Copy Markdown
Member Author

Closing in favor of #85263

@mirka mirka closed this Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] UI /packages/ui [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants