nextjs - 💡(How to fix) Fix Docs: Usage of Cache Components with Page-Level Authorization [5 comments, 3 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vercel/next.js#86670Fetched 2026-04-08 02:09:51
View on GitHub
Comments
5
Participants
3
Timeline
17
Reactions
1
Author
Timeline (top)
subscribed ×7commented ×5mentioned ×2issue_type_added ×1

Error Message

○ Compiling /test ... Error: Route "/test": Uncached data was accessed outside of <Suspense>. This delays the entire page from rendering, resulting in a slow user experience. Learn more: https://nextjs.org/docs/messages/blocking-route at ForgotPassword (src/app/test/page.tsx:20:19) 18 | 19 | export default async function ForgotPassword() {

20 | await connection(); | ^ 21 | await withGuest(); 22 | 23 | return <div>Forgot Password</div>; GET /test 200 in 4.0s (compile: 3.4s, render: 556ms)

Code Example

Compiling /test ...
Error: Route "/test": Uncached data was accessed outside of <Suspense>. This delays the entire page from rendering, resulting in a slow user experience. Learn more: https://nextjs.org/docs/messages/blocking-route
    at ForgotPassword (src/app/test/page.tsx:20:19)
  18 |
  19 | export default async function ForgotPassword() {
> 20 |   await connection();
     |                   ^
  21 |   await withGuest();
  22 |
  23 |   return <div>Forgot Password</div>;
 GET /test 200 in 4.0s (compile: 3.4s, render: 556ms)

---

import * as React from "react";
import { Metadata } from "next";
import { cookies } from "next/headers";
import { redirect } from "next/navigation";
import { connection } from "next/server";

export const metadata: Metadata = {
  title: "Forgot Password",
};

export async function withGuest() {
  const cookiesStore = await cookies();

  if (cookiesStore.get("AUTH_SESSION") !== undefined) {
    return redirect("/");
  }
}

export default async function ForgotPassword() {
  await connection();
  await withGuest();

  return <div>Forgot Password</div>;
}
RAW_BUFFERClick to expand / collapse

What is the documentation issue?

I don't use global / middleware-based authorization (middleware.ts/proxy.ts). instead I'm using page-level authorization on every page.

I tried migrating to Next.js v16 with Cache Components and almost every page fails with this error:

 ○ Compiling /test ...
Error: Route "/test": Uncached data was accessed outside of <Suspense>. This delays the entire page from rendering, resulting in a slow user experience. Learn more: https://nextjs.org/docs/messages/blocking-route
    at ForgotPassword (src/app/test/page.tsx:20:19)
  18 |
  19 | export default async function ForgotPassword() {
> 20 |   await connection();
     |                   ^
  21 |   await withGuest();
  22 |
  23 |   return <div>Forgot Password</div>;
 GET /test 200 in 4.0s (compile: 3.4s, render: 556ms)

so I open the "Learn more" page and I really can't find anything that would help me here. I don't really understand how am I supposed to migrate to Cache Components with Page-Level Authorization

Is there any context that might help us understand?

super simplified example code to reproduce the issue:

import * as React from "react";
import { Metadata } from "next";
import { cookies } from "next/headers";
import { redirect } from "next/navigation";
import { connection } from "next/server";

export const metadata: Metadata = {
  title: "Forgot Password",
};

export async function withGuest() {
  const cookiesStore = await cookies();

  if (cookiesStore.get("AUTH_SESSION") !== undefined) {
    return redirect("/");
  }
}

export default async function ForgotPassword() {
  await connection();
  await withGuest();

  return <div>Forgot Password</div>;
}

there are more examples:

  1. when user opens a product page and I need to verify that this product exists or return notFound.
  2. when I need to run analytics tracking on server side when user opens a page

Does the docs page already exist? Please link to it.

https://nextjs.org/docs/messages/blocking-route

extent analysis

TL;DR

Wrap the uncached data access in a Suspense component to prevent blocking the entire page from rendering.

Guidance

  • The error occurs because await connection() and await withGuest() are accessing uncached data outside of a Suspense component, which delays the page rendering.
  • To fix this, wrap the uncached data access in a Suspense component, like this: <Suspense fallback={<div>Loading...</div>}>...</Suspense>.
  • Review the Next.js documentation on Suspense to understand how to properly use it with Server Components.
  • Consider refactoring the withGuest function to use a more idiomatic approach, such as using a hook or a separate component, to handle the authentication logic.

Example

import { Suspense } from 'react';

export default async function ForgotPassword() {
  return (
    <Suspense fallback={<div>Loading...</div>}>
      <ForgotPasswordContent />
    </Suspense>
  );
}

async function ForgotPasswordContent() {
  await connection();
  await withGuest();

  return <div>Forgot Password</div>;
}

Notes

The provided example code is a simplified version of the actual issue, so the fix may need to be adapted to the specific use case. Additionally, the withGuest function seems to be using a redirect, which might not be the best approach when using Server Components.

Recommendation

Apply workaround: Wrap the uncached data access in a Suspense component to prevent blocking the entire page from rendering. This will allow the page to render while the uncached data is being fetched, improving the user experience.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING