Issue involves modifying or allowing a polyfill's internal Date usage in Next.js.
The issue arises because `Temporal.Instant.from` internally uses `new Date()`, triggering Next.js's uncached data access error. The solution likely involves modifying the polyfill or Next.js to handle this case, but depends on external polyfill maintenance.
https://github.com/rikbrown/nextjs-temporal-polyfill-cache-components-issue
next devBasically, 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:
new Date(<iso>).toTemporalInstant() -- this is the workaround for now in productionTemporal.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
Claim this issue to let others know you're working on it. You'll earn 20 points when you complete it!