Server Component Fetch Self

Server components fetching their own API routes

infoPerformanceserver-component-fetch-self

Why this matters

A server component fetching its own API route makes a needless HTTP round trip to itself. The server component can call the same logic directly — it's already running on the server.

Example

Flaggedapp/dashboard/page.tsx
// app/dashboard/page.tsx (server component)
export default async function Dashboard() {
  // Fetching your OWN API route from the server
  const res = await fetch("http://localhost:3000/api/stats");
  const stats = await res.json();
  return <div>{stats.total}</div>;
}
Fixedapp/dashboard/page.tsx
// app/dashboard/page.tsx (server component)
import { getStats } from "@/lib/stats";

export default async function Dashboard() {
  // Call the function directly — no HTTP round trip
  const stats = await getStats();
  return <div>{stats.total}</div>;
}

How to fix

Extract the logic from your API route into a shared function. Call it directly from server components instead of making an HTTP request to yourself.

Reference

In the output
Findings carry "ruleId": "server-component-fetch-self" in --json and the same id in SARIF and in the terminal.
Silence one line
// prodlint-disable-next-line server-component-fetch-self
Silence a whole file
// prodlint-disable server-component-fetch-self at the top of the file
How it works
Matches text patterns. Source on GitHub