nextjs - ✅(Solved) Fix `temporal-polyfill` `Temporal.Instant.from` flagged with "used `new Date()` before accessing either uncached data" [1 pull requests, 8 comments, 4 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#88696Fetched 2026-04-08 02:04:09
View on GitHub
Comments
8
Participants
4
Timeline
20
Reactions
0
Author
Timeline (top)
commented ×7subscribed ×4mentioned ×3renamed ×3

Error Message

Error: Route "/from-iso" used new Date() before accessing either uncached data (e.g. fetch()) or Request data (e.g. cookies(), headers(), connection(), and searchParams). Accessing the current time in a Server Component requires reading one of these data sources first. Alternatively, consider moving this expression into a Client Component or Cache Component. See more info here: https://nextjs.org/docs/messages/next-prerender-current-time at Home (page.tsx:4:35) at Home (<anonymous>:1:13)

Fix Action

Fix / Workaround

This does not reproduce:

  1. creating via new Date(<iso>).toTemporalInstant() -- this is the workaround for now in production
  2. creating via Temporal.Instant.from(<epoch ms>)

With Temporal starting to be released in browsers, it's likely many more people will reach for a polyfill so they can use it, and this is the most popular (or one of two most popuar) polyfills. Is there a way to allowlist this path so it is not considered uncached data access?

I will go deep in temporal-polyfill and see if it's patchable there (or just understand why it's occurring too).

PR fix notes

PR #82: fix(nextjs): initialize new Date() with (0) to avoid breaking Next.js 16 Cache Components pre-render

Description (problem / solution / changelog)

Next.js Cache Components does not allow access to any "dynamic" data during pre-rendering, because this is intended to build a static shell that could be cached by a remote server. It throws an error to prevent mistakes - i.e. make the user make a conscious decision what they want to do with dynamic data (in your Next app, you would mark it as cached for some period of time, in which case it will be cached in the pre-render).

new Date() is one of those functions you need to mark as explicitly cached and tell Next.js how long to cache it for (because it's the current time, not a fixed date). new Date('<some fixed>') would not be flagged as it is not dynamic.

Unfortunately, Temporal.Instant.from(<some fixed ISO string>) is flagged as dynamic, because it is using new Date()... but then immediately setting it to a fixed value in isoToLegacyDate. This forces users to wrap it with caching, which is tedious and unnecessary when it is actually a fixed date:

Error: Route "/from-iso" used `new Date()` before accessing either uncached data (e.g. `fetch()`) or Request data (e.g. `cookies()`, `headers()`, `connection()`, and `searchParams`). Accessing the current time in a Server Component requires reading one of these data sources first. Alternatively, consider moving this expression into a Client Component or Cache Component. See more info here: https://nextjs.org/docs/messages/next-prerender-current-time
    at Home (page.tsx:4:35)
    at Home (<anonymous>:1:13)

This fix inits it with new Date(0) instead, which stops Next.js complaining about this.

note: also raised this to Next.js: https://github.com/vercel/next.js/issues/88696 because it's a bit unergonomic that this pattern is flagged, although I can see why it'd be hard to detect.

Changed files

  • packages/temporal-polyfill/src/internal/timeMath.ts (modified, +1/-1)
  • packages/temporal-polyfill/src/internal/timeZoneConfig.ts (modified, +1/-1)

Code Example

Error: Route "/from-iso" used `new Date()` before accessing either uncached data (e.g. `fetch()`) or Request data (e.g. `cookies()`, `headers()`, `connection()`, and `searchParams`). Accessing the current time in a Server Component requires reading one of these data sources first. Alternatively, consider moving this expression into a Client Component or Cache Component. See more info here: https://nextjs.org/docs/messages/next-prerender-current-time
    at Home (page.tsx:4:35)
    at Home (<anonymous>:1:13)

---

pnpm next info

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.3.0: Sun Jan  4 19:18:29 PST 2026; root:xnu-12377.80.267~81/RELEASE_ARM64_T6041
  Available memory (MB): 131072
  Available CPU cores: 16
Binaries:
  Node: 22.18.0
  npm: 10.9.3
  Yarn: 1.22.22
  pnpm: 10.18.3
Relevant Packages:
  next: 16.1.1-canary.32 // Latest available version is detected (16.1.1-canary.32).
  eslint-config-next: N/A
  react: 19.2.3
  react-dom: 19.2.3
  typescript: 5.9.3
Next.js Config:
  output: N/A
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://github.com/rikbrown/nextjs-temporal-polyfill-cache-components-issue

To Reproduce

  1. Start the provided application in next dev
  2. Visit http://localhost:3000/from-iso
  3. Observe cache components error

Current vs. Expected behavior

Basically, Temporal.Instant.from(<iso>) polyfilled via temporal-polyfill is throwing the uncached data error. This isn't expected: this is used to create an instant from a fixed point of time which should be safe in cached environments.

This does not reproduce:

  1. creating via new Date(<iso>).toTemporalInstant() -- this is the workaround for now in production
  2. creating via Temporal.Instant.from(<epoch ms>)

I think Temporal.Instant.from(<iso>) is internally creating a new Date() somewhere, which is causing it to be flagged by Next.js. I suspect it is doing it to assign fields to the date, not to actually use anything about the current date, but haven't been able to go deep in their code yet (will update ticket soon). See comment below for the culprit code.

With Temporal starting to be released in browsers, it's likely many more people will reach for a polyfill so they can use it, and this is the most popular (or one of two most popuar) polyfills. Is there a way to allowlist this path so it is not considered uncached data access?


Current:

Error: Route "/from-iso" used `new Date()` before accessing either uncached data (e.g. `fetch()`) or Request data (e.g. `cookies()`, `headers()`, `connection()`, and `searchParams`). Accessing the current time in a Server Component requires reading one of these data sources first. Alternatively, consider moving this expression into a Client Component or Cache Component. See more info here: https://nextjs.org/docs/messages/next-prerender-current-time
    at Home (page.tsx:4:35)
    at Home (<anonymous>:1:13)

Expected: no error

Provide environment information

pnpm next info

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.3.0: Sun Jan  4 19:18:29 PST 2026; root:xnu-12377.80.267~81/RELEASE_ARM64_T6041
  Available memory (MB): 131072
  Available CPU cores: 16
Binaries:
  Node: 22.18.0
  npm: 10.9.3
  Yarn: 1.22.22
  pnpm: 10.18.3
Relevant Packages:
  next: 16.1.1-canary.32 // Latest available version is detected (16.1.1-canary.32).
  eslint-config-next: N/A
  react: 19.2.3
  react-dom: 19.2.3
  typescript: 5.9.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

cacheComponents

Which stage(s) are affected? (Select all that apply)

next dev (local), next build (local), next start (local)

Additional context

Attached github has the repro and the two non-repros discussed above.

I will go deep in temporal-polyfill and see if it's patchable there (or just understand why it's occurring too).

extent analysis

TL;DR

The most likely fix is to allowlist the Temporal.Instant.from(<iso>) path or modify the temporal-polyfill to avoid using new Date() internally.

Guidance

  • Investigate the temporal-polyfill code to understand why new Date() is being used internally and consider patching it to avoid this issue.
  • As a temporary workaround, use the existing workaround in production: creating via new Date(<iso>).toTemporalInstant().
  • Consider moving the expression into a Client Component or Cache Component to avoid the issue altogether.
  • Review the Next.js documentation on Server Components to understand the limitations and potential solutions.

Example

No code snippet is provided as the issue is related to the internal implementation of the temporal-polyfill library.

Notes

The issue is specific to the temporal-polyfill library and its interaction with Next.js Server Components. The workaround provided in the issue can be used temporarily, but a more permanent solution would require modifying the temporal-polyfill library or allowing the specific path to be allowlisted.

Recommendation

Apply the workaround by using new Date(<iso>).toTemporalInstant() until a more permanent solution can be found, as it is a safe and working alternative.

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