Skip to content

Conversation

@KATT
Copy link
Member

@KATT KATT commented Jan 26, 2025

Closes #

🎯 Changes

Move client interfaces from server to client

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced TRPCProcedureOptions type to enhance procedure configuration flexibility.
    • Added new method useSuspenseQueries() in @trpc/react.
  • Type Changes

    • Replaced ProcedureOptions with TRPCProcedureOptions across multiple packages.
    • Updated type signatures in client and server modules.
  • Deprecations

    • Marked several types and functions as deprecated, recommending newer alternatives.
  • Requirements

    • Now requires TypeScript 5.7.2 or higher.
    • Supports NodeJS 18+ and modern browsers.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 26, 2025

Walkthrough

This pull request introduces a new type TRPCProcedureOptions across multiple packages in the tRPC ecosystem. The changes involve replacing the existing ProcedureOptions with the new type, updating type signatures in client and server-side modules. The modification primarily affects type definitions, adding an optional context property and signal to the procedure options, and marks several existing types as deprecated. The changes aim to provide more flexibility in handling procedure options while preparing for future version improvements.

Changes

File Change Summary
packages/client/src/createTRPCClient.ts Updated function signatures to use TRPCProcedureOptions instead of ProcedureOptions. Removed export modifier from createTRPCClientProxy.
packages/client/src/index.ts Added export for TRPCProcedureOptions.
packages/client/src/internals/types.ts Introduced ClientContext type and TRPCProcedureOptions interface.
packages/next/src/app-dir/create-action-hook.tsx Updated MutationArgs type to use TRPCProcedureOptions.
packages/server/src/@trpc/server/index.ts Removed ProcedureOptions export and marked multiple types as deprecated.
packages/server/src/unstable-core-do-not-import/procedure.ts Removed ClientContext type and context property from ProcedureOptions.
www/docs/migration/migrate-from-v10-to-v11.mdx Updated migration instructions to reflect changes from ProcedureOptions to TRPCProcedureOptions.

Possibly related PRs

Poem

🐰 Hop, hop, type changes abound,
Options dancing, new paths found!
From ProcedureOptions to something more bright,
tRPC evolves with typeful might!
A rabbit's code leap of pure delight! 🚀


📜 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 074a6b9 and fb114b5.

📒 Files selected for processing (1)
  • packages/client/src/createTRPCClient.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/client/src/createTRPCClient.ts

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

@vercel
Copy link

vercel bot commented Jan 26, 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 Jan 26, 2025 1:10pm
og-image ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 26, 2025 1:10pm
www ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 26, 2025 1:10pm

@railway-app
Copy link

railway-app bot commented Jan 26, 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 Jan 26, 2025

Open in Stackblitz

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

commit: fb114b5

@KATT KATT marked this pull request as ready for review January 26, 2025 12:07
@KATT KATT requested review from a team as code owners January 26, 2025 12:07
@KATT KATT changed the title wip chore(server+client): move client context from server to client Jan 26, 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: 1

🧹 Nitpick comments (4)
packages/client/src/internals/types.ts (2)

90-90: Consider adding JSDoc comment for ClientContext type.

The ClientContext type would benefit from documentation explaining its purpose and usage.

+/**
+ * Type representing the client-side context that can be passed to procedures
+ * @public
+ */
 type ClientContext = Record<string, unknown>;

95-101: Add JSDoc comments for interface properties.

While the interface has a JSDoc comment, its properties would benefit from detailed documentation.

 export interface TRPCProcedureOptions {
   /**
    * Client-side context
+   * @description Optional context data that will be available during procedure execution
+   * @example
+   * ```ts
+   * const result = await client.query('myQuery', input, { 
+   *   context: { userId: '123' } 
+   * });
+   * ```
    */
   context?: ClientContext;
+  /**
+   * AbortSignal to cancel the procedure
+   * @description Optional signal that can be used to abort the procedure execution
+   * @example
+   * ```ts
+   * const controller = new AbortController();
+   * const result = await client.query('myQuery', input, { 
+   *   signal: controller.signal 
+   * });
+   * ```
+   */
   signal?: AbortSignal;
 }
packages/next/src/app-dir/create-action-hook.tsx (1)

28-29: Replace void with undefined in union type.

Using void in a union type can be confusing. Consider using undefined instead for better type clarity.

-  ? [input?: undefined | void, opts?: TRPCProcedureOptions]
+  ? [input?: undefined, opts?: TRPCProcedureOptions]
🧰 Tools
🪛 Biome (1.9.4)

[error] 28-28: void is confusing inside a union type.

Unsafe fix: Use undefined instead.

(lint/suspicious/noConfusingVoidType)

www/docs/migration/migrate-from-v10-to-v11.mdx (1)

27-30: Enhance the migration documentation for TRPCProcedureOptions.

The section would benefit from additional details to help users understand and implement the change:

  1. Add code examples showing before/after usage
  2. Explain why this change was made and its benefits
  3. Include steps to identify if a codebase is affected

Consider expanding the section like this:

 ### Move `TRPCProcedureOptions` to `@trpc/client` (non-breaking for most)
 
 If you previously used `ProcedureOptions` from `@trpc/server`, you now need to use `TRPCProcedureOptions` from `@trpc/client` instead.
 
+#### Why this change?
+
+This change consolidates client-related types in the client package, improving package organization and reducing cross-package dependencies.
+
+#### How to identify if you're affected
+
+You're affected if you're explicitly using the `ProcedureOptions` type in your code:
+
+```ts
+// Before
+import { ProcedureOptions } from '@trpc/server';
+
+// After
+import { TRPCProcedureOptions } from '@trpc/client';
+```
+
+#### Example migration
+
+```ts
+// Before
+import { ProcedureOptions } from '@trpc/server';
+
+function myMiddleware(opts: ProcedureOptions) {
+  // ...
+}
+
+// After
+import { TRPCProcedureOptions } from '@trpc/client';
+
+function myMiddleware(opts: TRPCProcedureOptions) {
+  // ...
+}
+```
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a604132 and db2586b.

📒 Files selected for processing (7)
  • packages/client/src/createTRPCClient.ts (2 hunks)
  • packages/client/src/index.ts (1 hunks)
  • packages/client/src/internals/types.ts (1 hunks)
  • packages/next/src/app-dir/create-action-hook.tsx (2 hunks)
  • packages/server/src/@trpc/server/index.ts (0 hunks)
  • packages/server/src/unstable-core-do-not-import/procedure.ts (0 hunks)
  • www/docs/migration/migrate-from-v10-to-v11.mdx (1 hunks)
💤 Files with no reviewable changes (2)
  • packages/server/src/unstable-core-do-not-import/procedure.ts
  • packages/server/src/@trpc/server/index.ts
🧰 Additional context used
🪛 Biome (1.9.4)
packages/next/src/app-dir/create-action-hook.tsx

[error] 28-28: void is confusing inside a union type.

Unsafe fix: Use undefined instead.

(lint/suspicious/noConfusingVoidType)

🔇 Additional comments (4)
packages/client/src/index.ts (2)

Line range hint 1-1: Address the TODO comment.

The comment "TODO: Be explicit about what we export here" should be addressed before finalizing this PR, especially since we're adding a new export.

Would you like me to help document the exports or create an issue to track this task?


24-24: LGTM! Clean export of the new type.

The export of TRPCProcedureOptions is well-placed alongside other type exports.

packages/client/src/createTRPCClient.ts (1)

47-47: LGTM! Consistent type updates.

The changes correctly update the option types to use TRPCProcedureOptions in both Resolver and SubscriptionResolver types.

Also applies to: 55-55

packages/next/src/app-dir/create-action-hook.tsx (1)

4-4: LGTM! Clean import of the new type.

The import of TRPCProcedureOptions is well-placed alongside other client types.

### Move `TRPCProcedureOptions` to `@trpc/client` (non-breaking for most)

If you previously used `ProcedureOptions` from `@trpc/server`, you can now need to use `TRPCProcedureOptions` from `@trpc/client` instead.
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix grammatical error in migration instruction.

The sentence contains a grammatical error that affects clarity.

Apply this diff to fix the grammar:

-If you previously used `ProcedureOptions` from `@trpc/server`, you can now need to use `TRPCProcedureOptions` from `@trpc/client` instead.
+If you previously used `ProcedureOptions` from `@trpc/server`, you now need to use `TRPCProcedureOptions` from `@trpc/client` instead.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
If you previously used `ProcedureOptions` from `@trpc/server`, you can now need to use `TRPCProcedureOptions` from `@trpc/client` instead.
If you previously used `ProcedureOptions` from `@trpc/server`, you now need to use `TRPCProcedureOptions` from `@trpc/client` instead.

@Not-Jayden
Copy link

Was thinking this was a bit strange haha

@KATT KATT changed the title chore(server+client): move client context from server to client fix(server+client): move client context from server to client Jan 26, 2025
@KATT
Copy link
Member Author

KATT commented Jan 26, 2025

Was thinking this was a bit strange haha

Yeah, it's been in there for years

Anyway, the real fix to #4876 isn't a global interface, I'll comment on your PR

@Not-Jayden
Copy link

Was thinking this was a bit strange haha

Yeah, it's been in there for years

Anyway, the real fix to #4876 isn't a global interface, I'll comment on your PR

Ok thanks, appreciate it!

@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 Jan 28, 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.

3 participants