Skip to content

feat(cli): optimize oRPC client dependencies by removing server dependency - #515

Merged
AmanVarshney01 merged 3 commits into
AmanVarshney01:mainfrom
theskinnycoder:feat/optimize-orpc-client-dependencies
Aug 15, 2025
Merged

AmanVarshney01 merged 3 commits into
AmanVarshney01:mainfrom
theskinnycoder:feat/optimize-orpc-client-dependencies

Conversation

@theskinnycoder

@theskinnycoder theskinnycoder commented Aug 15, 2025 •

Copy link
Copy Markdown

Summary

This PR optimizes oRPC client packages by eliminating the unnecessary @orpc/server dependency, reducing bundle size and creating cleaner architectural separation.

Problem

Previously, all oRPC client packages (React, Svelte, Solid, Nuxt, Native) installed @orpc/server as a runtime dependency solely for the RouterClient<T> type. This created:

  • Bundle bloat: Client packages included server-only runtime code
  • Unnecessary dependencies: Server package installed on client-side
  • Poor separation: Mixed server and client concerns

Solution

Export a pre-typed AppRouterClient from the server package instead of importing the generic RouterClient type on clients.

Before:

// Client code
import type { appRouter } from "../../../server/src/routers/index";
import type { RouterClient } from "@orpc/server"; // ❌ Server dependency on client

export const client: RouterClient<typeof appRouter> = createORPCClient(link)

After:

// Client code  
import type { AppRouterClient } from "../../../server/src/routers/index"; // ✅ Pre-typed from server

export const client: AppRouterClient = createORPCClient(link)

Changes Made

📦 Server Template Updates

  • apps/cli/templates/backend/server/server-base/src/routers/index.ts.hbs
    • Added AppRouterClient export: export type AppRouterClient = RouterClient<typeof appRouter>;

🎯 Client Template Updates (5 files)

  • React: apps/cli/templates/api/orpc/web/react/base/src/utils/orpc.ts.hbs
  • Svelte: apps/cli/templates/api/orpc/web/svelte/src/lib/orpc.ts.hbs
  • Solid: apps/cli/templates/api/orpc/web/solid/src/utils/orpc.ts.hbs
  • Nuxt: apps/cli/templates/api/orpc/web/nuxt/app/plugins/orpc.ts.hbs
  • Native: apps/cli/templates/api/orpc/native/utils/orpc.ts.hbs
  • TanStack Router: apps/cli/templates/frontend/react/tanstack-router/src/routes/__root.tsx.hbs

All updated to import AppRouterClient instead of RouterClient + appRouter.

⚙️ Dependency Installation Updates

  • apps/cli/src/helpers/setup/api-setup.ts
    • Removed @orpc/server from all client dependency arrays
    • Maintained @orpc/server only for server packages

Benefits

  • ✅ Reduced Bundle Size: Client packages no longer include server-only code
  • ✅ Cleaner Dependencies: Only necessary packages installed on client-side
  • ✅ Better Architecture: Clear separation between server and client concerns
  • ✅ Maintained Type Safety: Full end-to-end typing preserved across all frameworks
  • ✅ Backward Compatibility: All existing functionality unchanged

Test Plan

  • CLI builds successfully without errors
  • All client templates use AppRouterClient type correctly
  • No @orpc/server imports remain in client templates
  • Server packages still install @orpc/server dependency
  • Type safety maintained across all frameworks (React, Svelte, Solid, Nuxt, Native)
  • TanStack Router template properly updated

Frameworks Affected

  • ✅ React (Next.js, TanStack Router, React Router, TanStack Start)
  • ✅ Svelte (SvelteKit)
  • ✅ Solid (SolidStart)
  • ✅ Nuxt (Vue.js)
  • ✅ React Native (NativeWind, Unistyles)

Summary by CodeRabbit

  • New Features

    • Unified ORPC client typing across generated templates for more consistent developer experience.
  • Refactor

    • Updated frontend and native templates to use the new client type annotation for clearer typings.
  • Chores

    • Removed an unnecessary server-side ORPC package from frontend and native setups to streamline installs; server-side remains unchanged.
  • Notes

    • No runtime behavior or public CLI/API signature changes.

@changeset-bot

changeset-bot Bot commented Aug 15, 2025 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 8541380

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
create-better-t-stack Patch

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

@coderabbitai

coderabbitai Bot commented Aug 15, 2025 •

Copy link
Copy Markdown
Contributor

Caution

Review failed

The pull request is closed.

Walkthrough

Removes @orpc/server from frontend and native scaffold dependency lists, adds and exports an AppRouterClient type from server routers, and updates template imports/type annotations to use AppRouterClient; no runtime or public function signature changes.

Changes

