ptmkenny ยท GitHub

Prerequisites

Ionic Framework Version

v8.x

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.

Expected Behavior

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

Steps to Reproduce

See the code reproduction README.md.

Code Reproduction URL

https://github.com/ptmkenny/ionic-react-router-6-test/tree/refresher

Ionic Info

 Ionic:
     Ionic CLI       : 7.2.1
     Ionic Framework : @ionic/react 8.7.12-dev.11765219790.17cbe2e9
  Capacitor:
     Capacitor CLI      : 8.0.0
     @capacitor/android : not installed
     @capacitor/core    : 8.0.0
     @capacitor/ios     : not installed
  Utility:
     cordova-res : not installed globally
     native-run  : 2.0.1
  System:
     NodeJS : v24.18.1
     npm    : 11.16.0
     OS     : Linux 6.18

Additional Information

No response

Read the original on github.com โ†—