Skip to content

Conversation

@KATT
Copy link
Member

@KATT KATT commented Feb 7, 2025

Closes #6464

🎯 Changes

Fix for unstable_httpBatchStreamLink & transformers at top level

βœ… Checklist

  • I have followed the steps listed in the Contributing guide.
  • If necessary, I have added documentation related to the changes made.
  • I have added or updated the tests related to the changes made.

Summary by CodeRabbit

  • Tests
    • Introduced a regression test that validates the accurate serialization and deserialization of date values.
  • Refactor
    • Enhanced the streaming encoding logic to more reliably handle asynchronous values and non-object types, ensuring consistent data processing.

These internal improvements aim to boost the overall reliability of our data streaming mechanism while preserving the correct handling of date information.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 7, 2025

Walkthrough

The changes introduce a regression test that validates the encoding and decoding of Date objects using SuperJSON at the top level. The new test constructs a data structure with a Promise resolving to a Date, splits the resulting stream using tee, and verifies the deserialized output against an inline snapshot. In addition, the encoding logic within the createBatchStreamProducer function (in jsonl.ts) is enhanced with conditional handling for asynchronous and non-object values.

Changes

File(s) Change Summary
packages/server/.../jsonl.test.ts Added regression test "regression: encode/decode with superjson at top level" to validate Date serialization.
packages/server/.../jsonl.ts Enhanced the "encode" function to conditionally return arrays for async encoding results and handle non-object values.

Sequence Diagram(s)

sequenceDiagram
    participant T as Test Runner
    participant P as jsonlStreamProducer
    participant TE as Tee Method
    participant C as jsonlStreamConsumer

    T ->> P: Send data structure with Promise(Date)
    P ->> P: Process encoding (async call & type-check)
    P ->> TE: Split stream using tee()
    TE ->> T: Return aggregated output from second stream
    T ->> C: Pass first stream data for deserialization
    C ->> T: Return decoded data (verified as Date instance)
Loading

Assessment against linked issues

Objective Addressed Explanation
Ensure proper serialization of Decimal when returned directly (#6464) ❌ Changes add a test for Date objects and modify encoding logic but do not cover Decimal.

Poem

I'm a bunny coding under moonlight bright,
Hopping through streams with pure delight,
Dates now prance in SuperJSON's gleam,
Validation in code, like a dream,
With extra hops on every line so neatβ€”
This rabbit’s heart skips a beat!
πŸ‡πŸ’»

✨ Finishing Touches
  • πŸ“ Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❀️ Share
πŸͺ§ Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@railway-app
Copy link

railway-app bot commented Feb 7, 2025

πŸš… Previously deployed to Railway in the trpc-sse-and-websockets project. Environment has been deleted.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 7, 2025

Open in Stackblitz

npm i https://pkg.pr.new/trpc/trpc/@trpc/client@6457
npm i https://pkg.pr.new/trpc/trpc/@trpc/next@6457
npm i https://pkg.pr.new/trpc/trpc/@trpc/react-query@6457
npm i https://pkg.pr.new/trpc/trpc/@trpc/server@6457

commit: 56fdc38

@vercel
Copy link

vercel bot commented Feb 7, 2025

The latest updates on your projects. Learn more about Vercel for Git β†—οΈŽ

Name Status Preview Comments Updated (UTC)
next-prisma-starter βœ… Ready (Inspect) Visit Preview Feb 7, 2025 3:09pm
og-image βœ… Ready (Inspect) Visit Preview πŸ’¬ Add feedback Feb 7, 2025 3:09pm
www πŸ›‘ Canceled (Inspect) Feb 7, 2025 3:09pm

@KATT KATT marked this pull request as ready for review February 7, 2025 15:07
@KATT KATT requested a review from a team as a code owner February 7, 2025 15:07
@KATT KATT changed the title chore: add test for transformer in unstable_httpBatchStreamLink fix(server): transformer at top level for httpBatchStreamLink Feb 7, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/server/src/unstable-core-do-not-import/stream/jsonl.ts (1)

236-244: Good enhancement to handle special objects!

The changes improve the handling of non-plain objects (like Date) and async values. The implementation correctly uses Object.prototype.toString.call() to distinguish between plain objects and special objects.

Consider extracting the object type check into a named function for better readability:

+function isPlainObject(value: unknown): boolean {
+  return Object.prototype.toString.call(value) === '[object Object]';
+}
+
 function encode(value: unknown, path: (string | number)[]): EncodedValue {
   if (value === undefined) {
     return [[]];
   }
   if (!isObject(value)) {
     return [[value]];
   }

   const reg = encodeAsync(value, path);
   if (reg) {
     return [[placeholder], [null, ...reg]];
   }

-  if (Object.prototype.toString.call(value) !== '[object Object]') {
+  if (!isPlainObject(value)) {
     return [[value]];
   }
πŸ“œ Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 972d78b and 56fdc38.

πŸ“’ Files selected for processing (2)
  • packages/server/src/unstable-core-do-not-import/stream/jsonl.test.ts (1 hunks)
  • packages/server/src/unstable-core-do-not-import/stream/jsonl.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (18)
  • GitHub Check: E2E-tests (vercel-edge-runtime)
  • GitHub Check: E2E-tests (tanstack-start)
  • GitHub Check: E2E-tests (standalone-server)
  • GitHub Check: E2E-tests (soa)
  • GitHub Check: E2E-tests (next-prisma-websockets-starter)
  • GitHub Check: E2E-tests (next-prisma-todomvc)
  • GitHub Check: E2E-tests (next-prisma-starter)
  • GitHub Check: E2E-tests (next-minimal-starter)
  • GitHub Check: E2E-tests (next-formdata)
  • GitHub Check: E2E-tests (minimal-react)
  • GitHub Check: e2e-legacy-node (next-prisma-todomvc, 20.x)
  • GitHub Check: e2e-legacy-node (next-prisma-todomvc, 18.x)
  • GitHub Check: e2e-legacy-node (next-prisma-websockets-starter, 20.x)
  • GitHub Check: e2e-legacy-node (next-prisma-websockets-starter, 18.x)
  • GitHub Check: e2e-legacy-node (next-prisma-starter, 20.x)
  • GitHub Check: E2E-tests (.experimental/next-app-dir)
  • GitHub Check: e2e-legacy-node (next-prisma-starter, 18.x)
  • GitHub Check: Lint and auto-fix
πŸ”‡ Additional comments (1)
packages/server/src/unstable-core-do-not-import/stream/jsonl.test.ts (1)

630-684: Well-structured regression test!

The test thoroughly validates the encoding and decoding of Date objects using SuperJSON at the top level. It covers:

  1. Proper serialization of Promise
  2. Stream handling with tee
  3. Correct deserialization back to Date object
  4. Timestamp verification

@KATT KATT merged commit 6ab0f06 into next Feb 7, 2025
45 checks passed
@KATT KATT deleted the transformer-stream branch February 7, 2025 15:11
@github-actions
Copy link
Contributor

github-actions bot commented Feb 8, 2025

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 8, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: unstable_httpBatchStreamLink breaks serialization of Decimal (and maybe others) when it's directly returned from a procedure

3 participants