Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Only clear requestStorage if we're in onError/onPostpone
We only clear these to avoid replaying logs from onError on the client.

This doesn't make a difference because we're not clearing currentRequest
for console.error but it should line up.
  • Loading branch information
sebmarkbage committed Jul 4, 2024
commit e2e328c408713fa99735d26ce177bbbf214bad81
43 changes: 26 additions & 17 deletions packages/react-server/src/ReactFlightServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1121,23 +1121,8 @@ function callWithDebugContextInDEV<A, T>(
setCurrentOwner(componentDebugInfo);
try {
if (enableOwnerStacks && debugTask) {
if (supportsRequestStorage) {
// Exit the request context while running callbacks.
return debugTask.run(
// $FlowFixMe[method-unbinding]
requestStorage.run.bind(
requestStorage,
undefined,
callback.bind(null, arg),
),
);
}
return debugTask.run(callback.bind(null, arg));
}
if (supportsRequestStorage) {
// Exit the request context while running callbacks.
return requestStorage.run(undefined, callback, arg);
}
return callback(arg);
} finally {
setCurrentOwner(null);
Expand Down Expand Up @@ -2850,11 +2835,23 @@ function logPostpone(
task: Task | null, // DEV-only
): void {
const prevRequest = currentRequest;
// We clear the request context so that console.logs inside the callback doesn't
// get forwarded to the client.
currentRequest = null;
try {
const onPostpone = request.onPostpone;
if (__DEV__ && task !== null) {
callWithDebugContextInDEV(task, onPostpone, reason);
if (supportsRequestStorage) {
requestStorage.run(
undefined,
callWithDebugContextInDEV,
task,
onPostpone,
reason,
);
} else {
callWithDebugContextInDEV(task, onPostpone, reason);
}
} else if (supportsRequestStorage) {
// Exit the request context while running callbacks.
requestStorage.run(undefined, onPostpone, reason);
Expand All @@ -2872,12 +2869,24 @@ function logRecoverableError(
task: Task | null, // DEV-only
): string {
const prevRequest = currentRequest;
// We clear the request context so that console.logs inside the callback doesn't
// get forwarded to the client.
currentRequest = null;
let errorDigest;
try {
const onError = request.onError;
if (__DEV__ && task !== null) {
errorDigest = callWithDebugContextInDEV(task, onError, error);
if (supportsRequestStorage) {
errorDigest = requestStorage.run(
undefined,
callWithDebugContextInDEV,
task,
onError,
error,
);
} else {
errorDigest = callWithDebugContextInDEV(task, onError, error);
}
} else if (supportsRequestStorage) {
// Exit the request context while running callbacks.
errorDigest = requestStorage.run(undefined, onError, error);
Expand Down