Skip to content

Commit cecbf4f

Browse files
committed
[Fizz] handle errors in onHeaders (#27712)
`onHeaders` can throw however for now we can assume that headers are optimistic values since the only things we produce for them are preload links. This is a pragmatic decision because React could concievably have headers in the future which were not optimistic and thus non-optional however it is hard to imagine what these headers might be in practice. If we need to change this behavior to be fatal in the future it would be a breaking change. This commit adds error logging when `onHeaders` throws and ensures the request can continue to render successfully. DiffTrain build for [ee68446](ee68446)
1 parent 9e50f2a commit cecbf4f

9 files changed

+298
-284
lines changed

compiled/facebook-www/REVISION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
593ecee66a609d4a4c2b36b39b1e5e23b2456dd1
1+
ee68446ff198755bd38202ac9139275b657968b0

compiled/facebook-www/ReactART-dev.modern.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ if (__DEV__) {
6666
return self;
6767
}
6868

69-
var ReactVersion = "18.3.0-www-modern-7ac3e370";
69+
var ReactVersion = "18.3.0-www-modern-b8021dcf";
7070

7171
var LegacyRoot = 0;
7272
var ConcurrentRoot = 1;

compiled/facebook-www/ReactART-prod.modern.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9905,7 +9905,7 @@ var slice = Array.prototype.slice,
99059905
return null;
99069906
},
99079907
bundleType: 0,
9908-
version: "18.3.0-www-modern-fc53dc79",
9908+
version: "18.3.0-www-modern-88df5dd9",
99099909
rendererPackageName: "react-art"
99109910
};
99119911
var internals$jscomp$inline_1302 = {
@@ -9936,7 +9936,7 @@ var internals$jscomp$inline_1302 = {
99369936
scheduleRoot: null,
99379937
setRefreshHandler: null,
99389938
getCurrentFiber: null,
9939-
reconcilerVersion: "18.3.0-www-modern-fc53dc79"
9939+
reconcilerVersion: "18.3.0-www-modern-88df5dd9"
99409940
};
99419941
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
99429942
var hook$jscomp$inline_1303 = __REACT_DEVTOOLS_GLOBAL_HOOK__;

compiled/facebook-www/ReactDOMServer-dev.classic.js

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ if (__DEV__) {
1919
var React = require("react");
2020
var ReactDOM = require("react-dom");
2121

22-
var ReactVersion = "18.3.0-www-classic-deec0503";
22+
var ReactVersion = "18.3.0-www-classic-e27c8048";
2323

2424
// This refers to a WWW module.
2525
var warningWWW = require("warning");
@@ -7698,6 +7698,9 @@ if (__DEV__) {
76987698
var headers = renderState.headers;
76997699

77007700
if (headers) {
7701+
// Even if onHeaders throws we don't want to call this again so
7702+
// we drop the headers state from this point onwards.
7703+
renderState.headers = null;
77017704
var linkHeader = headers.preconnects;
77027705

77037706
if (headers.fontPreloads) {
@@ -7780,7 +7783,6 @@ if (__DEV__) {
77807783
onHeaders({});
77817784
}
77827785

7783-
renderState.headers = null;
77847786
return;
77857787
}
77867788
}
@@ -13219,6 +13221,19 @@ if (__DEV__) {
1321913221
if (request.allPendingTasks === 0) {
1322013222
completeAll(request);
1322113223
}
13224+
}
13225+
13226+
function safelyEmitEarlyPreloads(request, shellComplete) {
13227+
try {
13228+
emitEarlyPreloads(
13229+
request.renderState,
13230+
request.resumableState,
13231+
shellComplete
13232+
);
13233+
} catch (error) {
13234+
// We assume preloads are optimistic and thus non-fatal if errored.
13235+
logRecoverableError(request, error);
13236+
}
1322213237
} // I extracted this function out because we want to ensure we consistently emit preloads before
1322313238
// transitioning to the next request stage and this transition can happen in multiple places in this
1322413239
// implementation.
@@ -13231,11 +13246,7 @@ if (__DEV__) {
1323113246
// we should only be calling completeShell when the shell is complete so we
1323213247
// just use a literal here
1323313248
var shellComplete = true;
13234-
emitEarlyPreloads(
13235-
request.renderState,
13236-
request.resumableState,
13237-
shellComplete
13238-
);
13249+
safelyEmitEarlyPreloads(request, shellComplete);
1323913250
} // We have completed the shell so the shell can't error anymore.
1324013251

1324113252
request.onShellError = noop;
@@ -13255,11 +13266,7 @@ if (__DEV__) {
1325513266
? true // Prerender Request, we use the state of the root segment
1325613267
: request.completedRootSegment === null ||
1325713268
request.completedRootSegment.status !== POSTPONED;
13258-
emitEarlyPreloads(
13259-
request.renderState,
13260-
request.resumableState,
13261-
shellComplete
13262-
);
13269+
safelyEmitEarlyPreloads(request, shellComplete);
1326313270
var onAllReady = request.onAllReady;
1326413271
onAllReady();
1326513272
}
@@ -14102,11 +14109,7 @@ if (__DEV__) {
1410214109

1410314110
function enqueueEarlyPreloadsAfterInitialWork(request) {
1410414111
var shellComplete = request.pendingRootTasks === 0;
14105-
emitEarlyPreloads(
14106-
request.renderState,
14107-
request.resumableState,
14108-
shellComplete
14109-
);
14112+
safelyEmitEarlyPreloads(request, shellComplete);
1411014113
}
1411114114

1411214115
function enqueueFlush(request) {

compiled/facebook-www/ReactDOMServer-dev.modern.js

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ if (__DEV__) {
1919
var React = require("react");
2020
var ReactDOM = require("react-dom");
2121

22-
var ReactVersion = "18.3.0-www-modern-7ac3e370";
22+
var ReactVersion = "18.3.0-www-modern-b8021dcf";
2323

2424
// This refers to a WWW module.
2525
var warningWWW = require("warning");
@@ -7698,6 +7698,9 @@ if (__DEV__) {
76987698
var headers = renderState.headers;
76997699

77007700
if (headers) {
7701+
// Even if onHeaders throws we don't want to call this again so
7702+
// we drop the headers state from this point onwards.
7703+
renderState.headers = null;
77017704
var linkHeader = headers.preconnects;
77027705

77037706
if (headers.fontPreloads) {
@@ -7780,7 +7783,6 @@ if (__DEV__) {
77807783
onHeaders({});
77817784
}
77827785

7783-
renderState.headers = null;
77847786
return;
77857787
}
77867788
}
@@ -12947,6 +12949,19 @@ if (__DEV__) {
1294712949
if (request.allPendingTasks === 0) {
1294812950
completeAll(request);
1294912951
}
12952+
}
12953+
12954+
function safelyEmitEarlyPreloads(request, shellComplete) {
12955+
try {
12956+
emitEarlyPreloads(
12957+
request.renderState,
12958+
request.resumableState,
12959+
shellComplete
12960+
);
12961+
} catch (error) {
12962+
// We assume preloads are optimistic and thus non-fatal if errored.
12963+
logRecoverableError(request, error);
12964+
}
1295012965
} // I extracted this function out because we want to ensure we consistently emit preloads before
1295112966
// transitioning to the next request stage and this transition can happen in multiple places in this
1295212967
// implementation.
@@ -12959,11 +12974,7 @@ if (__DEV__) {
1295912974
// we should only be calling completeShell when the shell is complete so we
1296012975
// just use a literal here
1296112976
var shellComplete = true;
12962-
emitEarlyPreloads(
12963-
request.renderState,
12964-
request.resumableState,
12965-
shellComplete
12966-
);
12977+
safelyEmitEarlyPreloads(request, shellComplete);
1296712978
} // We have completed the shell so the shell can't error anymore.
1296812979

1296912980
request.onShellError = noop;
@@ -12983,11 +12994,7 @@ if (__DEV__) {
1298312994
? true // Prerender Request, we use the state of the root segment
1298412995
: request.completedRootSegment === null ||
1298512996
request.completedRootSegment.status !== POSTPONED;
12986-
emitEarlyPreloads(
12987-
request.renderState,
12988-
request.resumableState,
12989-
shellComplete
12990-
);
12997+
safelyEmitEarlyPreloads(request, shellComplete);
1299112998
var onAllReady = request.onAllReady;
1299212999
onAllReady();
1299313000
}
@@ -13830,11 +13837,7 @@ if (__DEV__) {
1383013837

1383113838
function enqueueEarlyPreloadsAfterInitialWork(request) {
1383213839
var shellComplete = request.pendingRootTasks === 0;
13833-
emitEarlyPreloads(
13834-
request.renderState,
13835-
request.resumableState,
13836-
shellComplete
13837-
);
13840+
safelyEmitEarlyPreloads(request, shellComplete);
1383813841
}
1383913842

1384013843
function enqueueFlush(request) {

0 commit comments

Comments
 (0)