fix(standard-server): unify empty body parsing behavior across envs#533
fix(standard-server): unify empty body parsing behavior across envs#533
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
WalkthroughThis update modifies body and event iterator handling in server fetch and node packages. It removes early returns for null bodies and specific HTTP methods, allowing further processing regardless of these conditions. Additionally, the event iterator now accepts null streams, with new tests ensuring correct behavior for empty streams. Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant toEventIterator
participant Reader
Caller->>toEventIterator: Call with stream (can be null)
alt stream is null
toEventIterator-->>Caller: Returns async iterator (done: true)
else stream is not null
toEventIterator->>Reader: getReader()
loop For each chunk
Reader-->>toEventIterator: yield value
toEventIterator-->>Caller: { value, done: false }
end
toEventIterator-->>Caller: { done: true }
end
Possibly related PRs
Poem
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Codecov ReportAll modified and coverable lines are covered by tests ✅ 📢 Thoughts on this report? Let us know! |
More templates
@orpc/arktype
@orpc/client
@orpc/nest
@orpc/contract
@orpc/openapi
@orpc/openapi-client
@orpc/react
@orpc/react-query
@orpc/server
@orpc/shared
@orpc/solid-query
@orpc/standard-server
@orpc/standard-server-fetch
@orpc/standard-server-node
@orpc/standard-server-peer
@orpc/svelte-query
@orpc/valibot
@orpc/vue-colada
@orpc/vue-query
@orpc/zod
commit: |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/standard-server-fetch/src/event-iterator.ts (1)
10-66: Consider addressing static analysis warnings about void in union types.The static analysis tool flagged the use of
voidin union types in the return type signature. While not directly related to your current changes, you might want to consider usingundefinedinstead ofvoidin these union types to improve type clarity.-): AsyncIteratorObject<unknown | void, unknown | void, void> & AsyncGenerator<unknown | void, unknown | void, void> { +): AsyncIteratorObject<unknown | undefined, unknown | undefined, void> & AsyncGenerator<unknown | undefined, unknown | undefined, void> {🧰 Tools
🪛 Biome (1.9.4)
[error] 12-12: void is confusing inside a union type.
Unsafe fix: Use undefined instead.
(lint/suspicious/noConfusingVoidType)
[error] 12-12: void is confusing inside a union type.
Unsafe fix: Use undefined instead.
(lint/suspicious/noConfusingVoidType)
[error] 12-12: void is confusing inside a union type.
Unsafe fix: Use undefined instead.
(lint/suspicious/noConfusingVoidType)
[error] 12-12: void is confusing inside a union type.
Unsafe fix: Use undefined instead.
(lint/suspicious/noConfusingVoidType)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
packages/standard-server-fetch/src/body.ts(0 hunks)packages/standard-server-fetch/src/event-iterator.test.ts(1 hunks)packages/standard-server-fetch/src/event-iterator.ts(2 hunks)packages/standard-server-node/src/body.ts(0 hunks)
💤 Files with no reviewable changes (2)
- packages/standard-server-fetch/src/body.ts
- packages/standard-server-node/src/body.ts
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/standard-server-fetch/src/event-iterator.test.ts (2)
packages/standard-server-fetch/src/event-iterator.ts (1)
toEventIterator(10-66)packages/shared/src/iterator.ts (1)
isAsyncIteratorObject(3-9)
🪛 Biome (1.9.4)
packages/standard-server-fetch/src/event-iterator.ts
[error] 12-12: void is confusing inside a union type.
Unsafe fix: Use undefined instead.
(lint/suspicious/noConfusingVoidType)
[error] 12-12: void is confusing inside a union type.
Unsafe fix: Use undefined instead.
(lint/suspicious/noConfusingVoidType)
[error] 12-12: void is confusing inside a union type.
Unsafe fix: Use undefined instead.
(lint/suspicious/noConfusingVoidType)
[error] 12-12: void is confusing inside a union type.
Unsafe fix: Use undefined instead.
(lint/suspicious/noConfusingVoidType)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: publish-commit
- GitHub Check: lint
🔇 Additional comments (6)
packages/standard-server-fetch/src/event-iterator.test.ts (1)
85-90: Good addition of test for empty stream handling.This test case effectively verifies that
toEventIteratorproperly handles null streams by returning a valid async iterator that immediately completes. This aligns with the PR objective of unifying empty body parsing behavior across environments.packages/standard-server-fetch/src/event-iterator.ts (5)
10-11: Good type enhancement to explicitly handle null streams.Updating the parameter type to accept
nullvalues explicitly documents the function's ability to handle empty streams, which aligns with the PR objective of unifying empty body parsing behavior.
13-15: Appropriate use of optional chaining for null safety.The optional chaining operator ensures that the pipeline is only created when the stream is not null, preventing potential runtime errors when working with empty streams.
17-17: Safe reader access with optional chaining.This change correctly handles the case where
eventStreammight be undefined due to a null input stream, ensuring consistent behavior across different environments.
21-23: Proper early return for undefined readers.This condition appropriately handles cases where either the input stream was null or there was an issue in the processing pipeline. The immediate return of
{ done: true, value: undefined }matches the expected behavior for empty streams.
64-64: Safe cleanup with optional chaining.Using optional chaining for the
cancel()call ensures that the cleanup logic safely handles cases where the reader is undefined, preventing potential exceptions during iterator cleanup.
Empty body parsing can be
undefinedin some environments (e.g., Bun), but now it always follows the headers.Summary by CodeRabbit
Bug Fixes
Tests