lighter icon indicating copy to clipboard operation
lighter copied to clipboard

Usage of Date.now() causing issues with Next.js 16 CacheComponents

Open Jacob-Roberts opened this issue 1 month ago • 1 comments

When rendering <Code> in a server component, with cacheComponents enabled, I get this error

Error: Route "/blog/[slug]" used Date.now() 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

It looks like the cache components mechanism is causing issues with the checks for performance.now and it is falling back to use Date.now

Jacob-Roberts avatar Nov 15 '25 07:11 Jacob-Roberts

I've got a PR in place that will fix this. https://github.com/code-hike/lighter/pull/52

Jacob-Roberts avatar Nov 15 '25 08:11 Jacob-Roberts

As a workaround, I've published @autovation/bright that has these changes in place

Jacob-Roberts avatar Nov 26 '25 23:11 Jacob-Roberts