Skip to content

bug(adapters): Battery API listeners can survive disposal #379

Description

@vamgan

Summary

Battery API listeners can survive component disposal, and Angular's battery service never removes its listeners.

Evidence

React, Vue, Svelte, and Solid attach listeners after asynchronous navigator.getBattery() resolution without consistently guarding against unmount before the promise settles. Angular attaches anonymous listener functions and cannot remove them during unregister()/ngOnDestroy(); repeated initialization accumulates listeners.

Affected implementations include each adapter's useAskableBatterySource and Angular's askable-battery-source.service.ts.

Proposed fix

  • Track disposal/generation around asynchronous battery initialization.
  • Do not update or attach if resolution occurs after disposal.
  • Keep stable named listener references.
  • Remove every listener and clear retained battery state during cleanup.

Acceptance criteria

  • Resolving getBattery() after unmount attaches no listeners and performs no state update
  • Repeated mount/unmount cycles return listener count to zero
  • Repeated Angular init/unregister does not accumulate callbacks
  • Only the newest async initialization remains active
  • Parity tests cover React, Vue, Svelte, Solid, and Angular

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions