Skip to content

Commit

Permalink
[Fizz] Only compute component stacks in DEV and prerenders (#27850)
Browse files Browse the repository at this point in the history
If you have a lot of intentional throws (or postpones) from client-only
rendering then computing the stack is too much.

DiffTrain build for [c5b9375](c5b9375)
  • Loading branch information
sebmarkbage committed Dec 19, 2023
1 parent beb4a4d commit f2094ee
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 75 deletions.
2 changes: 1 addition & 1 deletion compiled/facebook-www/REVISION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
cb2439624f43c510007f65aea5c50a8bb97917e4
c5b9375767e2c4102d7e5559d383523736f1c902
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ if (__DEV__) {
) {
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
}
var ReactVersion = "18.3.0-www-modern-2525a22c";
var ReactVersion = "18.3.0-www-modern-b06e722a";

// ATTENTION
// When adding new symbols to this file,
Expand Down
23 changes: 13 additions & 10 deletions compiled/facebook-www/ReactDOMServer-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ if (__DEV__) {
var React = require("react");
var ReactDOM = require("react-dom");

var ReactVersion = "18.3.0-www-classic-806ab62c";
var ReactVersion = "18.3.0-www-classic-350ad947";

// This refers to a WWW module.
var warningWWW = require("warning");
Expand Down Expand Up @@ -11034,8 +11034,11 @@ if (__DEV__) {
// of the request is less critical than the observability of the execution. For renders and resumes however we
// prioritize speed of the request.

function getThrownInfo(node) {
if (node) {
function getThrownInfo(request, node) {
if (
node && // Always produce a stack in dev
true
) {
return {
componentStack: getStackFromNode(node)
};
Expand Down Expand Up @@ -11212,7 +11215,7 @@ if (__DEV__) {
} catch (error) {
contentRootSegment.status = ERRORED;
newBoundary.status = CLIENT_RENDERED;
var thrownInfo = getThrownInfo(task.componentStack);
var thrownInfo = getThrownInfo(request, task.componentStack);
var errorDigest;

{
Expand Down Expand Up @@ -11354,7 +11357,7 @@ if (__DEV__) {
}
} catch (error) {
resumedBoundary.status = CLIENT_RENDERED;
var thrownInfo = getThrownInfo(task.componentStack);
var thrownInfo = getThrownInfo(request, task.componentStack);
var errorDigest;

{
Expand Down Expand Up @@ -12272,7 +12275,7 @@ if (__DEV__) {
// replay nodes which might be Suspense boundaries which are able to
// absorb the error and we can still continue with siblings.

var thrownInfo = getThrownInfo(task.componentStack);
var thrownInfo = getThrownInfo(request, task.componentStack);
erroredReplay(
request,
task.blockedBoundary,
Expand Down Expand Up @@ -12621,7 +12624,7 @@ if (__DEV__) {
// absorb the error and we can still continue with siblings.
// This is an error, stash the component stack if it is null.

var thrownInfo = getThrownInfo(task.componentStack);
var thrownInfo = getThrownInfo(request, task.componentStack);
erroredReplay(
request,
task.blockedBoundary,
Expand Down Expand Up @@ -13117,7 +13120,7 @@ if (__DEV__) {
boundary.status = CLIENT_RENDERED; // We construct an errorInfo from the boundary's componentStack so the error in dev will indicate which
// boundary the message is referring to

var _errorInfo = getThrownInfo(task.componentStack);
var _errorInfo = getThrownInfo(request, task.componentStack);

var _errorDigest = logRecoverableError(request, error, _errorInfo);

Expand Down Expand Up @@ -13402,7 +13405,7 @@ if (__DEV__) {
}
}

var errorInfo = getThrownInfo(task.componentStack);
var errorInfo = getThrownInfo(request, task.componentStack);
task.abortSet.delete(task);
segment.status = ERRORED;
erroredTask(request, task.blockedBoundary, x, errorInfo);
Expand Down Expand Up @@ -13487,7 +13490,7 @@ if (__DEV__) {

task.replay.pendingTasks--;
task.abortSet.delete(task);
var errorInfo = getThrownInfo(task.componentStack);
var errorInfo = getThrownInfo(request, task.componentStack);
erroredReplay(
request,
task.blockedBoundary,
Expand Down
23 changes: 13 additions & 10 deletions compiled/facebook-www/ReactDOMServer-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ if (__DEV__) {
var React = require("react");
var ReactDOM = require("react-dom");

var ReactVersion = "18.3.0-www-modern-50304adb";
var ReactVersion = "18.3.0-www-modern-73b83dcd";

// This refers to a WWW module.
var warningWWW = require("warning");
Expand Down Expand Up @@ -10773,8 +10773,11 @@ if (__DEV__) {
// of the request is less critical than the observability of the execution. For renders and resumes however we
// prioritize speed of the request.

function getThrownInfo(node) {
if (node) {
function getThrownInfo(request, node) {
if (
node && // Always produce a stack in dev
true
) {
return {
componentStack: getStackFromNode(node)
};
Expand Down Expand Up @@ -10951,7 +10954,7 @@ if (__DEV__) {
} catch (error) {
contentRootSegment.status = ERRORED;
newBoundary.status = CLIENT_RENDERED;
var thrownInfo = getThrownInfo(task.componentStack);
var thrownInfo = getThrownInfo(request, task.componentStack);
var errorDigest;

{
Expand Down Expand Up @@ -11093,7 +11096,7 @@ if (__DEV__) {
}
} catch (error) {
resumedBoundary.status = CLIENT_RENDERED;
var thrownInfo = getThrownInfo(task.componentStack);
var thrownInfo = getThrownInfo(request, task.componentStack);
var errorDigest;

{
Expand Down Expand Up @@ -12000,7 +12003,7 @@ if (__DEV__) {
// replay nodes which might be Suspense boundaries which are able to
// absorb the error and we can still continue with siblings.

var thrownInfo = getThrownInfo(task.componentStack);
var thrownInfo = getThrownInfo(request, task.componentStack);
erroredReplay(
request,
task.blockedBoundary,
Expand Down Expand Up @@ -12349,7 +12352,7 @@ if (__DEV__) {
// absorb the error and we can still continue with siblings.
// This is an error, stash the component stack if it is null.

var thrownInfo = getThrownInfo(task.componentStack);
var thrownInfo = getThrownInfo(request, task.componentStack);
erroredReplay(
request,
task.blockedBoundary,
Expand Down Expand Up @@ -12845,7 +12848,7 @@ if (__DEV__) {
boundary.status = CLIENT_RENDERED; // We construct an errorInfo from the boundary's componentStack so the error in dev will indicate which
// boundary the message is referring to

var _errorInfo = getThrownInfo(task.componentStack);
var _errorInfo = getThrownInfo(request, task.componentStack);

var _errorDigest = logRecoverableError(request, error, _errorInfo);

Expand Down Expand Up @@ -13130,7 +13133,7 @@ if (__DEV__) {
}
}

var errorInfo = getThrownInfo(task.componentStack);
var errorInfo = getThrownInfo(request, task.componentStack);
task.abortSet.delete(task);
segment.status = ERRORED;
erroredTask(request, task.blockedBoundary, x, errorInfo);
Expand Down Expand Up @@ -13215,7 +13218,7 @@ if (__DEV__) {

task.replay.pendingTasks--;
task.abortSet.delete(task);
var errorInfo = getThrownInfo(task.componentStack);
var errorInfo = getThrownInfo(request, task.componentStack);
erroredReplay(
request,
task.blockedBoundary,
Expand Down
42 changes: 27 additions & 15 deletions compiled/facebook-www/ReactDOMServer-prod.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -3550,24 +3550,24 @@ function createPendingSegment(
function createBuiltInComponentStack(task, type) {
return { tag: 0, parent: task.componentStack, type: type };
}
function getThrownInfo(node) {
if (node) {
function getThrownInfo(request, node) {
if (node && null !== request.trackedPostpones) {
try {
var info = "";
request = "";
do {
switch (node.tag) {
case 0:
info += describeBuiltInComponentFrame(node.type, null, null);
request += describeBuiltInComponentFrame(node.type, null, null);
break;
case 1:
info += describeNativeComponentFrame(node.type, !1);
request += describeNativeComponentFrame(node.type, !1);
break;
case 2:
info += describeNativeComponentFrame(node.type, !0);
request += describeNativeComponentFrame(node.type, !0);
}
node = node.parent;
} while (node);
var JSCompiler_temp = info;
var JSCompiler_temp = request;
} catch (x) {
JSCompiler_temp =
"\nError generating stack: " + x.message + "\n" + x.stack;
Expand Down Expand Up @@ -3972,7 +3972,10 @@ function renderElement(
} catch (error) {
(contentRootSegment.status = 4),
(ref.status = 4),
(previousComponentStack = getThrownInfo(task.componentStack)),
(previousComponentStack = getThrownInfo(
request,
task.componentStack
)),
(JSCompiler_inline_result = logRecoverableError(
request,
error,
Expand Down Expand Up @@ -4235,7 +4238,7 @@ function renderNodeDestructive(
)
throw (task.node === node && (task.replay = replay), x);
task.replay.pendingTasks--;
props = getThrownInfo(task.componentStack);
props = getThrownInfo(request, task.componentStack);
key = request;
request = task.blockedBoundary;
prevThenableState = x;
Expand Down Expand Up @@ -4311,7 +4314,10 @@ function renderNodeDestructive(
}
} catch (error) {
(resumedBoundary.status = 4),
(childNodes = getThrownInfo(task.componentStack)),
(childNodes = getThrownInfo(
request,
task.componentStack
)),
(replay = logRecoverableError(
request,
error,
Expand Down Expand Up @@ -4475,7 +4481,7 @@ function renderChildrenArray(request, task, children, childIndex) {
)
throw x;
task.replay.pendingTasks--;
children = getThrownInfo(task.componentStack);
children = getThrownInfo(request, task.componentStack);
var boundary = task.blockedBoundary,
error = x;
children = logRecoverableError(request, error, children);
Expand Down Expand Up @@ -4714,7 +4720,7 @@ function abortTask(task, request, error) {
boundary.pendingTasks--,
4 !== boundary.status &&
((boundary.status = 4),
(task = getThrownInfo(task.componentStack)),
(task = getThrownInfo(request, task.componentStack)),
(task = logRecoverableError(request, error, task)),
(boundary.errorDigest = task),
boundary.parentFlushed &&
Expand Down Expand Up @@ -4911,7 +4917,10 @@ function performWork(request$jscomp$2) {
} else {
task.replay.pendingTasks--;
task.abortSet.delete(task);
var errorInfo = getThrownInfo(task.componentStack);
var errorInfo = getThrownInfo(
request$jscomp$0,
task.componentStack
);
request = void 0;
var request$jscomp$1 = request$jscomp$0,
boundary = task.blockedBoundary,
Expand Down Expand Up @@ -4984,7 +4993,10 @@ function performWork(request$jscomp$2) {
x$jscomp$0.then(ping$jscomp$0, ping$jscomp$0);
task.thenableState = getThenableStateAfterSuspending();
} else {
var errorInfo$jscomp$0 = getThrownInfo(task.componentStack);
var errorInfo$jscomp$0 = getThrownInfo(
request,
task.componentStack
);
task.abortSet.delete(task);
request$jscomp$1.status = 4;
var boundary$jscomp$0 = task.blockedBoundary;
Expand Down Expand Up @@ -5652,4 +5664,4 @@ exports.renderToString = function (children, options) {
'The server used "renderToString" which does not support Suspense. If you intended for this Suspense boundary to render the fallback content on the server consider throwing an Error somewhere within the Suspense boundary. If you intended to have the server wait for the suspended component please switch to "renderToReadableStream" which supports Suspense on the server'
);
};
exports.version = "18.3.0-www-classic-1005353c";
exports.version = "18.3.0-www-classic-ef6a5528";
Loading

0 comments on commit f2094ee

Please sign in to comment.