Skip to content

Conversation

@timcole
Copy link
Contributor

@timcole timcole commented Nov 19, 2025

🎯 Changes

When using mergeRouter sse options from initTRPC.create({..}) weren't being honored, this PR adds sse options to mergeRouter's createRouterFactory config.

✅ 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

  • New Features
    • Router merging now preserves Server-Sent Events (SSE) configuration from the primary router, enabling seamless router composition.

@timcole timcole requested a review from a team as a code owner November 19, 2025 19:52
@vercel
Copy link

vercel bot commented Nov 19, 2025

@timcole is attempting to deploy a commit to the trpc Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 19, 2025

Walkthrough

A new sse property is added to the merged router configuration in mergeRouters. The property is extracted from the first router's internal configuration and forwarded to the new merged router's config object.

Changes

Cohort / File(s) Change summary
Router SSE Property Addition
packages/server/src/unstable-core-do-not-import/router.ts
Adds sse property to merged router config, sourced from first router's _def._config.sse

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

  • Verify that the sse property is correctly inherited from the first router in the list
  • Confirm this is the intended behavior when merging multiple routers with potentially different SSE configurations
  • Check if any documentation or tests require updates to reflect this new merged config property

Poem

🐰 When routers merge in harmony,

The SSE travels silently,

From first to merged with gentle care,

Configuration floats through the air! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding missing SSE options to mergeRouter, which aligns with the file changes and PR objectives.
Description check ✅ Passed The description includes the required 'Changes' section explaining the issue and fix, and includes a completed checklist. However, the 'Closes #' section is missing the issue number.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 86e12a5 and 11ffdb4.

📒 Files selected for processing (1)
  • packages/server/src/unstable-core-do-not-import/router.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/coding-guidelines.mdc)

**/*.{ts,tsx}: Always use import type for type-only imports
Separate type imports from value imports
Avoid overzealous object destructuring; prefer direct property access
Object destructuring is acceptable when a variable is used 3+ times
Prefer array destructuring
Avoid sparse array destructuring
Never destructure in function parameter declarations
Avoid destructuring potentially nullish nested properties
Maximum 3 parameters per function; use options objects when more
Type parameter names must match /^(T|$)(A-Z)?[0-9]*$/
Prefix unused variables, parameters, and caught errors with _
Prefer namespace imports for validation libraries and large modules (e.g., import * as z from 'zod', import * as React from 'react')
Follow import order: test helpers, tRPC test imports, third-party, then relative
Never import from @trpc/*/src; import from the package root instead
Do not use Symbol.dispose or Symbol.asyncDispose; use makeResource()/makeAsyncResource()
Always use await using for resource cleanup
Prefer makeResource()/makeAsyncResource() over manual disposal logic
Avoid non-null assertions (!)
Use proper type guards and optional chaining instead of non-null assertions
Switch statements must be exhaustive for union types
Rely on TypeScript inference; avoid unnecessary explicit return/output types
Use explicit types at public API boundaries, for complex generic constraints, or when inference is insufficient/ambiguous
Use the satisfies operator to retain inference while enforcing shapes
Use as const for literal type inference when appropriate
Prefer explicit typing over any
Use type assertions sparingly
Leverage TypeScript strict mode features

Files:

  • packages/server/src/unstable-core-do-not-import/router.ts
**/*.{ts,tsx,md,mdx}

📄 CodeRabbit inference engine (.cursor/rules/coding-guidelines.mdc)

Use camelCase for file names (with exceptions like TRPC/RPC/HTTP/JSON acronyms, .config.js, .d.ts, and tests)

Files:

  • packages/server/src/unstable-core-do-not-import/router.ts
packages/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/coding-guidelines.mdc)

No console.log in packages; use proper logging instead

Files:

  • packages/server/src/unstable-core-do-not-import/router.ts
🧠 Learnings (1)
📚 Learning: 2025-09-05T15:16:48.745Z
Learnt from: CR
Repo: trpc/trpc PR: 0
File: .cursor/rules/test-patterns.mdc:0-0
Timestamp: 2025-09-05T15:16:48.745Z
Learning: Applies to **/*.test.ts : NEVER use the deprecated `routerToServerAndClientNew()` in tests

Applied to files:

  • packages/server/src/unstable-core-do-not-import/router.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: E2E-tests (express-server)
  • GitHub Check: E2E-tests (next-formdata)
  • GitHub Check: e2e-legacy-node (next-prisma-todomvc, 18.x)
  • GitHub Check: test
  • GitHub Check: Lint and auto-fix
🔇 Additional comments (1)
packages/server/src/unstable-core-do-not-import/router.ts (1)

560-560: Based on verification of the codebase, the implementation at line 560 is correct and intentional.

Implementation is correct—no changes needed.

The SSE configuration is a server-wide setting that applies globally to all merged routers executing on the same HTTP server instance. Taking the first router's SSE config (line 560) is consistent with how $types is handled (line 559), and differs intentionally from errorFormatter and transformer which require validation because they represent merge strategies.

SSE, like $types, is a singular global configuration—all routers in a merged set operate on the same server, so having multiple SSE configs is neither possible nor meaningful. The optional chaining (routerList[0]?._def._config.sse) correctly handles cases where routers lack SSE configuration.

Tip

📝 Customizable high-level summaries are now available in beta!

You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.

  • Provide your own instructions using the high_level_summary_instructions setting.
  • Format the summary however you like (bullet lists, tables, multi-section layouts, contributor stats, etc.).
  • Use high_level_summary_in_walkthrough to move the summary from the description to the walkthrough section.

Example instruction:

"Divide the high-level summary into five sections:

  1. 📝 Description — Summarize the main change in 50–60 words, explaining what was done.
  2. 📓 References — List relevant issues, discussions, documentation, or related PRs.
  3. 📦 Dependencies & Requirements — Mention any new/updated dependencies, environment variable changes, or configuration updates.
  4. 📊 Contributor Summary — Include a Markdown table showing contributions:
    | Contributor | Lines Added | Lines Removed | Files Changed |
  5. ✔️ Additional Notes — Add any extra reviewer context.
    Keep each section concise (under 200 words) and use bullet or numbered lists for clarity."

Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later.


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 and usage tips.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Nov 19, 2025

Open in StackBlitz

@trpc/client

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

@trpc/next

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

@trpc/react-query

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

@trpc/server

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

@trpc/tanstack-react-query

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

@trpc/upgrade

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

commit: 11ffdb4

@vercel
Copy link

vercel bot commented Nov 21, 2025

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

Project Deployment Preview Comments Updated (UTC)
www Ready Ready Preview Comment Nov 21, 2025 4:49pm

@KATT KATT enabled auto-merge (squash) November 21, 2025 16:47
@KATT KATT merged commit ffa88b0 into trpc:main Nov 21, 2025
42 of 45 checks passed
@github-actions
Copy link
Contributor

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 Nov 22, 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.

2 participants