Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions packages/next/src/server/after/after-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,19 @@ export class AfterContext {
// after(() => x())
// after(x())
// await x()
const wrappedCallback = bindSnapshot(async () => {
try {
await afterTaskAsyncStorage.run({ rootTaskSpawnPhase }, () =>
callback()
)
} catch (error) {
this.reportTaskError('function', error)
const wrappedCallback = bindSnapshot(
// WARNING: Don't make this a named function. It must be anonymous.
// See: https://github.com/facebook/react/pull/34911
async () => {
try {
await afterTaskAsyncStorage.run({ rootTaskSpawnPhase }, () =>
callback()
)
} catch (error) {
this.reportTaskError('function', error)
}
}
})
)

this.callbackQueue.add(wrappedCallback)
}
Expand Down
5 changes: 4 additions & 1 deletion packages/next/src/server/app-render/async-local-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ export function createAsyncLocalStorage<
return new FakeAsyncLocalStorage()
}

export function bindSnapshot<T>(fn: T): T {
export function bindSnapshot<T>(
// WARNING: Don't pass a named function to this argument! See: https://github.com/facebook/react/pull/34911
fn: T
): T {
if (maybeGlobalAsyncLocalStorage) {
return maybeGlobalAsyncLocalStorage.bind(fn)
}
Expand Down
Loading