nextjs - 💡(How to fix) Fix Docs: cacheComponent [1 comments, 2 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#91244Fetched 2026-04-08 00:18:49
View on GitHub
Comments
1
Participants
2
Timeline
5
Reactions
0
Author
Timeline (top)
closed ×1commented ×1issue_type_added ×1labeled ×1
RAW_BUFFERClick to expand / collapse

What is the documentation issue?

Next.js cannot guarantee that Cache Components will run as expected due to the current runtime's implementation of setTimeout().

Is there any context that might help us understand?

no

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

No response

extent analysis

Problem Summary

Next.js warns that Cache Components can’t be trusted because the current runtime’s setTimeout() implementation is unreliable (e.g., on the Edge runtime). The component ends up re‑validating at the wrong time or never at all.

Root Cause

  • The Edge runtime (or a custom runtime) provides a non‑standard setTimeout that may be throttled, capped, or completely omitted after a short period.
  • Cache components (unstable_cache, revalidate, fetch(..., { next: { revalidate } })) rely on setTimeout to schedule the next re‑validation. When the timer never fires, the cached value stays stale.

Fix Plan

1. Choose a runtime that guarantees setTimeout

OptionWhen to useHow
Node.js server runtime (default)All pages can run on a traditional server (Vercel Serverless, self‑hosted)Remove runtime: 'edge' from export const runtime = 'edge' or from next.config.js.
Edge runtime with polyfillYou must stay on Edge (e.g., for low‑latency geo‑routing)Add a reliable setTimeout polyfill (see step 2).

2. Add a reliable setTimeout polyfill for Edge (if you must stay on Edge)

Create a file lib/edge-timers.ts and import it at the top of any file that uses caching:

// lib/edge-timers.ts
// Simple polyfill using the native scheduler (requestIdleCallback) when setTimeout is missing or capped.
export const safeSetTimeout = (cb: () => void, ms: number) => {
  // Edge may cap timers at 1 s; break long delays into chunks.
  const MAX_CHUNK = 1000; // 1 s
  if (ms <= MAX_CHUNK) {
    return setTimeout(cb, ms);
  }

  let remaining = ms;
  const tick = () => {
    if (remaining <= MAX_CHUNK) {
      setTimeout(cb, remaining);
    }

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

nextjs - 💡(How to fix) Fix Docs: cacheComponent [1 comments, 2 participants]