Skip to content

feat(realtime): Realtime deferred disconnect - #2270

Merged
grdsdev merged 4 commits into
developfrom
feat/realtime-deferred-disconnect
Apr 23, 2026
Merged

grdsdev merged 4 commits into
developfrom
feat/realtime-deferred-disconnect

Conversation

@edgurgel

Copy link
Copy Markdown
Member

🔍 Description

What changed?

  • Adds a disconnectOnEmptyChannelsAfterMs option to RealtimeClientOptions that delays the WebSocket disconnect after the last channel is removed
  • Defaults to 2 × heartbeatIntervalMs — giving a window to reuse the existing connection when switching channels without a reconnect penalty
  • Cancels the pending disconnect if a new channel is created before the timer fires
  • removeAllChannels() continues to disconnect immediately (explicit teardown intent)

Why was this change needed?

WebSockets could be left open wasting resources (both on client and server side) even when all channels have been removed

📸 Screenshots/Examples

🔄 Breaking changes

  • This PR contains no breaking changes

📋 Checklist

  • I have read the Contributing Guidelines
  • My PR title follows the conventional commit format: <type>(<scope>): <description>
  • I have run npx nx format to ensure consistent code formatting
  • I have added tests for new functionality (if applicable)
  • I have updated documentation (if applicable)

@edgurgel
edgurgel requested review from a team as code owners April 23, 2026 01:16
@github-actions github-actions Bot added the realtime-js Related to the realtime-js library. label Apr 23, 2026
@pkg-pr-new

pkg-pr-new Bot commented Apr 23, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@supabase/auth-js

npm i https://pkg.pr.new/@supabase/auth-js@2270

@supabase/functions-js

npm i https://pkg.pr.new/@supabase/functions-js@2270

@supabase/postgrest-js

npm i https://pkg.pr.new/@supabase/postgrest-js@2270

@supabase/realtime-js

npm i https://pkg.pr.new/@supabase/realtime-js@2270

@supabase/storage-js

npm i https://pkg.pr.new/@supabase/storage-js@2270

@supabase/supabase-js

npm i https://pkg.pr.new/@supabase/supabase-js@2270

commit: f80b563

@grdsdev
grdsdev merged commit 4c1efa5 into develop Apr 23, 2026
24 checks passed
@grdsdev
grdsdev deleted the feat/realtime-deferred-disconnect branch April 23, 2026 08:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

realtime-js Related to the realtime-js library.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants