Skip to content

fix unmount race in refresher - #31316

Open
ptmkenny wants to merge 1 commit into
ionic-team:mainfrom
ptmkenny:refresher
Open

fix unmount race in refresher#31316
ptmkenny wants to merge 1 commit into
ionic-team:mainfrom
ptmkenny:refresher

Conversation

@ptmkenny

@ptmkenny ptmkenny commented Aug 1, 2026

Copy link
Copy Markdown

Issue number: resolves #31315

What is the current behavior?

When an ion-refresher's host page is unmounted while the native refresher is still being set up, Ionic throws an uncaught TypeError from the gesture utility:

TypeError: Cannot read properties of undefined (reading '__zone_symbol__addEventListener')
    at addEventListener (core/src/utils/gesture/listener.ts:21)
    at Object.enable (core/src/utils/gesture/index.ts)
    at Refresher.disabledChanged (core/src/components/refresher/refresher.tsx:125)
    at Refresher.setupMDNativeRefresher (core/src/components/refresher/refresher.tsx:372)

setupMDNativeRefresher() and setupiOSNativeRefresher() both do:

this.gesture = (await import('../../utils/gesture')).createGesture({
  el: this.scrollEl!,
  ...
});

The dynamic import yields to the event loop. If the refresher is disconnected while it resolves, disconnectedCallback() (line 547-549) has already run this.scrollEl = undefined, so createGesture receives el: undefined, and the subsequent disabledChanged()gesture.enable(true) calls addEventListener(undefined, ...), which throws.

Because this happens inside an async method that nothing awaits, it surfaces as an unhandled promise rejection — it cannot be caught by a framework error boundary; this crashes my app in playwright sometimes when components are mounted very quickly.

The ! non-null assertions on this.scrollEl are what hide this from TypeScript.

What is the new behavior?

If the refresher is disconnected while the gesture module is being imported, setup aborts quietly. No gesture is created, and no error is thrown.

Does this introduce a breaking change?

  • Yes
  • [ X] No

Other information

@ptmkenny
ptmkenny requested a review from a team as a code owner August 1, 2026 00:36
@ptmkenny
ptmkenny requested a review from ShaneK August 1, 2026 00:36
@vercel

vercel Bot commented Aug 1, 2026

Copy link
Copy Markdown

@ptmkenny is attempting to deploy a commit to the Ionic Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added the package: core @ionic/core package label Aug 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package: core @ionic/core package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: ion-refresher throws when its page unmounts during native refresher setup

1 participant