@@ -22,6 +22,7 @@ import { configureUseCacheHandlers } from './use-cache-handler.js'
2222import { setupWaitUntil } from './wait-until.cjs'
2323// make use of global fetch before Next.js applies any patching
2424setFetchBeforeNextPatchedIt ( globalThis . fetch )
25+ globalThis . DateBeforeNextPatchedIt = Date
2526// configure globals that Next.js make use of before we start importing any Next.js code
2627// as some globals are consumed at import time
2728const { nextConfig : initialNextConfig , enableUseCacheHandler } = await getRunConfig ( )
@@ -35,6 +36,30 @@ const nextImportPromise = import('../next.cjs')
3536
3637let nextHandler : WorkerRequestHandler
3738
39+ // Lambda Runtime patches these methods to include timestamp with `new Date()` which ...
40+ // has tension with https://nextjs.org/docs/messages/next-prerender-current-time
41+ // as this timestamp is NOT impacting Next.js render we temporarily restore original Date
42+ // to not affect Next.js heuristics related to `Date` usage
43+ for ( const consoleMethod of [
44+ 'trace' ,
45+ 'debug' ,
46+ 'info' ,
47+ 'log' ,
48+ 'warn' ,
49+ 'error' ,
50+ // fatal is not console method, but AWS Lambda Runtime adds it
51+ 'fatal' ,
52+ ] as const ) {
53+ const originalMethod = console [ consoleMethod ] . bind ( console )
54+ console [ consoleMethod ] = ( ...args : unknown [ ] ) => {
55+ const patchedDate = Date
56+ Date = DateBeforeNextPatchedIt
57+ const retval = originalMethod ( ...args )
58+ Date = patchedDate
59+ return retval
60+ }
61+ }
62+
3863/**
3964 * When Next.js proxies requests externally, it writes the response back as-is.
4065 * In some cases, this includes Transfer-Encoding: chunked.
0 commit comments