Skip to content

[Bug] External API middleware leaks unload event listeners on every SET_CONFIG #17245

@codewithabhay10

Description

@codewithabhay10

What happened?

Description

In react/features/external-api/middleware.ts, the SET_CONFIG handler registers an anonymous arrow function for the unload (or beforeunload) event:
https://github.com/jitsi/jitsi-meet/blob/master/react/features/external-api/middleware.ts#L247

Every time SET_CONFIG is dispatched (such as during iframe embeds or long-lived SPA sessions that update config dynamically), a brand new, anonymous event listener is bound to the window.

Because it's an anonymous function without a stable reference, these listeners accumulate and are never deduplicated or removed.

Impact

When the window is eventually closed or unloaded, this triggers duplicate side effects for each accumulated listener:

  • notifyConferenceLeft is fired redundantly.
  • APP.API.dispose() and getJitsiMeetTransport().dispose() are called multiple times unnecessarily.

Proposed Solution

Hoist the event handler and event name to module-scoped variables. Within the SET_CONFIG case, check if the previous listener exists and remove it via window.removeEventListener() before registering the new one.

I am opening a PR with the fix shortly.

Platform

  • Chrome (or Chromium based)
  • Firefox
  • Safari
  • Other desktop browser
  • Android browser
  • iOS browser
  • Electron app
  • Android mobile app
  • iOS mobile app
  • Custom app using a mobile SDK

Browser / app / sdk version

Latest (master / meet.jit.si)

Relevant log output

There are no direct crash logs. However, if using the iFrame API or a long-lived session where SET_CONFIG is updated, checking `getEventListeners(window).unload` in the devtools console will show multiple anonymous listeners accumulating. Upon closing the window, the Network Tab will show duplicate requests for `notifyConferenceLeft`.

Reproducibility

  • The problem is reproducible on meet.jit.si

More details?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions