You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(server): encode undefined subscription values in SSE stream - #8146
Producer writes an empty data: line instead of the literal text undefined when a chunk serializes to undefined.
Consumer reads an empty data: line back as undefined instead of calling JSON.parse('').
No change for transformer users: superjson already encodes undefined.
Links
None
Alternatives considered
Skipping undefined yields: drops values the subscriber expects.
Testing
Regression check: packages/tests/server/regression/issue-8143-sse-undefined-yield.test.ts fails without this change ("undefined" is not valid JSON) and passes with it.
AI model
Muse Spark
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.
Summary by CodeRabbit
Bug Fixes
Server-sent event subscriptions now correctly transmit undefined values, preserving the order of streamed results and allowing subscriptions to complete without errors.
A subscription yielding `undefined` over httpSubscriptionLink stalled:
the producer wrote the literal text `data: undefined` and the client
threw parsing it. Write an empty `data:` line instead and read it
back as `undefined`.
Closestrpc#8143
No actionable comments were generated in the recent review.
Walkthrough
The SSE producer encodes undefined as an empty payload. The consumer maps empty message payloads to undefined and continues to parse and deserialize nonempty payloads. A regression test checks delivery of 1, undefined, and 3.
Changes: SSE undefined value handling
Layer / File(s)
Summary
SSE undefined value round trip packages/server/src/unstable-core-do-not-import/stream/sse.ts, packages/tests/server/regression/issue-8143-sse-undefined-yield.test.ts
The producer converts serialized undefined to an empty payload. The consumer maps empty message payloads to undefined and continues to parse and deserialize nonempty payloads. The regression test checks ordered data delivery, no error callback, and exactly one completion or error callback.
This fixes subscriptions over httpSubscriptionLink without a transformer so that a yielded undefined is delivered as undefined and the stream continues. The change is small, covered by a regression test, and no merge-blocking risk remains.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title "fix(server): encode undefined subscription values in SSE stream" matches the main change. The raw summary says sseStreamProducer now encodes serialized undefined values as an empty string…
Linked Issues check
[#8143] Objective: a subscription that yields undefined over httpSubscriptionLink (SSE, no transformer) must deliver onData(undefined) and keep the stream open. I read `packages/server/src/unsta…
Out of Scope Changes check
The whole-PR diff against merge base 0813ceb changes sse.ts and adds the regression test packages/tests/server/regression/issue-8143-sse-undefined-yield.test.ts. The sse.ts changes are limited t…
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check
Explanation
The title "fix(server): encode undefined subscription values in SSE stream" matches the main change. The raw summary says sseStreamProducer now encodes serialized undefined values as an empty string, and the consumer reads an empty payload as undefined without JSON.parse. The added regression test for issue #8143 covers the same behavior. The title is specific and describes the primary fix.
Full details: Linked Issues check
Explanation
[#8143] Objective: a subscription that yields undefined over httpSubscriptionLink (SSE, no transformer) must deliver onData(undefined) and keep the stream open. I read packages/server/src/unstable-core-do-not-import/stream/sse.ts at the reviewed head d04e797. The producer writes JSON.stringify(serialize(chunk.data)) ?? '', so an undefined value produces an empty data: line instead of data: undefined. The consumer's 'message' listener maps msg.data === '' to undefined and skips JSON.parse, then enqueues a data result. Non-empty payloads still go through deserialize(JSON.parse(...)). The restore-id and return events use other event names and are not affected by the 'message' listener. The empty string cannot collide with real output, because JSON.stringify('') returns "". The change since the previous reviewed head (ce58908) affects the regression test, per the commit message 'test: fail with the parse error instead of a timeout'. The incremental diff could not be read because changed blobs are missing from the checkout. The test source was not read. The test summary states it waits for one completion or error callback and asserts no error and ordered delivery of 1, undefined, and 3, which matches the objective. The source code path the objective depends on is unchanged from the prior assessment at the head. The accepted tradeoff (old client with new server still fails) is listed in the issue as a known option.
Full details: Out of Scope Changes check
Explanation
The whole-PR diff against merge base 0813ceb changes sse.ts and adds the regression test packages/tests/server/regression/issue-8143-sse-undefined-yield.test.ts. The sse.ts changes are limited to the producer encoding line and the consumer empty-payload branch, both of which implement #8143. The test exercises the same behavior. The latest commit changes only the test's failure reporting, which supports the same objective. No unrelated files or refactors appear in the supplied summaries. The incremental diff could not be read, so the test-only change since the previous review is assessed from its commit message and the test summary.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Fix failing CI checks
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
This pull request has been locked because we are very unlikely to see comments on closed issues. If you think, this PR is still necessary, create a new one with the same branch. Thank you.
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
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.
Why
undefinedoverhttpSubscriptionLinkerrors: the server writesdata: undefined, and the client throws parsing it.undefinedends with "undefined is not valid JSON" over httpSubscriptionLink (SSE) #8143What
data:line instead of the literal textundefinedwhen a chunk serializes toundefined.data:line back asundefinedinstead of callingJSON.parse('').undefined.Links
None
Alternatives considered
undefinedyields: drops values the subscriber expects.Testing
packages/tests/server/regression/issue-8143-sse-undefined-yield.test.tsfails without this change ("undefined" is not valid JSON) and passes with it.AI model
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.Summary by CodeRabbit
undefinedvalues, preserving the order of streamed results and allowing subscriptions to complete without errors.