Skip to content

Commit

Permalink
Only clear requestStorage if we're in onError/onPostpone
Browse files Browse the repository at this point in the history
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 3, 2024
1 parent 25ed7a7 commit 06948a6
Showing 1 changed file with 26 additions and 17 deletions.
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

0 comments on commit 06948a6

Please sign in to comment.