-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
fix(server+client): move client context from server to client #6422
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughThis pull request introduces a new type Changes
Possibly related PRs
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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 (
|
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
|
🚅 Previously deployed to Railway in the trpc-sse-and-websockets project. Environment has been deleted. |
commit: |
There was a problem hiding this 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
ClientContexttype 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: Replacevoidwithundefinedin union type.Using
voidin a union type can be confusing. Consider usingundefinedinstead 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:
- Add code examples showing before/after usage
- Explain why this change was made and its benefits
- 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
📒 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
TRPCProcedureOptionsis 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
TRPCProcedureOptionsin bothResolverandSubscriptionResolvertypes.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
TRPCProcedureOptionsis 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
| 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. |
|
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! |
|
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. |
Closes #
🎯 Changes
Move client interfaces from server to client
Summary by CodeRabbit
Release Notes
New Features
TRPCProcedureOptionstype to enhance procedure configuration flexibility.useSuspenseQueries()in@trpc/react.Type Changes
ProcedureOptionswithTRPCProcedureOptionsacross multiple packages.Deprecations
Requirements