Skip to content

Commit 40965eb

Browse files
authored
Patch React with fix for write-after-close for ReadableStream (#57011)
1 parent 54145b4 commit 40965eb

34 files changed

+205
-93
lines changed

packages/next/src/compiled/react-dom-experimental/cjs/react-dom-server-legacy.browser.development.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ if (process.env.NODE_ENV !== "production") {
1717
var React = require("next/dist/compiled/react-experimental");
1818
var ReactDOM = require('react-dom');
1919

20-
var ReactVersion = '18.3.0-experimental-d900fadbf-20230929';
20+
var ReactVersion = '18.3.0-experimental-3cfcbc5bc-20231018';
2121

2222
var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
2323

@@ -11264,7 +11264,10 @@ function flushCompletedQueues(request, destination) {
1126411264
} // We're done.
1126511265

1126611266

11267-
close(destination);
11267+
close(destination); // We need to stop flowing now because we do not want any async contexts which might call
11268+
// float methods to initiate any flushes after this point
11269+
11270+
stopFlowing(request);
1126811271
}
1126911272
}
1127011273
}
@@ -11284,10 +11287,17 @@ function enqueueFlush(request) {
1128411287
request.pingedTasks.length === 0 && // If there is no destination there is nothing we can flush to. A flush will
1128511288
// happen when we start flowing again
1128611289
request.destination !== null) {
11287-
var destination = request.destination;
1128811290
request.flushScheduled = true;
1128911291
scheduleWork(function () {
11290-
return flushCompletedQueues(request, destination);
11292+
// We need to existence check destination again here because it might go away
11293+
// in between the enqueueFlush call and the work execution
11294+
var destination = request.destination;
11295+
11296+
if (destination) {
11297+
flushCompletedQueues(request, destination);
11298+
} else {
11299+
request.flushScheduled = false;
11300+
}
1129111301
});
1129211302
}
1129311303
}
@@ -11317,6 +11327,9 @@ function startFlowing(request, destination) {
1131711327
fatalError(request, error);
1131811328
}
1131911329
}
11330+
function stopFlowing(request) {
11331+
request.destination = null;
11332+
} // This is called to early terminate a request. It puts all pending boundaries in client rendered state.
1132011333

1132111334
function abort(request, reason) {
1132211335
try {

packages/next/src/compiled/react-dom-experimental/cjs/react-dom-server-legacy.browser.production.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/next/src/compiled/react-dom-experimental/cjs/react-dom-server-legacy.node.development.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ var React = require("next/dist/compiled/react-experimental");
1818
var ReactDOM = require('react-dom');
1919
var stream = require('stream');
2020

21-
var ReactVersion = '18.3.0-experimental-d900fadbf-20230929';
21+
var ReactVersion = '18.3.0-experimental-3cfcbc5bc-20231018';
2222

2323
var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
2424

@@ -11265,7 +11265,10 @@ function flushCompletedQueues(request, destination) {
1126511265
} // We're done.
1126611266

1126711267

11268-
close(destination);
11268+
close(destination); // We need to stop flowing now because we do not want any async contexts which might call
11269+
// float methods to initiate any flushes after this point
11270+
11271+
stopFlowing(request);
1126911272
}
1127011273
}
1127111274
}
@@ -11285,10 +11288,17 @@ function enqueueFlush(request) {
1128511288
request.pingedTasks.length === 0 && // If there is no destination there is nothing we can flush to. A flush will
1128611289
// happen when we start flowing again
1128711290
request.destination !== null) {
11288-
var destination = request.destination;
1128911291
request.flushScheduled = true;
1129011292
scheduleWork(function () {
11291-
return flushCompletedQueues(request, destination);
11293+
// We need to existence check destination again here because it might go away
11294+
// in between the enqueueFlush call and the work execution
11295+
var destination = request.destination;
11296+
11297+
if (destination) {
11298+
flushCompletedQueues(request, destination);
11299+
} else {
11300+
request.flushScheduled = false;
11301+
}
1129211302
});
1129311303
}
1129411304
}
@@ -11318,6 +11328,9 @@ function startFlowing(request, destination) {
1131811328
fatalError(request, error);
1131911329
}
1132011330
}
11331+
function stopFlowing(request) {
11332+
request.destination = null;
11333+
} // This is called to early terminate a request. It puts all pending boundaries in client rendered state.
1132111334

1132211335
function abort(request, reason) {
1132311336
try {

packages/next/src/compiled/react-dom-experimental/cjs/react-dom-server-legacy.node.production.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/next/src/compiled/react-dom-experimental/cjs/react-dom-server-rendering-stub.development.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ if (process.env.NODE_ENV !== "production") {
1616

1717
var React = require("next/dist/compiled/react-experimental");
1818

19-
var ReactVersion = '18.3.0-experimental-d900fadbf-20230929';
19+
var ReactVersion = '18.3.0-experimental-3cfcbc5bc-20231018';
2020

2121
var Internals = {
2222
usingClientEntryPoint: false,

packages/next/src/compiled/react-dom-experimental/cjs/react-dom-server-rendering-stub.production.min.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.

packages/next/src/compiled/react-dom-experimental/cjs/react-dom-server.browser.development.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ if (process.env.NODE_ENV !== "production") {
1717
var React = require("next/dist/compiled/react-experimental");
1818
var ReactDOM = require('react-dom');
1919

20-
var ReactVersion = '18.3.0-experimental-d900fadbf-20230929';
20+
var ReactVersion = '18.3.0-experimental-3cfcbc5bc-20231018';
2121

2222
var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
2323

@@ -11320,7 +11320,10 @@ function flushCompletedQueues(request, destination) {
1132011320
} // We're done.
1132111321

1132211322

11323-
close(destination);
11323+
close(destination); // We need to stop flowing now because we do not want any async contexts which might call
11324+
// float methods to initiate any flushes after this point
11325+
11326+
stopFlowing(request);
1132411327
} else {
1132511328
completeWriting(destination);
1132611329
}
@@ -11342,10 +11345,17 @@ function enqueueFlush(request) {
1134211345
request.pingedTasks.length === 0 && // If there is no destination there is nothing we can flush to. A flush will
1134311346
// happen when we start flowing again
1134411347
request.destination !== null) {
11345-
var destination = request.destination;
1134611348
request.flushScheduled = true;
1134711349
scheduleWork(function () {
11348-
return flushCompletedQueues(request, destination);
11350+
// We need to existence check destination again here because it might go away
11351+
// in between the enqueueFlush call and the work execution
11352+
var destination = request.destination;
11353+
11354+
if (destination) {
11355+
flushCompletedQueues(request, destination);
11356+
} else {
11357+
request.flushScheduled = false;
11358+
}
1134911359
});
1135011360
}
1135111361
}

0 commit comments

Comments
 (0)