supabase-js icon indicating copy to clipboard operation
supabase-js copied to clipboard

fix(auth): add dispose method to cleanup BroadcastChannel

Open 7ttp opened this issue 1 month ago • 1 comments

Summary

Adds a dispose() method to GoTrueClient to properly clean up the BroadcastChannel event listener and close the channel.

Problem

In GoTrueClient, a BroadcastChannel is created with an event listener in the constructor, but there's no way to remove the listener or close the channel. The cleanup pattern exists for visibilityChangedCallback (via _removeVisibilityChangedCallback()) but was missed for BroadcastChannel.

Location: packages/core/auth-js/src/GoTrueClient.ts (~line 398)

Solution

  • Store callback reference in broadcastChannelCallback property
  • Add private _removeBroadcastChannel() method (matches existing pattern)
  • Add public dispose() method for full resource cleanup

Changes

  • GoTrueClient.ts: Added broadcastChannelCallback property, _removeBroadcastChannel(), and dispose() methods
  • GoTrueClient.browser.test.ts: Added test for dispose cleanup

Related

Closes #2020

7ttp avatar Jan 14 '26 17:01 7ttp

Coverage Status

coverage: 81.023% (+0.03%) from 80.997% when pulling 9bf0ecd63246ab4fb517deb30a1bcdafaceafa0b on 7ttp:fix/auth-broadcastchannel-cleanup into 09aa10628b00cbdf65ace0f9e8e79237e7c0c1dc on supabase:master.

coveralls avatar Jan 14 '26 17:01 coveralls

@mandarini

7ttp avatar Jan 26 '26 14:01 7ttp

Hi @7ttp ! Thank you for the PR! I discussed it with the auth team and we decided that we will not be merging this PR. We do not see the reason why this needs cleaning. The general opinion is that it doesn’t solve a real problem, but in fact it may create more because someone will try to use it properly, fail, and then be “why isn’t X working”.

Thank you for contributing though! 💚

mandarini avatar Jan 26 '26 14:01 mandarini