Cohort / File(s) Summary
CLI setup dependency pruning (ORPC)
apps/cli/src/helpers/setup/api-setup.ts
Removes @orpc/server from ORPC dependency arrays for web and native scaffolds (React, Nuxt, Svelte, Solid, native); leaves @orpc/server in serverDir.
Backend: export AppRouterClient
apps/cli/templates/backend/server/server-base/src/routers/index.ts.hbs
Imports RouterClient from @orpc/server and adds export type AppRouterClient = RouterClient<typeof appRouter>.
Native ORPC client template
apps/cli/templates/api/orpc/native/utils/orpc.ts.hbs
Replaces RouterClient<typeof appRouter> with AppRouterClient and imports AppRouterClient from server routers; runtime creation unchanged.
Web ORPC client template — Nuxt
apps/cli/templates/api/orpc/web/nuxt/app/plugins/orpc.ts.hbs
Replaces RouterClient<typeof appRouter> with AppRouterClient; removes direct @orpc/server/appRouter type imports.
Web ORPC client templates — React
apps/cli/templates/api/orpc/web/react/base/src/utils/orpc.ts.hbs, apps/cli/templates/frontend/react/tanstack-router/src/routes/__root.tsx.hbs
Updates client type annotations to AppRouterClient and swaps imports to use server-exported AppRouterClient; removes RouterClient/appRouter type imports.
Web ORPC client template — Solid
apps/cli/templates/api/orpc/web/solid/src/utils/orpc.ts.hbs
Changes exported client type to AppRouterClient and updates type import.
Web ORPC client template — Svelte
apps/cli/templates/api/orpc/web/svelte/src/lib/orpc.ts.hbs
Changes exported client type to AppRouterClient and updates type import.
Changeset
.changeset/bright-areas-film.md
Adds patch changeset: "optimize oRPC client dependencies by removing server dependency."

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Possibly related PRs

Poem

In my burrow I hop through lines so bright,
Snipping server threads from the client's light.
AppRouterClient now leads the way,
Types aligned, templates at play.
Carrot commits — small hops, big delight. 🥕

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

📥 Commits

Reviewing files that changed from the base of the PR and between 23f494e and 8541380.

📒 Files selected for processing (1)
  • .changeset/bright-areas-film.md (1 hunks)
✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

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

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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

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

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 templates

Found 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/client or 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 AppRouter alias instead of typeof 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.

error may not always be an instance of Error; avoid potential type pitfalls and undefined message.

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 error isn’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 /index suffix for consistency.

import type cleanly avoids bundling server code. Minor nit: align path style with other templates by importing from .../routers instead 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.

📥 Commits

Reviewing files that changed from the base of the PR and between a9166fc and 468ee47.

📒 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 type ensures 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 client as AppRouterClient achieves the intended typing while keeping runtime deps clean.


2-2: ORPC client imports — server export present; no @orpc/server in client templates

Verified: 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 AppRouterClient from the server routers keeps typing intact without adding a dependency on @orpc/server.


32-32: LGTM: Correct client typing with AppRouterClient.

This matches the new server-exported alias and avoids generic plumbing in the client template.

@AmanVarshney01

Copy link
Copy Markdown
Owner

Thanks for the PR 😄

will merge in a while

@theskinnycoder

theskinnycoder commented Aug 15, 2025 •

Copy link
Copy Markdown
Author

Thanks for the PR 😄

will merge in a while

Cool! Looks like I missed a TanStack router template. Will update that.

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

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 setter

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

📥 Commits

Reviewing files that changed from the base of the PR and between 468ee47 and 03428b4.

📒 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 remain

Short 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";

@theskinnycoder

Copy link
Copy Markdown
Author

Thanks for the PR 😄
will merge in a while

Cool! Looks like I missed a TanStack router template. Will update that.

@AmanVarshney01 Done!

@AmanVarshney01

Copy link
Copy Markdown
Owner

rolling 😆
image

theskinnycoder added 2 commits August 15, 2025 19:56
…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.
@AmanVarshney01
AmanVarshney01 force-pushed the feat/optimize-orpc-client-dependencies branch from 03428b4 to 23f494e Compare August 15, 2025 14:26
@AmanVarshney01
AmanVarshney01 merged commit 4790cb8 into AmanVarshney01:main Aug 15, 2025

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

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 inference

Current 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 call createORPCClient<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 site

If you prefer being explicit (and to avoid relying on contextual return-type inference), you can import the server’s AppRouter type and pass it as a generic parameter to createORPCClient. This keeps the client free of @orpc/server and 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.

📥 Commits

Reviewing files that changed from the base of the PR and between 03428b4 and 23f494e.

📒 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 objective

Using import type avoids runtime coupling, and the AppRouterClient alias provides a stable client typing surface sourced from the server. This enables clients to drop @orpc/server while 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>;

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.

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

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.

2 participants