Files
Josh StoryandGitHub a0e5996f0a [Cache Components] Allow sync IO inside console methods (#83843)
console methods may be patched to do things like add a timestamp to the
log row. While we can't determine the meaning of reading the current
time in arbitrary contexts we can know with reasonable certainty that
any sync IO inside a console method is not being used in the logical
output of the program. To account for this we can make a special
affordance for sync IO inside of these methods that allows them to run
without interrupting the prerender early.

To do this we patch these properties on the console global and set up a
wrapper in the setter. This wrapper will make any assigned function into
another function that exits the `workUnitAsyncStorage` scope before
executing the wrapped function. This will allow `new Date()` and other
sync IO APIs to be called in the internal implementation of these
methods without triggering an error while prerendering.

Fixes NAR-403
2025-09-18 08:23:56 -07:00

13 lines
477 B
TypeScript

export default async function Page() {
console.log('This is a console log from a server component page')
return (
<div>
This page uses a console.log that has been patched before Next.js runs to
include a timestamp in the log line. It does not actually print the
timestamp because we want the assertions to be stable but we are asserting
that this sync IO does not interrupt the prerender when Cache Components
are enabled
</div>
)
}