Skip to content

Pass close code and reason to WebSocket close event#14

Merged
dimdenGD merged 1 commit intodimdenGD:mainfrom
MayCXC:fix-close-event-args
Apr 1, 2026
Merged

Pass close code and reason to WebSocket close event#14
dimdenGD merged 1 commit intodimdenGD:mainfrom
MayCXC:fix-close-event-args

Conversation

@MayCXC
Copy link
Copy Markdown
Contributor

@MayCXC MayCXC commented Apr 1, 2026

The uWebSockets.js close callback provides (ws, code, message) but the server-side close handler discards code and message, emitting the close event with no arguments.

This breaks libraries that listen for ws-compatible close events with (code, reason) parameters. For example, Hocuspocus v3 calls reason.toString() in its handleWebsocketClose handler, which throws TypeError: Cannot read properties of undefined (reading 'toString') when reason is not provided.

The fix passes code and Buffer.from(message) through to the emitted close event, matching the ws library's behavior.

The uWebSockets.js close callback provides (ws, code, message) but
the server-side close handler discarded code and message, emitting
the close event with no arguments. This breaks libraries that expect
ws-compatible close events with (code, reason) parameters, such as
Hocuspocus which calls reason.toString() on the close reason.
@dimdenGD dimdenGD merged commit dac4a0f into dimdenGD:main Apr 1, 2026
4 checks passed
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.

2 participants