-
Notifications
You must be signed in to change notification settings - Fork 91
Description
Notes:
-
Date
is being patched in https://github.com/vercel/next.js/blob/b1e2dc2ad52e0447aad9d567074b1ceb56368e4c/packages/next/src/server/node-environment-extensions/date.tsxWhen
cacheComponents
are enabled, someDate
usage is treated as dynamic bailout. -
console.*
methods are being patched by AWS lambda to include timestamp -
If any logs are produced while rendering static portion of the page, whole rendering fails with 500 and this error https://nextjs.org/docs/messages/next-prerender-current-time
Above can be reproduced by running this test https://github.com/vercel/next.js/blob/b1e2dc2ad52e0447aad9d567074b1ceb56368e4c/test/e2e/app-dir/cache-components-allow-otel-spans/cache-components-allow-otel-spans.test.ts#L263 and in particular this step https://github.com/vercel/next.js/blob/b1e2dc2ad52e0447aad9d567074b1ceb56368e4c/test/e2e/app-dir/cache-components-allow-otel-spans/cache-components-allow-otel-spans.test.ts#L290 which does result in Next.js printing a warning with console.error
(this on itself is not fatal error and rather a warning):
Sep 12, 11:22:52 AM: 5308d983 ERROR A Cache Function (`use cache`) was passed to startActiveSpan which means it will receive a Span argument with a possibly random ID on every invocation leading to cache misses. Provide a wrapping function around the Cache Function that does not forward the Span argument to avoid this issue.
Log line being prefixed with timestamp that was generated with help of new Date()
which Next.js interpret as using something dynamic while rendering cacheable and throwing https://nextjs.org/docs/messages/next-prerender-current-time fatal error and responding with 500 response
Sep 12, 11:22:52 AM: 5308d983 ERROR Error: Route "/[slug]/server" used `new Date()` instead of using `performance` or without explicitly calling `await connection()` beforehand. See more info here: https://nextjs.org/docs/messages/next-prerender-current-time
at <unknown> (../runtime/index.mjs:612:20)
at console.error (../runtime/index.mjs:684:11) <- This is AWS Lambda Runtime patching console.* method, it's not Netlify doing that
at <unknown> (.next/server/app/[slug]/fallback/page.js:86:23)
at Inner (.next/server/app/[slug]/fallback/page.js:177:30)
at stringify (<anonymous>)
Sep 12, 11:22:52 AM: 5308d983 ERROR To get a more detailed stack trace and pinpoint the issue, try one of the following:
- Start the app in development mode by running `next dev`, then open "/[slug]/server" in your browser to investigate the error.
- Rerun the production build with `next build --debug-prerender` to generate better stack traces.
Sep 12, 11:22:52 AM: 5308d983 ERROR Error:
at async doRender (.next/server/app/[slug]/server/page.js:832:28) {
code: 'NEXT_STATIC_GEN_BAILOUT'
}
Here's a workaround that "fixes" the problem https://github.com/opennextjs/opennextjs-netlify/compare/workaround-date-cache-components by changing next-runtime's internal use of Date
as well as hacks to prevent logs in AWS Lambda Runtime hit this case. But this is all very hacky. This was also reported upstream in vercel/next.js#83795 - ideally there are some changes in Next.js in handling so it doesn't leak so much.
Data
The following is parsed automatically by the Next.js repo e2e test report generator.
test: hello-world should allow creating Spans during prerendering at runtime - inside a Cache Components
reason: [cache-components] console.*
calls result in https://nextjs.org/docs/messages/next-prerender-current-time errors