chore: sync upstream PR #8653 - fix(core): release native plugin listeners on remove and removeAllLis…
Merged
RI
10d ago+206+206+012345678901234567890123456789-30-30-01234567890123456789
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, andfinally(ionic-team/capacitor#8472 style adoption paths), and nativeaddListenerfailures reject the promise returned to JS instead of hanging.
Why
- Upstream 8653 fixes listener retention and event forwarding after removal.
- Short circuiting only
thenleftcatchandfinallycallable so promise adoption could still misbehave; restoring all three matches the safer pattern. - Wrapping
addListenerinnew 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
gettrap:then,catchandfinallyreturn undefined, with a comment on promise adoption. addListenerNative: usecall.then(() => ({ remove }))so rejections propagate.
Testing
cd core && npm test(63 passed), including new tests thatthen,catch,finallyare undefined and that a nativeaddListenerrejection 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
undefinedforthen,catch, andfinally, avoiding unintended promise-like behavior.
- Tests
- Added coverage for plugin proxy behavior, listener registration and removal, native event delivery, and listener cleanup.