Skip to content

Commit d06d633

Browse files
committed
[Fizz] Prevent uncloned large precomputed chunks without relying on render-time assertions (#28568)
A while back we implemented a heuristic that if a chunk was large it was assumed to be produced by the render and thus was safe to stream which results in transferring the underlying object memory. Later we ran into an issue where a precomputed chunk grew large enough to trigger this hueristic and it started causing renders to fail because once a second render had occurred the precomputed chunk would not have an underlying buffer of bytes to send and these bytes would be omitted from the stream. We implemented a technique to detect large precomputed chunks and we enforced that these always be cloned before writing. Unfortunately our test coverage was not perfect and there has been for a very long time now a usage pattern where if you complete a boundary in one flush and then complete a boundary that has stylehsheet dependencies in another flush you can get a large precomputed chunk that was not being cloned to be sent twice causing streaming errors. I've thought about why we even went with this solution in the first place and I think it was a mistake. It relies on a dev only check to catch paired with potentially version specific order of operations on the streaming side. This is too unreliable. Additionally the low limit of view size for Edge is not used in Node.js but there is not real justification for this. In this change I updated the view size for edge streaming to match Node at 2048 bytes which is still relatively small and we have no data one way or another to preference 512 over this. Then I updated the assertion logic to error anytime a precomputed chunk exceeds the size. This eliminates the need to clone these chunks by just making sure our view size is always larger than the largest precomputed chunk we can possibly write. I'm generally in favor of this for a few reasons. First, we'll always know during testing whether we've violated the limit as long as we exercise each stream config because the precomputed chunks are created in module scope. Second, we can always split up large chunks so making sure the precomptued chunk is smaller than whatever view size we actually desire is relatively trivial. DiffTrain build for [b09e102](b09e102)
1 parent cb7bf99 commit d06d633

6 files changed

+8
-26
lines changed

compiled/facebook-www/REVISION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
a870b2d5494351d75b68c3d9baf03a52fd40a8ef
1+
b09e102ff1e2aaaf5eb6585b04609ac7ff54a5c8

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,4 +625,4 @@ exports.useSyncExternalStore = function (
625625
exports.useTransition = function () {
626626
return ReactCurrentDispatcher.current.useTransition();
627627
};
628-
exports.version = "18.3.0-www-modern-26dfe226";
628+
exports.version = "18.3.0-www-modern-94e2c94e";

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

Lines changed: 2 additions & 8 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-3a1cc8c2";
22+
var ReactVersion = "18.3.0-www-classic-c69e4b0a";
2323

2424
// This refers to a WWW module.
2525
var warningWWW = require("warning");
@@ -548,9 +548,6 @@ if (__DEV__) {
548548
function stringToPrecomputedChunk(content) {
549549
return content;
550550
}
551-
function clonePrecomputedChunk(chunk) {
552-
return chunk;
553-
}
554551
function closeWithError(destination, error) {
555552
// $FlowFixMe[incompatible-call]: This is an Error object or the destination accepts other types.
556553
destination.destroy(error);
@@ -6422,10 +6419,7 @@ if (__DEV__) {
64226419
) {
64236420
resumableState.instructions |=
64246421
SentStyleInsertionFunction | SentCompleteBoundaryFunction;
6425-
writeChunk(
6426-
destination,
6427-
clonePrecomputedChunk(completeBoundaryWithStylesScript1FullBoth)
6428-
);
6422+
writeChunk(destination, completeBoundaryWithStylesScript1FullBoth);
64296423
} else if (
64306424
(resumableState.instructions & SentStyleInsertionFunction) ===
64316425
NothingSent

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

Lines changed: 2 additions & 8 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-7205a424";
22+
var ReactVersion = "18.3.0-www-modern-ac7e39a5";
2323

2424
// This refers to a WWW module.
2525
var warningWWW = require("warning");
@@ -548,9 +548,6 @@ if (__DEV__) {
548548
function stringToPrecomputedChunk(content) {
549549
return content;
550550
}
551-
function clonePrecomputedChunk(chunk) {
552-
return chunk;
553-
}
554551
function closeWithError(destination, error) {
555552
// $FlowFixMe[incompatible-call]: This is an Error object or the destination accepts other types.
556553
destination.destroy(error);
@@ -6422,10 +6419,7 @@ if (__DEV__) {
64226419
) {
64236420
resumableState.instructions |=
64246421
SentStyleInsertionFunction | SentCompleteBoundaryFunction;
6425-
writeChunk(
6426-
destination,
6427-
clonePrecomputedChunk(completeBoundaryWithStylesScript1FullBoth)
6428-
);
6422+
writeChunk(destination, completeBoundaryWithStylesScript1FullBoth);
64296423
} else if (
64306424
(resumableState.instructions & SentStyleInsertionFunction) ===
64316425
NothingSent

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -544,9 +544,6 @@ if (__DEV__) {
544544
function stringToPrecomputedChunk(content) {
545545
return content;
546546
}
547-
function clonePrecomputedChunk(chunk) {
548-
return chunk;
549-
}
550547
function closeWithError(destination, error) {
551548
destination.done = true;
552549
destination.fatal = true;
@@ -6418,10 +6415,7 @@ if (__DEV__) {
64186415
) {
64196416
resumableState.instructions |=
64206417
SentStyleInsertionFunction | SentCompleteBoundaryFunction;
6421-
writeChunk(
6422-
destination,
6423-
clonePrecomputedChunk(completeBoundaryWithStylesScript1FullBoth)
6424-
);
6418+
writeChunk(destination, completeBoundaryWithStylesScript1FullBoth);
64256419
} else if (
64266420
(resumableState.instructions & SentStyleInsertionFunction) ===
64276421
NothingSent

compiled/facebook-www/__test_utils__/ReactAllWarnings.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)