chore: sync upstream PR #8653 - fix(core): release native plugin listeners on remove and removeAllLis…

Merged
RI
10d ago
+206-30

What

  • Sync of upstream PR ionic-team/capacitor#8653: listener release so removing a listener stops native forwards and removeAllListeners clears the same path, plus tests for GC and bridge behavior.
  • Core runtime follow ups on this branch: plugin proxy stays non thenable by returning undefined for then, catch, and finally (ionic-team/capacitor#8472 style adoption paths), and native addListener failures reject the promise returned to JS instead of hanging.

Why

  • Upstream 8653 fixes listener retention and event forwarding after removal.
  • Short circuiting only then left catch and finally callable so promise adoption could still misbehave; restoring all three matches the safer pattern.
  • Wrapping addListener in new Promise((resolve) => call.then(...)) dropped rejections; callers waited forever on native failure.

How

  • Forwarder indirection for native listeners, detach on remove, clear callbacks on removeAllListeners (from upstream 8653).
  • Proxy get trap: then, catch and finally return undefined, with a comment on promise adoption.
  • addListenerNative: use call.then(() => ({ remove })) so rejections propagate.

Testing

  • cd core && npm test (63 passed), including new tests that then, catch, finally are undefined and that a native addListener rejection rejects the returned promise.
  • eslint and prettier clean on the changed files.

Summary by CodeRabbit

  • Bug Fixes
    • Removing an event listener now prevents it from receiving later native events. Removing all listeners also stops their callbacks from receiving further events.
    • Removed listeners are no longer retained unnecessarily, and native listener removal uses the expected callback identifier.
    • Plugin proxies return undefined for then, catch, and finally, avoiding unintended promise-like behavior.
  • Tests
    • Added coverage for plugin proxy behavior, listener registration and removal, native event delivery, and listener cleanup.