FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

docs: add observable deprecation note to subscriptions reference projects by supermadu7 · Pull Request #7429 · trpc/trpc · GitHub

/ trpc Public

docs: add observable deprecation note to subscriptions reference projects - #7429

Open
supermadu7 wants to merge 4 commits into
trpc:mainfrom
supermadu7:fix/subscriptions-observable-deprecation
Open

docs: add observable deprecation note to subscriptions reference projects#7429
supermadu7 wants to merge 4 commits into
trpc:mainfrom
supermadu7:fix/subscriptions-observable-deprecation

Conversation

supermadu7 commented Jul 4, 2026
edited by coderabbitai Bot
Loading

Copy link
Copy Markdown

Closes #7368

🎯 Changes

This PR replaces the deprecated @trpc/server/observable API with the modern async function* generator pattern in the standalone-server reference project.

Additionally, it adds a deprecation notice to the Subscriptions documentation (www/docs/server/subscriptions.md) to clearly warn users that the observable API will be removed in tRPC v12 and provides instructions to migrate to async generators.

✅ 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

  • Refactor

    • Updated the standalone server’s subscription implementation to use async function* generators instead of the deprecated observable-based approach.
    • Random number streaming behavior remains the same, including clean termination when the client unsubscribes or disconnects.
  • Documentation

    • Added a warning that the older subscription API is deprecated (planned removal) and guidance to migrate to async generator-based subscriptions.
    • Linked to a reference project to help with migration.

Copilot AI review requested due to automatic review settings July 4, 2026 19:19
supermadu7 requested review from a team as code owners July 4, 2026 19:19

vercel Bot commented Jul 4, 2026
edited
Loading

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
next-prisma-starter Ready Preview Jul 4, 2026 7:37pm
og-image Ready Preview, Comment Jul 4, 2026 7:37pm

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Pull request overview

Updates the subscriptions documentation and the standalone-server reference project to steer users away from the deprecated @trpc/server/observable API and toward the recommended async function* generator pattern ahead of tRPC v12.

Changes:

  • Added a deprecation warning in the Subscriptions docs under “Reference projects”.
  • Replaced the observable-based randomNumber subscription in the standalone-server example with an async generator implementation.

Reviewed changes

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

File Description
www/docs/server/subscriptions.md Adds a caution block warning about @trpc/server/observable deprecation and pointing to the updated example.
examples/standalone-server/src/server.ts Migrates the randomNumber subscription implementation from observable to an async function* generator.

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

Comment thread www/docs/server/subscriptions.md Outdated
Comment on lines +25 to +27
:::caution Deprecation Notice
The `@trpc/server/observable` API is deprecated and will be removed in tRPC v12.
Please migrate your subscriptions to use `async function*` generators instead.
Comment on lines +47 to 56
randomNumber: publicProcedure.subscription(async function* ({ signal }) {
// Loop until the client disconnects and triggers the abort signal
while (!signal?.aborted) {
// Yield the random number instead of using emit.next()
yield { randomNumber: Math.random() };

// Wait for 200ms before the next loop instead of using setInterval
await new Promise((resolve) => setTimeout(resolve, 200));
}
}),

coderabbitai Bot commented Jul 4, 2026
edited
Loading

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info ⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: a3fb2b70-97d1-4cf3-ae03-02e3c5a40f88

📥 Commits

Reviewing files that changed from the base of the PR and between 277f3ee and d770f3e.

📒 Files selected for processing (2)
  • examples/standalone-server/src/server.ts
  • www/docs/server/subscriptions.md
✅ Files skipped from review due to trivial changes (1)
  • www/docs/server/subscriptions.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • examples/standalone-server/src/server.ts

📝 Walkthrough

Walkthrough

The standalone-server example's randomNumber subscription is rewritten from an observable-based implementation to an async generator that yields values until the abort signal fires. The subscriptions documentation adds a deprecation caution for the observable API.

Changes

Deprecate observable in favor of async generators

