Skip to content

fix(external-api): prevent unload listener accumulation on SET_CONFIG#17246

Open
codewithabhay10 wants to merge 1 commit intojitsi:masterfrom
codewithabhay10:fix/unload-listener-leak
Open

fix(external-api): prevent unload listener accumulation on SET_CONFIG#17246
codewithabhay10 wants to merge 1 commit intojitsi:masterfrom
codewithabhay10:fix/unload-listener-leak

Conversation

@codewithabhay10
Copy link
Copy Markdown

Motivation and Context

Fixes #17245

Currently, the SET_CONFIG middleware in the External API registers an anonymous unload (or beforeunload) event listener every time it is dispatched:
https://github.com/jitsi/jitsi-meet/blob/master/react/features/external-api/middleware.ts#L244

Because the handler is an anonymous function, the listeners accumulate over the lifecycle of a long-lived session if SET_CONFIG is updated multiple times, leading to redundant notifyConferenceLeft and dispose() calls on window unload.

Description

This PR resolves the issue by hoisting the unload handler into module-level variables (_location and _unloadHandler).
Before registering a new listener during the SET_CONFIG dispatch, any previously registered listener is removed using window.removeEventListener(). This ensures that exactly one unload listener exists at any given time.

Testing Performed

  • Validated that dispatching SET_CONFIG no longer creates orphaned unload event listeners on the window object.
  • Validated that when the page unloads, notifyConferenceLeft() and dispose() are gracefully executed exactly once.

@jitsi-jenkins
Copy link
Copy Markdown

Hi, thanks for your contribution!
If you haven't already done so, could you please make sure you sign our CLA (https://jitsi.org/icla for individuals and https://jitsi.org/ccla for corporations)? We would unfortunately be unable to merge your patch unless we have that piece :(.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants