Skip to content

fix(standard-server): make event iterator encoder/decoder SSE spec compliant - #1742

Merged
dinwwwh merged 1 commit into
1.xfrom
claude/event-stream-encoder-decoder-70c950
Jul 29, 2026
Merged

fix(standard-server): make event iterator encoder/decoder SSE spec compliant#1742
dinwwwh merged 1 commit into
1.xfrom
claude/event-stream-encoder-decoder-70c950

Conversation

@dinwwwh

@dinwwwh dinwwwh commented Jul 28, 2026

Copy link
Copy Markdown
Member

Summary

Applies the event stream encoder/decoder from the standardserver repo to @orpc/standard-server's event-iterator.

What this fixes

  • Streams using CR or CRLF line endings now decode correctly per the SSE spec, including messages and delimiters split at any chunk boundary.
  • Data containing \r or \r\n now encodes to valid SSE output.
  • Decoding large or finely-chunked streams is faster.

Compatibility

No breaking changes: all exported names, signatures, and shapes are unchanged. The only observable differences are the spec fixes above and the assertion error messages now mentioning carriage returns.

…mpliant

Port the event stream encoder/decoder logic from the standardserver repo:

- Decoder recognizes LF, CR, and CRLF line endings and message delimiters,
  including delimiters split across chunk boundaries
- Decoder strips only a single U+0020 space after the colon per spec
  (previously any single whitespace character, e.g. tabs)
- Decoder buffers chunks in an array joined lazily and only re-scans the
  last 3 characters for delimiters straddling a boundary
- Encoder splits data on \r and \r\n in addition to \n
- Encoder assertions reject carriage returns in id/event/comment,
  preventing field injection into the stream

No public API changes: all exported names, signatures, and the
EventMessage shape are unchanged.
@vercel

vercel Bot commented Jul 28, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
orpc Ready Ready Preview, Comment Jul 28, 2026 2:04pm

@pkg-pr-new

pkg-pr-new Bot commented Jul 28, 2026

Copy link
Copy Markdown
More templates

@orpc/ai-sdk

npm i https://pkg.pr.new/@orpc/ai-sdk@1742

@orpc/arktype

npm i https://pkg.pr.new/@orpc/arktype@1742

@orpc/client

npm i https://pkg.pr.new/@orpc/client@1742

@orpc/contract

npm i https://pkg.pr.new/@orpc/contract@1742

@orpc/experimental-durable-iterator

npm i https://pkg.pr.new/@orpc/experimental-durable-iterator@1742

@orpc/hey-api

npm i https://pkg.pr.new/@orpc/hey-api@1742

@orpc/interop

npm i https://pkg.pr.new/@orpc/interop@1742

@orpc/json-schema

npm i https://pkg.pr.new/@orpc/json-schema@1742

@orpc/nest

npm i https://pkg.pr.new/@orpc/nest@1742

@orpc/openapi

npm i https://pkg.pr.new/@orpc/openapi@1742

@orpc/openapi-client

npm i https://pkg.pr.new/@orpc/openapi-client@1742

@orpc/otel

npm i https://pkg.pr.new/@orpc/otel@1742

@orpc/experimental-pino

npm i https://pkg.pr.new/@orpc/experimental-pino@1742

@orpc/experimental-publisher

npm i https://pkg.pr.new/@orpc/experimental-publisher@1742

@orpc/experimental-publisher-durable-object

npm i https://pkg.pr.new/@orpc/experimental-publisher-durable-object@1742

@orpc/experimental-ratelimit

npm i https://pkg.pr.new/@orpc/experimental-ratelimit@1742

@orpc/react

npm i https://pkg.pr.new/@orpc/react@1742

@orpc/react-query

npm i https://pkg.pr.new/@orpc/react-query@1742

@orpc/experimental-react-swr

npm i https://pkg.pr.new/@orpc/experimental-react-swr@1742

@orpc/server

npm i https://pkg.pr.new/@orpc/server@1742

@orpc/shared

npm i https://pkg.pr.new/@orpc/shared@1742

@orpc/solid-query

npm i https://pkg.pr.new/@orpc/solid-query@1742

@orpc/standard-server

npm i https://pkg.pr.new/@orpc/standard-server@1742

@orpc/standard-server-aws-lambda

npm i https://pkg.pr.new/@orpc/standard-server-aws-lambda@1742

@orpc/standard-server-fastify

npm i https://pkg.pr.new/@orpc/standard-server-fastify@1742

@orpc/standard-server-fetch

npm i https://pkg.pr.new/@orpc/standard-server-fetch@1742

@orpc/standard-server-node

npm i https://pkg.pr.new/@orpc/standard-server-node@1742

@orpc/standard-server-peer

npm i https://pkg.pr.new/@orpc/standard-server-peer@1742

@orpc/svelte-query

npm i https://pkg.pr.new/@orpc/svelte-query@1742

@orpc/tanstack-query

npm i https://pkg.pr.new/@orpc/tanstack-query@1742

@orpc/trpc

npm i https://pkg.pr.new/@orpc/trpc@1742

@orpc/valibot

npm i https://pkg.pr.new/@orpc/valibot@1742

@orpc/vue-colada

npm i https://pkg.pr.new/@orpc/vue-colada@1742

@orpc/vue-query

npm i https://pkg.pr.new/@orpc/vue-query@1742

@orpc/zod

npm i https://pkg.pr.new/@orpc/zod@1742

commit: a819642

@codecov

codecov Bot commented Jul 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates @orpc/standard-server’s event-iterator SSE encoder/decoder to be compliant with the WHATWG Server-Sent Events event-stream parsing rules, particularly around CR/CRLF handling, chunk-boundary correctness, and field-value whitespace semantics.

Changes:

  • Tighten encoder validation to reject carriage returns (in addition to newlines) in id/event/comment values and encode data with correct CR/CRLF normalization.
  • Rewrite the decoder to correctly interpret LF/CR/CRLF line endings and reliably detect message delimiters across arbitrary chunk boundaries.
  • Expand unit tests to cover CR/CRLF, delimiter splits at all positions, chunk-size invariance, and encode→decode round-trips.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/standard-server/src/event-iterator/meta.test.ts Updates assertions to reflect new CR/CRLF-aware validation error messages.
packages/standard-server/src/event-iterator/encoder.ts Adds CR/CRLF detection in field validation and makes data encoding SSE-spec compliant for CR/CRLF inputs.
packages/standard-server/src/event-iterator/encoder.test.ts Adds coverage for CR/CRLF in data encoding, comment validation, and encode→decode round-trips.
packages/standard-server/src/event-iterator/decoder.ts Implements spec-compliant line ending handling and robust delimiter detection across chunk boundaries.
packages/standard-server/src/event-iterator/decoder.test.ts Adds thorough tests for CR/CRLF support, delimiter split edge-cases, and chunk-size invariance.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes — ports the SSE encoder/decoder logic from the standardserver reference implementation into @orpc/standard-server's event-iterator module, with no public API changes.

  • SSE-compliant line ending and delimiter handlingdecodeEventMessage and EventDecoder.feed now recognize CR, LF, and CRLF line endings and message delimiters, including delimiters straddling chunk boundaries.
  • Space-stripping spec fix — only a single U+0020 SPACE is stripped after the colon; tabs and other whitespace are preserved per the SSE spec.
  • encodeEventData handles CR-containing data — splits on \r and \r\n in addition to \n.
  • Stronger assertion coverageassertEventId / assertEventName / assertEventComment reject carriage returns.
  • Comprehensive test coverage — chunk-size-invariance, every delimiter split at every position, CRLF split between chunks, 64 KB large-message, and encode→decode round-trip tests ported from the reference implementation.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@dinwwwh
dinwwwh merged commit b26a05c into 1.x Jul 29, 2026
7 checks passed
@dinwwwh
dinwwwh deleted the claude/event-stream-encoder-decoder-70c950 branch July 30, 2026 02:44
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