Layer / File(s) Summary
Async generator subscription example
examples/standalone-server/src/server.ts
Removes the observable import and replaces the subscription implementation with an async generator that yields { randomNumber } every 200ms and stops when the signal is aborted.
Deprecation notice in subscriptions docs
www/docs/server/subscriptions.md
Adds a caution callout stating @trpc/server/observable is deprecated and will be removed in tRPC v12, with guidance to migrate to async function* generators.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant Server
  participant Signal

  Client->>Server: subscribe to randomNumber
  loop every 200ms
    Server->>Server: yield {randomNumber}
    Server->>Client: emit value
  end
  Client->>Signal: unsubscribe/disconnect
  Signal->>Server: abort signal
  Server->>Server: exit loop
Loading

Possibly related PRs

  • trpc/trpc#6932: Also removes @trpc/server/observable usage from example server code.

Suggested labels: ♻️ autoupdate

Suggested reviewers: KATT

🚥 Pre-merge checks | ✅ 5 ✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: adding an observable deprecation note for subscriptions reference projects.
Description check ✅ Passed The description follows the required template and includes the issue link, change summary, and completed checklist items.
Linked Issues check ✅ Passed The PR updates the subscriptions reference example to async generators and adds deprecation guidance for the deprecated observable API.
Out of Scope Changes check ✅ Passed The changes stay within the stated scope of updating subscription reference docs and the standalone-server example.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches 🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

coderabbitai 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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
🧹 Nitpick comments (1)
examples/standalone-server/src/server.ts (1)

47-47: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Avoid destructuring in the function parameter.

async function* ({ signal }) destructures directly in the parameter declaration. As per coding guidelines: "Never destructure in function parameter declarations." Destructure signal from opts inside the function body instead.

♻️ Proposed fix
-  randomNumber: publicProcedure.subscription(async function* ({ signal }) {
+  randomNumber: publicProcedure.subscription(async function* (opts) {
     // Loop until the client disconnects and triggers the abort signal
-    while (!signal?.aborted) {
+    while (!opts.signal?.aborted) {
       // Yield the random number instead of using emit.next()
       yield { randomNumber: Math.random() };
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@examples/standalone-server/src/server.ts` at line 47, The subscription
handler in publicProcedure should not destructure its argument in the async
function* parameter list. Update the randomNumber subscription to accept the
options object as a single parameter and destructure signal inside the function
body instead, so the handler follows the no-destructuring-in-parameters
guideline.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@examples/standalone-server/src/server.ts`:
- Line 47: The subscription handler in publicProcedure should not destructure
its argument in the async function* parameter list. Update the randomNumber
subscription to accept the options object as a single parameter and destructure
signal inside the function body instead, so the handler follows the
no-destructuring-in-parameters guideline.

ℹ️ Review info ⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: d3da6c94-78f7-44d0-b8aa-26f750e54a6b

📥 Commits

Reviewing files that changed from the base of the PR and between 340811b and 277f3ee.

📒 Files selected for processing (2)
  • examples/standalone-server/src/server.ts
  • www/docs/server/subscriptions.md

pkg-pr-new Bot commented Jul 4, 2026
edited
Loading

Copy link
Copy Markdown

Open in StackBlitz

@trpc/client

npm i https://pkg.pr.new/@trpc/client@7429

@trpc/next

npm i https://pkg.pr.new/@trpc/next@7429

@trpc/openapi

npm i https://pkg.pr.new/@trpc/openapi@7429

@trpc/react-query

npm i https://pkg.pr.new/@trpc/react-query@7429

@trpc/server

npm i https://pkg.pr.new/@trpc/server@7429

@trpc/tanstack-react-query

npm i https://pkg.pr.new/@trpc/tanstack-react-query@7429

@trpc/upgrade

npm i https://pkg.pr.new/@trpc/upgrade@7429

commit: 80e015d

Copy link
Copy Markdown
Author

Hi team! I've implemented the fix for #7368 (migrating the standalone-server to async generators and updating the docs). The PR is ready, but it looks like the @trpc/upgrade test/transforms.test.ts > hooks > hooks optimistic-update.tsx test is flaking in the CI pipeline (it passes cleanly on my local machine). Could a maintainer take a look or re-run the failed job when you have a moment?

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
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.

docs: Subscriptions WebSockets reference projects use deprecated observable

2 participants


Back | FazBrowse Home | New Git URL