Skip to content

fix(react): bind events properly for overlays rendered within a nav#31159

Merged
ShaneK merged 1 commit into
mainfrom
FW-6314
May 20, 2026
Merged

fix(react): bind events properly for overlays rendered within a nav#31159
ShaneK merged 1 commit into
mainfrom
FW-6314

Conversation

@ShaneK

@ShaneK ShaneK commented May 20, 2026

Copy link
Copy Markdown
Member

Issue number: resolves #27843


What is the current behavior?

createInlineOverlayComponent renders inline overlays (modal, popover, etc.) inside a <template> at their declared JSX position. When the overlay presents, CoreDelegate teleports the DOM node into ion-app, but React's synthetic event delegation root stays at the original JSX parent. Once the overlay lives outside that subtree, React no longer dispatches events to children inside it, so onClick, onChange, and other handlers inside an IonModal rendered within an IonNav silently stop firing

What is the new behavior?

Top-level inline overlays now render through createPortal into the same ion-app container that CoreDelegate teleports into, so React's event root follows the DOM

Does this introduce a breaking change?

  • Yes
  • No

Other information

This issue also reports the same problem in Vue, but that was fixed in #30227

Preview: navigation-modal

Dev build:

8.8.8-dev.11779302602.17decfbf

@ShaneK ShaneK requested a review from a team as a code owner May 20, 2026 18:15
@ShaneK ShaneK requested a review from OS-jacobbell May 20, 2026 18:15
@vercel

vercel Bot commented May 20, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
ionic-framework Ready Ready Preview, Comment May 20, 2026 6:26pm

Request Review

@github-actions github-actions Bot added the package: react @ionic/react package label May 20, 2026

@brandyscarney brandyscarney left a comment

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.

Nice fix! 👍

@ShaneK ShaneK added this pull request to the merge queue May 20, 2026
@brandyscarney brandyscarney removed this pull request from the merge queue due to a manual request May 20, 2026
@ShaneK ShaneK changed the title fix(react): portal inline overlays so React events reach children after teleport fix(react): bind events properly for overlays rendered within a nav May 20, 2026
@ShaneK ShaneK added this pull request to the merge queue May 20, 2026
Merged via the queue into main with commit fa4593d May 20, 2026
65 checks passed
@ShaneK ShaneK deleted the FW-6314 branch May 20, 2026 20:20
pull Bot pushed a commit to goldtoad6/ionic-framework that referenced this pull request Jun 17, 2026
…ic-team#31223)

Issue number: internal

---------

## What is the current behavior?

Currently, when an inline overlay (`ion-modal`, `ion-popover`) is
rendered through React and `CoreDelegate` teleports its host out of the
React-rendered location, unmounting the component can leave the host
orphaned in the DOM. `componentWillUnmount` only recovered a relocated
host when `this.state.isOpen` was `true`, so a host that was moved while
still closed was never reattached for React to remove. That happens
during the React 18 StrictMode mount/unmount cycle, or any re-render
before the present events flip `isOpen`. The result is duplicate
`<ion-modal>` elements stacking up in `document.body`. This came from
the portal change in ionic-team#31159

## What is the new behavior?

This splits the unmount cleanup into two independent steps. The DOM
recovery now runs whenever the host is still connected and has been
relocated, regardless of open state: portaled overlays get reattached to
`portalTarget` so React's `removeChild` can find them, and nested
overlays moved out of their `<template>` are removed directly. The
dismiss-lifecycle teardown, detaching the `didDismiss` listener and
props, stays gated on `isOpen` as before. So a relocated-but-closed host
is now cleaned up instead of orphaned.

## Does this introduce a breaking change?

- [ ] Yes
- [X] No

## Other information
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package: react @ionic/react package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: react/vue, rendering modal within nav does not bind events

2 participants