-
SummaryGetting this error with next 16 and cache components enabled. Yes, I am wrapping the component that uses headers() with a suspense Additional informationI am creating an ORPC link to a different backend and injecting request headers to the orpc link instance and thats where the error is being thrown i guess. NOTE: this error just appears in the console, page rendering both in development and production build works just fine and no issue with partial pre rendering also, just error in server console. ExampleNo response |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 5 replies
-
|
Bu then the headers data is incorrect? Is it possible to see a repository, or more context around the usage area? |
Beta Was this translation helpful? Give feedback.
-
|
@icyJoseph here is the link to repo, try running dev server and going to / page, you will see error on console https://github.com/ahmedivy/next-headers-error-example |
Beta Was this translation helpful? Give feedback.
-
|
@icyJoseph any update? |
Beta Was this translation helpful? Give feedback.
-
|
@ahmedivy if i understand correctly, during prerendering (static generation), Next.js generates HTML at build time or during the first request. At that point, there's no actual HTTP request, so there are no headers to access. When your component tries to make an API call → the ORPC client tries to call headers throws during prerendering because there's no request context. To fix this, you can use import { api } from "@/lib/api";
import { connection } from "next/server";
export async function UserAvatar() {
await connection();
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const user = await (api as any).user.currentUser();
return <pre>{JSON.stringify(user, null, 2)}</pre>;
}So you force the request to be dynamic. You can see more here |
Beta Was this translation helpful? Give feedback.
@ahmedivy if i understand correctly, during prerendering (static generation), Next.js generates HTML at build time or during the first request. At that point, there's no actual HTTP request, so there are no headers to access.
When your component tries to make an API call → the ORPC client tries to call headers throws during prerendering because there's no request context.
To fix this, you can use
connection()like: