Skip to content

fix: use the JSON message replacer for automatic pongs - #703

Merged
enisdenjo merged 1 commit into
enisdenjo:masterfrom
lprnmns:fix/pong-json-message-replacer
Oct 15, 2026
Merged

enisdenjo merged 1 commit into
enisdenjo:masterfrom
lprnmns:fix/pong-json-message-replacer

Conversation

@lprnmns

@lprnmns lprnmns commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

Both the client and the server answer a ping with a pong that echoes the ping's payload, but that pong is the only message they serialize without jsonMessageReplacer. Every other message (connection_init, connection_ack, subscribe, next, error, complete) already passes it.

This matters when the reviver and replacer are a pair. For example, with a reviver that turns a field into a BigInt and a replacer that turns it back into a string, the revived ping payload can't be serialized for the pong: JSON.stringify throws "Do not know how to serialize a BigInt", and the connection gets closed.

The fix passes replacer to stringifyMessage for the automatic pong in src/server.ts and src/client.ts.

Tests: one new test in tests/server.test.ts and one in tests/client.test.ts, each sending a ping with a payload that the reviver turns into a BigInt. Both fail on master (the server test gets no pong, and the client closes the socket) and pass with this change. The full suite, tsc --noEmit and Prettier pass. A patch changeset is included.

@enisdenjo enisdenjo left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙏

@enisdenjo
enisdenjo merged commit 707c38c into enisdenjo:master Oct 15, 2026
19 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