Skip to content
Back to skills

Orpc Optimize Ssr

ASecurity

Optimize SSR for fullstack frameworks by avoiding unnecessary HTTP self-calls.

  • 30 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added November 8, 2026
ai-agentsnextjsgitapifullstack

Works with

  • cli
  • api

Security analysis

A100/100

Scanned November 8, 2026

npx -y skills add majiayu000/claude-skill-registry-data --skill orpc-optimize-ssr --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Orpc Optimize Ssr?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Orpc Optimize Ssr
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/majiayu000-orpc-optimize-ssr/badge)](https://www.skillsdirectory.com/skills/majiayu000-orpc-optimize-ssr)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: oRPC Optimize SSR
description: Optimize SSR for fullstack frameworks by avoiding unnecessary HTTP self-calls.
license: MIT
metadata:
  author: Ali Torki
  homepage: https://github.com/ali-master
  version: "1.0.0"
---

# Optimize Server-Side Rendering (SSR) for Fullstack Frameworks

Optimize SSR with oRPC to eliminate redundant network calls during server rendering.

## The Problem

Standard SSR involves the server making HTTP requests back to its own API endpoints, adding latency.

## Conceptual approach

```ts
// Use this for server-side calls
const orpc = createRouterClient(router)

// Fallback to this for client-side calls
const orpc: RouterClient<typeof router> = createORPCClient(someLink)
```

A naive `typeof window === 'undefined'` check exposes your router logic to the client. Use `globalThis` to share the server client without bundling into client code.

## Implementation

```ts
// lib/orpc.ts
import type { RouterClient } from '@orpc/server'
import { RPCLink } from '@orpc/client/fetch'
import { createORPCClient } from '@orpc/client'

declare global {
  var $client: RouterClient<typeof router> | undefined
}

const link = new RPCLink({
  url: () => {
    if (typeof window === 'undefined') {
      throw new Error('RPCLink is not allowed on the server side.')
    }
    return `${window.location.origin}/rpc`
  },
})

export const client: RouterClient<typeof router> = globalThis.$client ?? createORPCClient(link)
```

```ts
// lib/orpc.server.ts
import 'server-only'
import { createRouterClient } from '@orpc/server'

globalThis.$client = createRouterClient(router, {
  context: async () => ({
    headers: await headers(),
  }),
})
```

## OpenAPILink support

```ts
// lib/orpc.server.ts
import { createJsonifiedRouterClient } from '@orpc/openapi'

globalThis.$client = createJsonifiedRouterClient(router, {
  context: async () => ({ headers: await headers() }),
})
```

## Ensure `orpc.server.ts` is imported first

```ts
// instrumentation.ts (Next.js)
export async function register() {
  await import('./lib/orpc.server')
}
```

```ts
// app/layout.tsx
import '../lib/orpc.server'
```

## Alternative Approach (Fetch-based)

```ts
// lib/orpc.server.ts
import 'server-only'
import { createORPCClient } from '@orpc/client'
import { RPCLink } from '@orpc/client/fetch'
import { handler } from '@/app/rpc/[[...rest]]/route'

const link = new RPCLink({
  url: 'http://placeholder',
  method: inferRPCMethodFromRouter(router),
  plugins: [
    new DedupeRequestsPlugin({
      groups: [{ condition: () => true, context: {} }],
    }),
  ],
  fetch: async (request) => {
    const { response } = await handler.handle(request, {
      context: { headers: await headers() },
    })
    return response ?? new Response('Not Found', { status: 404 })
  },
})

globalThis.$client = createORPCClient<RouterClient<typeof router>>(link)
```

## Using the Client

```tsx
export default async function PlanetListPage() {
  const planets = await client.planet.list({ limit: 10 })

  return (
    <div>
      {planets.map(planet => (
        <div key={planet.id}>{planet.name}</div>
      ))}
    </div>
  )
}
```

## TanStack Query

```tsx
export default function PlanetListPage() {
  const { data: planets } = useSuspenseQuery(
    orpc.planet.list.queryOptions({
      input: { limit: 10 },
    }),
  )

  return (
    <div>
      {planets.map(planet => <div key={planet.id}>{planet.name}</div>)}
    </div>
  )
}
```

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.