Skip to content

Commit 5a4c295

Browse files
authored
[Cache Components] Dim logs after prerender aborts (#84153)
When prerenders abort we reject hanging promises so resources can clean up. This can lead to user code which logs errors from rejections reporting many more errors than expected and these logs are for semantically irrelevant errors. To make it clearer that these errors are not semantically relevant we will dim them. This is a partial solution because 3rd party loggers will not necessarily interpret this and so these logs might continue to show up as normal logs in donwstream systems. We may need to ask that consumers of these logs interpret the dimmed nature and convey this status to the viewer. We will follow up this work with a config that allows you to hide logs from aborted prerenders. This will completely suppress their emission to the underlying log system but it will run after any userland patches so you could still end up reporting errors for instance to an otel collector because the filtering would be applied after not before. The right way to solve this is for the log to check if there is a react cacheSignal that is aborted and do their own suppresion.
1 parent c781f40 commit 5a4c295

File tree

18 files changed

+1457
-309
lines changed

18 files changed

+1457
-309
lines changed

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
"packages/next/src/server/app-render/dynamic-access-async-storage-instance.ts",
6363
"packages/next/src/server/app-render/work-async-storage-instance.ts",
6464
"packages/next/src/server/app-render/work-unit-async-storage-instance.ts",
65-
"packages/next/src/server/app-render/dev-logs-async-storage-instance.ts",
65+
"packages/next/src/server/app-render/console-async-storage-instance.ts",
6666
"packages/next/src/client/components/segment-cache-impl/*"
6767
],
6868
// Disable TypeScript surveys.

packages/next/src/server/app-render/app-render.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ import {
174174
workUnitAsyncStorage,
175175
type PrerenderStore,
176176
} from './work-unit-async-storage.external'
177-
import { devLogsAsyncStorage } from './dev-logs-async-storage.external'
177+
import { consoleAsyncStorage } from './console-async-storage.external'
178178
import { CacheSignal } from './cache-signal'
179179
import { getTracedMetadata } from '../lib/trace/utils'
180180
import { InvariantError } from '../../shared/lib/invariant-error'
@@ -2309,7 +2309,7 @@ async function renderToStream(
23092309
}
23102310
)
23112311

2312-
devLogsAsyncStorage.run(
2312+
consoleAsyncStorage.run(
23132313
{ dim: true },
23142314
spawnDynamicValidationInDev,
23152315
resolveValidation,
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { createAsyncLocalStorage } from './async-local-storage'
2+
import type { ConsoleAsyncStorage } from './console-async-storage.external'
3+
4+
export const consoleAsyncStorageInstance: ConsoleAsyncStorage =
5+
createAsyncLocalStorage()
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import type { AsyncLocalStorage } from 'async_hooks'
22

33
// Share the instance module in the next-shared layer
4-
import { devLogsAsyncStorageInstance } from './dev-logs-async-storage-instance' with { 'turbopack-transition': 'next-shared' }
4+
import { consoleAsyncStorageInstance } from './console-async-storage-instance' with { 'turbopack-transition': 'next-shared' }
55

6-
export interface DevLogsStore {
6+
export interface ConsoleStore {
77
/**
88
* if true the color of logs output will be dimmed to indicate the log is
99
* from a repeat or validation render that is not typically relevant to
@@ -12,6 +12,6 @@ export interface DevLogsStore {
1212
readonly dim: boolean
1313
}
1414

15-
export type DevLogsAsyncStorage = AsyncLocalStorage<DevLogsStore>
15+
export type ConsoleAsyncStorage = AsyncLocalStorage<ConsoleStore>
1616

17-
export { devLogsAsyncStorageInstance as devLogsAsyncStorage }
17+
export { consoleAsyncStorageInstance as consoleAsyncStorage }

packages/next/src/server/app-render/dev-logs-async-storage-instance.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

packages/next/src/server/node-environment-extensions/console-dev.tsx

Lines changed: 0 additions & 206 deletions
This file was deleted.

0 commit comments

Comments
 (0)