Repository navigation
Conversation
|
@Ultranmus is attempting to deploy a commit to the Ionic Team on Vercel. A member of the Team first needs to authorize it. |
3 tasks done
thetaPC
requested changes
Dec 3, 2026
thetaPC
left a comment
Contributor
There was a problem hiding this comment.
Thanks for the fix!
The approach matches what ion-modal does, and checking isConnected alone is an improvement: unlike the modal, the popover stays open when its parent is only moved. A couple of changes below, the first one for nested popovers.
| this.parentRemovalObserver = new MutationObserver(() => { | ||
| if (!cachedOriginalParent.isConnected) { | ||
| this.cleanupParentRemovalObserver(); | ||
| this.dismiss(undefined, 'parent-removed'); |
Contributor
There was a problem hiding this comment.
- Leaving
dismissParentPopoverat its default makes removing a submenu's container also close the parent popover, with roleparent-removed, even though the parent's own container is still there. That's a regression for nested menus. - Every other automatic dismiss of a single nested popover passes
false, such as the parent'sionPopoverWillDismisslistener and the hover and ArrowLeft handlers inutils.ts. - Could you add a nested case to the test too: open a submenu, remove the element it's declared in, and check that the parent stays open?
Suggested change
| this.dismiss(undefined, 'parent-removed'); | |
| this.dismiss(undefined, 'parent-removed', false); |
| expect(dismissEvent.detail.role).toBe('parent-removed'); | ||
| await expect(popover).toBeHidden(); | ||
| await expect(page.locator('body')).not.toHaveClass(/backdrop-no-scroll/); | ||
| }); |
Contributor
There was a problem hiding this comment.
- Moving an open popover runs
disconnectedCallback, which tears down the observer, so only the newinitParentRemovalObserver()call inconnectedCallbackbrings it back. The test above never moves the popover, so it still passes if that call is removed. - Modal covers this case with "it should still dismiss on parent removal after the modal was moved" in
modal/test/inline/modal.e2e.ts.
Suggested change
| }); | |
| }); | |
| test('should still dismiss on parent removal after the popover was moved', async ({ page }) => { | |
| await page.setContent( | |
| ` | |
| <ion-app> | |
| <div id="container"> | |
| <button id="trigger">Open</button> | |
| <ion-popover trigger="trigger"> | |
| <ion-content>Popover content</ion-content> | |
| </ion-popover> | |
| </div> | |
| </ion-app> | |
| `, | |
| config | |
| ); | |
| const ionPopoverDidPresent = await page.spyOnEvent('ionPopoverDidPresent'); | |
| const ionPopoverDidDismiss = await page.spyOnEvent('ionPopoverDidDismiss'); | |
| const popover = page.locator('ion-popover'); | |
| await page.click('#trigger'); | |
| await ionPopoverDidPresent.next(); | |
| await detachAndReattach(popover); | |
| await page.locator('#container').evaluate((el: HTMLElement) => el.remove()); | |
| const dismissEvent = await ionPopoverDidDismiss.next(); | |
| expect(dismissEvent.detail.role).toBe('parent-removed'); | |
| await expect(popover).toBeHidden(); | |
| }); |
The import at the top of the file also needs detachAndReattach:
import { configs, detachAndReattach, test } from '@utils/test/playwright';
Comment on lines
+649
to
+653
| // Inline popovers are moved to the app root on present, so watch the original parent instead. | ||
| private initParentRemovalObserver() { | ||
| const { cachedOriginalParent } = this; | ||
|
|
||
| if ( |
Contributor
There was a problem hiding this comment.
- The comment says the method watches the original parent, but it observes
document.body. An observer on the parent never fires when the parent itself is removed, so someone trusting the comment could switch toobserve(cachedOriginalParent)and break the dismiss. - The guard skips controller popovers and
bodyorion-appparents for performance, not validity: a subtree observer onbodyhung Angular apps when this ran for controller modals. Without the reason, a later cleanup could drop those clauses.
Suggested change
| // Inline popovers are moved to the app root on present, so watch the original parent instead. | |
| private initParentRemovalObserver() { | |
| const { cachedOriginalParent } = this; | |
| if ( | |
| /** | |
| * Inline popovers are moved to the app root on present, so removing the | |
| * element they were declared in does not disconnect them. The observer | |
| * watches the body, since an observer on the parent never fires when the | |
| * parent itself is removed. | |
| */ | |
| private initParentRemovalObserver() { | |
| const { cachedOriginalParent } = this; | |
| // Controller popovers and app-root parents are never removed, and a | |
| // subtree observer on the body slows Angular change detection. | |
| if ( |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue number: resolves #31858
What is the current behavior?
An inline
ion-popoveris moved to the app root while it's presented. If the element it was declared in gets removed (an@ifturning false, for example), the popover stays open over the page, with its backdrop andbackdrop-no-scrollonbody, until the user taps the backdrop.What is the new behavior?
parent-removedrole when that parent is removed. This is the same thingion-modaldoes since fix(modal): dismiss modal when parent element is removed from DOM #30544.present()and again if the presented popover is moved, and is cleaned up on dismiss and disconnect.bodyorion-appare skipped, as in modal.Does this introduce a breaking change?
Other information
Added an e2e test in
popover/test/inlinethat opens a popover, removes its container and checks it's dismissed with the right role and thatbodyno longer hasbackdrop-no-scroll. It fails without the change. The popover, modal, select and datetime-button e2e suites pass locally on Mobile Chrome, along with the popover spec tests and lint.