Repository navigation
feat(cli): optimize oRPC client dependencies by removing server dependency - #515
Conversation
🦋 Changeset detectedLatest commit: 8541380 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Caution Review failedThe pull request is closed. WalkthroughRemoves Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~15 minutes Possibly related PRs
Poem
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. 📜 Recent review detailsConfiguration used: CodeRabbit UI 💡 Knowledge Base configuration:
You can enable these sources in your CodeRabbit configuration. 📒 Files selected for processing (1)
✨ Finishing Touches🧪 Generate 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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🔭 Outside diff range comments (1)
apps/cli/src/helpers/setup/api-setup.ts (1)
53-105: Remove/replace @orpc/server import from client templatesFound a client-side template importing @orpc/server — needs to be fixed. The server-side import under api/orpc/server is expected and can be ignored.
- apps/cli/templates/frontend/react/tanstack-router/src/routes/__root.tsx.hbs:10 —
import type { RouterClient } from "@orpc/server";(client template — replace/remove)- apps/cli/templates/api/orpc/server/base/src/lib/orpc.ts.hbs:1 —
import { ORPCError, os } from "@orpc/server";(server template — expected)Action: update the client template(s) to import the client-side package (e.g.,
@orpc/clientor the appropriate client export) or remove the server-only import. Re-scan other frontend templates (Nuxt/Svelte/Solid/Native) for similar occurrences after changes.
🧹 Nitpick comments (5)
apps/cli/templates/backend/server/server-base/src/routers/index.ts.hbs (1)
25-25: Exporting AppRouterClient unblocks client-side typing without @orpc/server in clients.This keeps client code clean while preserving end-to-end type safety. One small readability tweak: consider using the existing
AppRouteralias instead oftypeof appRouter.Proposed diff:
-export type AppRouterClient = RouterClient<typeof appRouter>; +export type AppRouterClient = RouterClient<AppRouter>;Optionally, re-export the type from the server package root to avoid deep imports from clients and reduce fragility if router paths change. For example (outside this file):
// server/src/index.ts export type { AppRouter, AppRouterClient } from "./routers";apps/cli/templates/api/orpc/web/solid/src/utils/orpc.ts.hbs (1)
9-12: Guard against non-Error values in onError.
errormay not always be an instance of Error; avoid potential type pitfalls and undefinedmessage.Apply:
- onError: (error) => { - console.error(`Error: ${error.message}`); - }, + onError: (error: unknown) => { + const message = error instanceof Error ? error.message : String(error); + console.error(`Error: ${message}`); + },apps/cli/templates/api/orpc/web/react/base/src/utils/orpc.ts.hbs (1)
39-41: Nit: add missing semicolons for consistency.Keeps style consistent with the rest of the file.
-export const client: AppRouterClient = createORPCClient(link) +export const client: AppRouterClient = createORPCClient(link); -export const orpc = createTanstackQueryUtils(client) +export const orpc = createTanstackQueryUtils(client);apps/cli/templates/api/orpc/web/svelte/src/lib/orpc.ts.hbs (1)
10-12: Optional: safer error handling for non-Error values.Prevent potential runtime issues when
errorisn’t an Error.- onError: (error) => { - console.error(`Error: ${error.message}`); - }, + onError: (error: unknown) => { + const message = error instanceof Error ? error.message : String(error); + console.error(`Error: ${message}`); + },apps/cli/templates/api/orpc/web/nuxt/app/plugins/orpc.ts.hbs (1)
2-2: Type-only import is spot on; consider dropping/indexsuffix for consistency.
import typecleanly avoids bundling server code. Minor nit: align path style with other templates by importing from.../routersinstead of.../routers/index.-import type { AppRouterClient } from "../../../server/src/routers/index"; +import type { AppRouterClient } from "../../../server/src/routers";
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (7)
apps/cli/src/helpers/setup/api-setup.ts(2 hunks)apps/cli/templates/api/orpc/native/utils/orpc.ts.hbs(2 hunks)apps/cli/templates/api/orpc/web/nuxt/app/plugins/orpc.ts.hbs(2 hunks)apps/cli/templates/api/orpc/web/react/base/src/utils/orpc.ts.hbs(2 hunks)apps/cli/templates/api/orpc/web/solid/src/utils/orpc.ts.hbs(2 hunks)apps/cli/templates/api/orpc/web/svelte/src/lib/orpc.ts.hbs(2 hunks)apps/cli/templates/backend/server/server-base/src/routers/index.ts.hbs(2 hunks)
🔇 Additional comments (12)
apps/cli/templates/backend/server/server-base/src/routers/index.ts.hbs (1)
3-3: Good use of type-only import to avoid runtime coupling.Importing RouterClient with
import typeensures no server runtime code leaks into the client bundles via this file. Aligned with the PR’s objective.apps/cli/src/helpers/setup/api-setup.ts (2)
57-58: Removed @orpc/server from React web client deps — as intended.This meets the PR’s goal of keeping server-only code out of client bundles.
119-121: Removed @orpc/server from native client deps — consistent with web.Keeps client packages lean and avoids mixing server concerns.
apps/cli/templates/api/orpc/web/solid/src/utils/orpc.ts.hbs (2)
5-5: Type-only import of AppRouterClient is spot on.This keeps the client free from @orpc/server runtime while preserving types.
27-27: Typed client assignment is clean and matches the new server export.No runtime changes; type safety retained.
apps/cli/templates/api/orpc/web/react/base/src/utils/orpc.ts.hbs (1)
6-6: Type-only import of AppRouterClient is correct.This removes any direct client dependency on @orpc/server while keeping types intact.
apps/cli/templates/api/orpc/web/svelte/src/lib/orpc.ts.hbs (2)
6-6: Type-only import of AppRouterClient looks good.Ensures no runtime tie to @orpc/server from the Svelte client.
28-28: Typed client assignment aligns with new server-side export.No runtime changes; type safety preserved.
apps/cli/templates/api/orpc/web/nuxt/app/plugins/orpc.ts.hbs (2)
26-26: LGTM: Strongly-typed client without pulling in @orpc/server at runtime.Annotating
clientasAppRouterClientachieves the intended typing while keeping runtime deps clean.
2-2: ORPC client imports — server export present; no @orpc/server in client templatesVerified: the server exports AppRouterClient and no client-side templates import '@orpc/server'. Client templates reference AppRouterClient as expected.
Files confirmed referencing AppRouterClient:
- apps/cli/templates/api/orpc/web/svelte/src/lib/orpc.ts.hbs
- apps/cli/templates/api/orpc/web/react/base/src/utils/orpc.ts.hbs
- apps/cli/templates/api/orpc/web/nuxt/app/plugins/orpc.ts.hbs
- apps/cli/templates/api/orpc/web/solid/src/utils/orpc.ts.hbs
- apps/cli/templates/api/orpc/native/utils/orpc.ts.hbs
Relevant snippet (unchanged):
import type { AppRouterClient } from "../../../server/src/routers/index";apps/cli/templates/api/orpc/native/utils/orpc.ts.hbs (2)
5-5: LGTM: Type-only import ensures no runtime coupling to server package.Importing
AppRouterClientfrom the server routers keeps typing intact without adding a dependency on@orpc/server.
32-32: LGTM: Correct client typing withAppRouterClient.This matches the new server-exported alias and avoids generic plumbing in the client template.
|
Thanks for the PR 😄 will merge in a while |
Cool! Looks like I missed a TanStack router template. Will update that. |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
apps/cli/templates/frontend/react/tanstack-router/src/routes/__root.tsx.hbs (1)
69-71: Prefer useMemo over useState when you don’t use the setterYour current approach works, but useMemo communicates intent better for a derived, stable value and avoids the unused setter.
Apply this diff within this block:
- const [client] = useState<AppRouterClient>(() => createORPCClient(link)); - const [orpcUtils] = useState(() => createTanstackQueryUtils(client)); + const client = useMemo<AppRouterClient>(() => createORPCClient(link), []); + const orpcUtils = useMemo(() => createTanstackQueryUtils(client), [client]);Additionally update the import:
- import { useState } from "react"; + import { useMemo } from "react";
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
apps/cli/templates/frontend/react/tanstack-router/src/routes/__root.tsx.hbs(2 hunks)
🔇 Additional comments (1)
apps/cli/templates/frontend/react/tanstack-router/src/routes/__root.tsx.hbs (1)
11-11: Type-only AppRouterClient import: verified — server exports the type and no @orpc/server client imports remainShort summary: I verified the server export and confirmed the frontend uses a type-only import; no @orpc/server imports were found in frontend templates.
- Server export confirmed: apps/cli/templates/backend/server/server-base/src/routers/index.ts.hbs — contains
- export type AppRouter = typeof appRouter;
- export type AppRouterClient = RouterClient;
- Frontend import confirmed (type-only): apps/cli/templates/frontend/react/tanstack-router/src/routes/__root.tsx.hbs — line with:
- import type { AppRouterClient } from "../../../server/src/routers";
- No @orpc/server imports under apps/cli/templates/frontend (rg returned no matches).
Optional: if you use path aliases in tsconfig, consider replacing the deep relative import for maintainability:
- import type { AppRouterClient } from "../../../server/src/routers"; + import type { AppRouterClient } from "@server/src/routers";
@AmanVarshney01 Done! |
…dency - Remove unnecessary @orpc/server dependency from all client packages by exporting pre-typed AppRouterClient from server package. This eliminates bundle bloat and creates cleaner separation between server and client concerns. Changes: - Export AppRouterClient type from server router template - Update all oRPC client templates to import AppRouterClient instead of RouterClient - Remove @orpc/server from client dependency installations (React, Svelte, Solid, Nuxt, Native) - Maintain @orpc/server dependency only in server packages where needed Benefits: - Reduced client bundle size by excluding server-only code - Cleaner dependency management with only necessary packages - Better architectural separation between server and client - Maintained end-to-end type safety across all frameworks
Complete the oRPC client optimization by updating the TanStack Router template to use AppRouterClient instead of RouterClient<typeof appRouter>. This was the only remaining client template that still imported @orpc/server for type definitions.
03428b4 to
23f494e
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
apps/cli/templates/backend/server/server-base/src/routers/index.ts.hbs (1)
25-25: Optional: also document how clients can use AppRouter generic for explicit inferenceCurrent approach relies on contextual typing at the assignment site. As an optional enhancement (not required), consider documenting the alternative where clients import
type { AppRouter }and callcreateORPCClient<AppRouter>(link)to make the router type parameter explicit without importing runtime values. This can help newcomers understand where the types originate and avoids relying on return-type inference.If you choose to showcase this alternative in client templates, it would look like:
// in client templates import type { AppRouter } from "../../../server/src/routers"; const client = createORPCClient<AppRouter>(link);apps/cli/templates/api/orpc/web/solid/src/utils/orpc.ts.hbs (1)
5-5: Optional: make the router type parameter explicit at the call siteIf you prefer being explicit (and to avoid relying on contextual return-type inference), you can import the server’s
AppRoutertype and pass it as a generic parameter tocreateORPCClient. This keeps the client free of@orpc/serverand makes the type relationship obvious.Here’s what that would look like:
-import type { AppRouterClient } from "../../../server/src/routers/index"; +import type { AppRouterClient, AppRouter } from "../../../server/src/routers/index"; -export const client: AppRouterClient = createORPCClient(link); +export const client = createORPCClient<AppRouter>(link);Both approaches are valid; this is just a style preference for clarity.
Also applies to: 27-27
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (8)
apps/cli/src/helpers/setup/api-setup.ts(2 hunks)apps/cli/templates/api/orpc/native/utils/orpc.ts.hbs(2 hunks)apps/cli/templates/api/orpc/web/nuxt/app/plugins/orpc.ts.hbs(2 hunks)apps/cli/templates/api/orpc/web/react/base/src/utils/orpc.ts.hbs(2 hunks)apps/cli/templates/api/orpc/web/solid/src/utils/orpc.ts.hbs(2 hunks)apps/cli/templates/api/orpc/web/svelte/src/lib/orpc.ts.hbs(2 hunks)apps/cli/templates/backend/server/server-base/src/routers/index.ts.hbs(2 hunks)apps/cli/templates/frontend/react/tanstack-router/src/routes/__root.tsx.hbs(2 hunks)
🚧 Files skipped from review as they are similar to previous changes (6)
- apps/cli/templates/api/orpc/web/svelte/src/lib/orpc.ts.hbs
- apps/cli/templates/frontend/react/tanstack-router/src/routes/__root.tsx.hbs
- apps/cli/templates/api/orpc/web/react/base/src/utils/orpc.ts.hbs
- apps/cli/src/helpers/setup/api-setup.ts
- apps/cli/templates/api/orpc/web/nuxt/app/plugins/orpc.ts.hbs
- apps/cli/templates/api/orpc/native/utils/orpc.ts.hbs
🔇 Additional comments (2)
apps/cli/templates/backend/server/server-base/src/routers/index.ts.hbs (1)
3-3: LGTM: type-only import + AppRouterClient export cleanly meet the PR objectiveUsing
import typeavoids runtime coupling, and theAppRouterClientalias provides a stable client typing surface sourced from the server. This enables clients to drop@orpc/serverwhile preserving end-to-end types. Nicely done.Also applies to: 25-25
apps/cli/templates/api/orpc/web/solid/src/utils/orpc.ts.hbs (1)
5-5: Good: type-only import ensures no server runtime code leaks into the client
import type { AppRouterClient } ...prevents bundlers from pulling server code while still providing strong typing.
| {{/if}} | ||
| }; | ||
| export type AppRouter = typeof appRouter; | ||
| export type AppRouterClient = RouterClient<typeof appRouter>; |
There was a problem hiding this comment.
💡 Verification agent
🧩 Analysis chain
Verify the removal of @orpc/server from all client templates
To ensure no stragglers remain and that only the server exports the AppRouterClient type, run the following checks.
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# 1) Ensure no client template imports from '@orpc/server'
echo "Checking that client templates do not import '@orpc/server'..."
pattern=$'from\\s+[\'"]@orpc/server[\'"]'
# Show any imports anywhere for visibility
rg -nP -C2 "$pattern" apps/cli/templates || true
# Fail if any occur outside backend (server) templates
if rg -nP "$pattern" apps/cli/templates -g '!apps/cli/templates/backend/**' >/dev/null; then
echo "ERROR: Found '@orpc/server' imports outside backend templates."
exit 1
else
echo "OK: No '@orpc/server' imports in client templates."
fi
# 2) Confirm AppRouterClient is exported from the server routers barrel
echo "Checking server export of AppRouterClient..."
rg -n 'export\s+type\s+AppRouterClient\s*=' apps/cli/templates/backend/server/server-base/src/routers/index.ts.hbs -n -C1
# 3) Confirm clients import AppRouterClient from the server routers
echo "Checking that clients import AppRouterClient from the server routers..."
rg -nP -C1 'import\s+type\s+\{\s*AppRouterClient\s*\}\s+from\s+[\'"].*server/src/routers' apps/cli/templates -g '!apps/cli/templates/backend/**'
# 4) Ensure no client templates import RouterClient directly
echo "Ensuring clients no longer import RouterClient from '@orpc/server'..."
if rg -nP 'import\s+type\s+\{\s*RouterClient\s*\}\s+from\s+[\'"]@orpc/server[\'"]' apps/cli/templates -g '!apps/cli/templates/backend/**' >/dev/null; then
echo "ERROR: Found client imports of RouterClient from '@orpc/server'."
exit 1
else
echo "OK: No client imports of RouterClient from '@orpc/server'."
fi
# 5) Sanity check TanStack Router template update was applied
echo "Checking TanStack Router template for AppRouterClient usage..."
rg -n 'AppRouterClient' apps/cli/templates/frontend/react/tanstack-router -C2 || {
echo "WARNING: No AppRouterClient usage found in TanStack Router template. Verify manually if applicable."
}Length of output: 1399
Remove remaining @orpc/server imports from non-server templates
The verification run found @orpc/server imports outside the intended backend templates — these need to be removed or confirmed as intentionally server-only.
Files/locations found:
- apps/cli/templates/backend/server/server-base/src/routers/index.ts.hbs — line 3:
import type { RouterClient } from "@orpc/server"; - apps/cli/templates/api/orpc/server/base/src/lib/orpc.ts.hbs — line 1:
import { ORPCError, os } from "@orpc/server";
Action required:
- Remove any @orpc/server imports from client/frontend templates (ensure clients import AppRouterClient from the server routers barrel instead).
- If the files under apps/cli/templates/api/... are server-only, confirm they should be excluded from the "no @orpc/server in clients" rule or move them under the backend template set so the verification script ignores them.
🤖 Prompt for AI Agents
In apps/cli/templates/backend/server/server-base/src/routers/index.ts.hbs around
line 25, remove the direct import of RouterClient from "@orpc/server" and
instead ensure the file exports AppRouterClient without importing @orpc/server
(i.e., stop using `import type { RouterClient } from "@orpc/server";` in this
template); update the routers barrel so clients consume a pre-defined
AppRouterClient type from the server routers barrel (or add a local type alias
that references the server-side export) and move/mark any files under
apps/cli/templates/api/... that truly belong to server runtime into the
backend/server templates so the verification script ignores them.

Summary
This PR optimizes oRPC client packages by eliminating the unnecessary
@orpc/serverdependency, reducing bundle size and creating cleaner architectural separation.Problem
Previously, all oRPC client packages (React, Svelte, Solid, Nuxt, Native) installed
@orpc/serveras a runtime dependency solely for theRouterClient<T>type. This created:Solution
Export a pre-typed
AppRouterClientfrom the server package instead of importing the genericRouterClienttype on clients.Before:
After:
Changes Made
📦 Server Template Updates
apps/cli/templates/backend/server/server-base/src/routers/index.ts.hbsAppRouterClientexport:export type AppRouterClient = RouterClient<typeof appRouter>;🎯 Client Template Updates (5 files)
apps/cli/templates/api/orpc/web/react/base/src/utils/orpc.ts.hbsapps/cli/templates/api/orpc/web/svelte/src/lib/orpc.ts.hbsapps/cli/templates/api/orpc/web/solid/src/utils/orpc.ts.hbsapps/cli/templates/api/orpc/web/nuxt/app/plugins/orpc.ts.hbsapps/cli/templates/api/orpc/native/utils/orpc.ts.hbsapps/cli/templates/frontend/react/tanstack-router/src/routes/__root.tsx.hbsAll updated to import
AppRouterClientinstead ofRouterClient+appRouter.⚙️ Dependency Installation Updates
apps/cli/src/helpers/setup/api-setup.ts@orpc/serverfrom all client dependency arrays@orpc/serveronly for server packagesBenefits
Test Plan
AppRouterClienttype correctly@orpc/serverimports remain in client templates@orpc/serverdependencyFrameworks Affected
Summary by CodeRabbit
New Features
Refactor
Chores
Notes