Repository navigation
fix: forward close/error reason to channels in triggerChanError - #29
Merged
Merged
Conversation
5 of 6 tasks
filipecabaco
approved these changes
Apr 28, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What kind of change does this PR introduce?
Bug fix.
What is the current behavior?
When a transport-level failure occurs (socket close, heartbeat timeout, connection error),
Socket.triggerChanError()callschannel.trigger(CHANNEL_EVENTS.error)with no payload. As a result, everyChannel.onError(callback)listener receivesreason === undefined, even though the calling sites (onConnClose(event),onConnError(error),heartbeatTimeout()) all have the underlying close or error event in scope.This bubbles all the way up to consumers. In
@supabase/realtime-js, the user'schannel.subscribe((status, err) => ...)callback fires withstatus === 'CHANNEL_ERROR'anderr === undefined, so applications cannot distinguish between a heartbeat timeout, an abnormal websocket close, an invalid JWT, or a network error. See supabase/supabase-js#1734 for the user-facing report.What is the new behavior?
triggerChanErrornow accepts an optionalreasonand forwards it as the payload tochannel.trigger(CHANNEL_EVENTS.error, reason). The three callers pass what they already have:onConnClose(event)forwards theCloseEventonConnError(error)forwards the transportEventheartbeatTimeout()synthesizesnew Error("heartbeat timeout")since no DOM event is in scopeChannel.trigger(event, payload, ref, joinRef)already accepts a payload, so no signature change is needed inchannel.js. ExistingonError(callback => ...)listeners that ignore the argument keep working unchanged; listeners that look at the argument now get a meaningful value instead ofundefined.Additional context
Channel.onErrorlisteners receive a real reason instead ofundefined. Consumers that previously did nothing with the argument are unaffected.@supabase/realtime-jsadds a normalizer that mapsError | CloseEvent | Event | string | undefinedto a realErrorwithcause, so end users see messages like"socket closed: 1006 (Network Failure)"and can still inspect the raw event.socket_test.jsassertions for the existingonConnClose/onConnErrorcases to verify the close/error event is forwarded as the second argument tophx_error.heartbeatCallbackdescribe block asserting thatheartbeatTimeout()triggersphx_errorwith anError("heartbeat timeout")payload.npx jest, 208 tests).priv/static/are not committed here; theassets.ymlworkflow rebuilds them fromassets/js/phoenix/*on merge.