Skip to content

Commit ec9490a

Browse files
committed
[Flight] Fix broken byte stream parsing caused by buffer detachment (facebook#35127)
This PR fixes a critical bug where `ReadableStream({type: 'bytes'})` instances passed through React Server Components (RSC) would stall after reading only the first chunk or the first few chunks in the client. This issue was masked by using `web-streams-polyfill` in tests, but manifests with native Web Streams implementations. The root cause is that when a chunk is enqueued to a `ReadableByteStreamController`, the spec requires the underlying ArrayBuffer to be synchronously transferred/detached. In the React Flight Client's chunk parsing, embedded byte stream chunks are created as views into the incoming RSC stream chunk buffer using `new Uint8Array(chunk.buffer, offset, length)`. When embedded byte stream chunks are enqueued, they can detach the shared buffer, leaving the RSC stream parsing in a broken state. The fix is to copy embedded byte stream chunks before enqueueing them, preventing buffer detachment from affecting subsequent parsing. To not affect performance too much, we use a zero-copy optimization: when a chunk ends exactly at the end of the RSC stream chunk, or when the row spans into the next RSC chunk, no further parsing will access that buffer, so we can safely enqueue the view directly without copying. We now also enqueue embedded byte stream chunks immediately as they are parsed, without waiting for the full row to complete. To simplify the logic in the client, we introduce a new `'b'` protocol tag specifically for byte stream chunks. The server now emits `'b'` instead of `'o'` for `Uint8Array` chunks from byte streams (detected via `supportsBYOB`). This allows the client to recognize byte stream chunks without needing to track stream IDs. Tests now use the proper Jest environment with native Web Streams instead of polyfills, exposing and validating the fix for this issue. DiffTrain build for [93fc574](facebook@93fc574)
1 parent 057acdb commit ec9490a

File tree

21 files changed

+72
-72
lines changed

21 files changed

+72
-72
lines changed

compiled-rn/VERSION_NATIVE_FB

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
19.3.0-native-fb-093b3246-20251113
1+
19.3.0-native-fb-93fc5740-20251113

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOM-dev.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<25b6ebb820a125c78032767ff76ee204>>
10+
* @generated SignedSource<<999d3c9c2317233c8d99ed68497e5db2>>
1111
*/
1212

1313
"use strict";
@@ -404,5 +404,5 @@ __DEV__ &&
404404
exports.useFormStatus = function () {
405405
return resolveDispatcher().useHostTransitionStatus();
406406
};
407-
exports.version = "19.3.0-native-fb-093b3246-20251113";
407+
exports.version = "19.3.0-native-fb-93fc5740-20251113";
408408
})();

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOM-prod.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<9b6ea1433e9810b1eb5ceea5bac3a7d5>>
10+
* @generated SignedSource<<fcced61322caf0a0a2c299b3193730c1>>
1111
*/
1212

1313
"use strict";
@@ -203,4 +203,4 @@ exports.useFormState = function (action, initialState, permalink) {
203203
exports.useFormStatus = function () {
204204
return ReactSharedInternals.H.useHostTransitionStatus();
205205
};
206-
exports.version = "19.3.0-native-fb-093b3246-20251113";
206+
exports.version = "19.3.0-native-fb-93fc5740-20251113";

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOM-profiling.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<9b6ea1433e9810b1eb5ceea5bac3a7d5>>
10+
* @generated SignedSource<<fcced61322caf0a0a2c299b3193730c1>>
1111
*/
1212

1313
"use strict";
@@ -203,4 +203,4 @@ exports.useFormState = function (action, initialState, permalink) {
203203
exports.useFormStatus = function () {
204204
return ReactSharedInternals.H.useHostTransitionStatus();
205205
};
206-
exports.version = "19.3.0-native-fb-093b3246-20251113";
206+
exports.version = "19.3.0-native-fb-93fc5740-20251113";

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOMClient-dev.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<93d115a32d74e9bc15da4902c7badca7>>
10+
* @generated SignedSource<<2a6d047b91f4e7be0b0d6d4395a1f0ee>>
1111
*/
1212

1313
/*
@@ -30242,11 +30242,11 @@ __DEV__ &&
3024230242
};
3024330243
(function () {
3024430244
var isomorphicReactPackageVersion = React.version;
30245-
if ("19.3.0-native-fb-093b3246-20251113" !== isomorphicReactPackageVersion)
30245+
if ("19.3.0-native-fb-93fc5740-20251113" !== isomorphicReactPackageVersion)
3024630246
throw Error(
3024730247
'Incompatible React versions: The "react" and "react-dom" packages must have the exact same version. Instead got:\n - react: ' +
3024830248
(isomorphicReactPackageVersion +
30249-
"\n - react-dom: 19.3.0-native-fb-093b3246-20251113\nLearn more: https://react.dev/warnings/version-mismatch")
30249+
"\n - react-dom: 19.3.0-native-fb-93fc5740-20251113\nLearn more: https://react.dev/warnings/version-mismatch")
3025030250
);
3025130251
})();
3025230252
("function" === typeof Map &&
@@ -30283,10 +30283,10 @@ __DEV__ &&
3028330283
!(function () {
3028430284
var internals = {
3028530285
bundleType: 1,
30286-
version: "19.3.0-native-fb-093b3246-20251113",
30286+
version: "19.3.0-native-fb-93fc5740-20251113",
3028730287
rendererPackageName: "react-dom",
3028830288
currentDispatcherRef: ReactSharedInternals,
30289-
reconcilerVersion: "19.3.0-native-fb-093b3246-20251113"
30289+
reconcilerVersion: "19.3.0-native-fb-93fc5740-20251113"
3029030290
};
3029130291
internals.overrideHookState = overrideHookState;
3029230292
internals.overrideHookStateDeletePath = overrideHookStateDeletePath;
@@ -30436,5 +30436,5 @@ __DEV__ &&
3043630436
listenToAllSupportedEvents(container);
3043730437
return new ReactDOMHydrationRoot(initialChildren);
3043830438
};
30439-
exports.version = "19.3.0-native-fb-093b3246-20251113";
30439+
exports.version = "19.3.0-native-fb-93fc5740-20251113";
3044030440
})();

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOMClient-prod.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<66d8560d5d1fd17915e1985d584c47dd>>
10+
* @generated SignedSource<<7d4763b3fb9ff2dad435f3671e195b37>>
1111
*/
1212

1313
/*
@@ -17702,14 +17702,14 @@ ReactDOMHydrationRoot.prototype.unstable_scheduleHydration = function (target) {
1770217702
};
1770317703
var isomorphicReactPackageVersion$jscomp$inline_2054 = React.version;
1770417704
if (
17705-
"19.3.0-native-fb-093b3246-20251113" !==
17705+
"19.3.0-native-fb-93fc5740-20251113" !==
1770617706
isomorphicReactPackageVersion$jscomp$inline_2054
1770717707
)
1770817708
throw Error(
1770917709
formatProdErrorMessage(
1771017710
527,
1771117711
isomorphicReactPackageVersion$jscomp$inline_2054,
17712-
"19.3.0-native-fb-093b3246-20251113"
17712+
"19.3.0-native-fb-93fc5740-20251113"
1771317713
)
1771417714
);
1771517715
ReactDOMSharedInternals.findDOMNode = function (componentOrElement) {
@@ -17731,10 +17731,10 @@ ReactDOMSharedInternals.findDOMNode = function (componentOrElement) {
1773117731
};
1773217732
var internals$jscomp$inline_2636 = {
1773317733
bundleType: 0,
17734-
version: "19.3.0-native-fb-093b3246-20251113",
17734+
version: "19.3.0-native-fb-93fc5740-20251113",
1773517735
rendererPackageName: "react-dom",
1773617736
currentDispatcherRef: ReactSharedInternals,
17737-
reconcilerVersion: "19.3.0-native-fb-093b3246-20251113"
17737+
reconcilerVersion: "19.3.0-native-fb-93fc5740-20251113"
1773817738
};
1773917739
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
1774017740
var hook$jscomp$inline_2637 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
@@ -17841,4 +17841,4 @@ exports.hydrateRoot = function (container, initialChildren, options) {
1784117841
listenToAllSupportedEvents(container);
1784217842
return new ReactDOMHydrationRoot(initialChildren);
1784317843
};
17844-
exports.version = "19.3.0-native-fb-093b3246-20251113";
17844+
exports.version = "19.3.0-native-fb-93fc5740-20251113";

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOMClient-profiling.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<0edf5b7a836c5a3300077346cb391df7>>
10+
* @generated SignedSource<<cbc3536f1eeedda1472c094e3679c71d>>
1111
*/
1212

1313
/*
@@ -19828,14 +19828,14 @@ ReactDOMHydrationRoot.prototype.unstable_scheduleHydration = function (target) {
1982819828
};
1982919829
var isomorphicReactPackageVersion$jscomp$inline_2369 = React.version;
1983019830
if (
19831-
"19.3.0-native-fb-093b3246-20251113" !==
19831+
"19.3.0-native-fb-93fc5740-20251113" !==
1983219832
isomorphicReactPackageVersion$jscomp$inline_2369
1983319833
)
1983419834
throw Error(
1983519835
formatProdErrorMessage(
1983619836
527,
1983719837
isomorphicReactPackageVersion$jscomp$inline_2369,
19838-
"19.3.0-native-fb-093b3246-20251113"
19838+
"19.3.0-native-fb-93fc5740-20251113"
1983919839
)
1984019840
);
1984119841
ReactDOMSharedInternals.findDOMNode = function (componentOrElement) {
@@ -19857,10 +19857,10 @@ ReactDOMSharedInternals.findDOMNode = function (componentOrElement) {
1985719857
};
1985819858
var internals$jscomp$inline_2376 = {
1985919859
bundleType: 0,
19860-
version: "19.3.0-native-fb-093b3246-20251113",
19860+
version: "19.3.0-native-fb-93fc5740-20251113",
1986119861
rendererPackageName: "react-dom",
1986219862
currentDispatcherRef: ReactSharedInternals,
19863-
reconcilerVersion: "19.3.0-native-fb-093b3246-20251113",
19863+
reconcilerVersion: "19.3.0-native-fb-93fc5740-20251113",
1986419864
getLaneLabelMap: function () {
1986519865
for (
1986619866
var map = new Map(), lane = 1, index$336 = 0;
@@ -19983,4 +19983,4 @@ exports.hydrateRoot = function (container, initialChildren, options) {
1998319983
listenToAllSupportedEvents(container);
1998419984
return new ReactDOMHydrationRoot(initialChildren);
1998519985
};
19986-
exports.version = "19.3.0-native-fb-093b3246-20251113";
19986+
exports.version = "19.3.0-native-fb-93fc5740-20251113";

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOMProfiling-dev.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<4af52ab84a2da7728be945391705d1d4>>
10+
* @generated SignedSource<<ffbfb9d305b0a47195f46c79c4b3e0e6>>
1111
*/
1212

1313
/*
@@ -30298,11 +30298,11 @@ __DEV__ &&
3029830298
};
3029930299
(function () {
3030030300
var isomorphicReactPackageVersion = React.version;
30301-
if ("19.3.0-native-fb-093b3246-20251113" !== isomorphicReactPackageVersion)
30301+
if ("19.3.0-native-fb-93fc5740-20251113" !== isomorphicReactPackageVersion)
3030230302
throw Error(
3030330303
'Incompatible React versions: The "react" and "react-dom" packages must have the exact same version. Instead got:\n - react: ' +
3030430304
(isomorphicReactPackageVersion +
30305-
"\n - react-dom: 19.3.0-native-fb-093b3246-20251113\nLearn more: https://react.dev/warnings/version-mismatch")
30305+
"\n - react-dom: 19.3.0-native-fb-93fc5740-20251113\nLearn more: https://react.dev/warnings/version-mismatch")
3030630306
);
3030730307
})();
3030830308
("function" === typeof Map &&
@@ -30339,10 +30339,10 @@ __DEV__ &&
3033930339
!(function () {
3034030340
var internals = {
3034130341
bundleType: 1,
30342-
version: "19.3.0-native-fb-093b3246-20251113",
30342+
version: "19.3.0-native-fb-93fc5740-20251113",
3034330343
rendererPackageName: "react-dom",
3034430344
currentDispatcherRef: ReactSharedInternals,
30345-
reconcilerVersion: "19.3.0-native-fb-093b3246-20251113"
30345+
reconcilerVersion: "19.3.0-native-fb-93fc5740-20251113"
3034630346
};
3034730347
internals.overrideHookState = overrideHookState;
3034830348
internals.overrideHookStateDeletePath = overrideHookStateDeletePath;
@@ -30808,7 +30808,7 @@ __DEV__ &&
3080830808
exports.useFormStatus = function () {
3080930809
return resolveDispatcher().useHostTransitionStatus();
3081030810
};
30811-
exports.version = "19.3.0-native-fb-093b3246-20251113";
30811+
exports.version = "19.3.0-native-fb-93fc5740-20251113";
3081230812
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
3081330813
"function" ===
3081430814
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOMProfiling-prod.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<5bf0c986a694719ad9238c2b6a6fc5fc>>
10+
* @generated SignedSource<<7399cd27dca5e363bc7d0b657b9d4132>>
1111
*/
1212

1313
/*
@@ -17713,14 +17713,14 @@ ReactDOMHydrationRoot.prototype.unstable_scheduleHydration = function (target) {
1771317713
};
1771417714
var isomorphicReactPackageVersion$jscomp$inline_2055 = React.version;
1771517715
if (
17716-
"19.3.0-native-fb-093b3246-20251113" !==
17716+
"19.3.0-native-fb-93fc5740-20251113" !==
1771717717
isomorphicReactPackageVersion$jscomp$inline_2055
1771817718
)
1771917719
throw Error(
1772017720
formatProdErrorMessage(
1772117721
527,
1772217722
isomorphicReactPackageVersion$jscomp$inline_2055,
17723-
"19.3.0-native-fb-093b3246-20251113"
17723+
"19.3.0-native-fb-93fc5740-20251113"
1772417724
)
1772517725
);
1772617726
ReactDOMSharedInternals.findDOMNode = function (componentOrElement) {
@@ -17742,10 +17742,10 @@ ReactDOMSharedInternals.findDOMNode = function (componentOrElement) {
1774217742
};
1774317743
var internals$jscomp$inline_2639 = {
1774417744
bundleType: 0,
17745-
version: "19.3.0-native-fb-093b3246-20251113",
17745+
version: "19.3.0-native-fb-93fc5740-20251113",
1774617746
rendererPackageName: "react-dom",
1774717747
currentDispatcherRef: ReactSharedInternals,
17748-
reconcilerVersion: "19.3.0-native-fb-093b3246-20251113"
17748+
reconcilerVersion: "19.3.0-native-fb-93fc5740-20251113"
1774917749
};
1775017750
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
1775117751
var hook$jscomp$inline_2640 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
@@ -18005,4 +18005,4 @@ exports.useFormState = function (action, initialState, permalink) {
1800518005
exports.useFormStatus = function () {
1800618006
return ReactSharedInternals.H.useHostTransitionStatus();
1800718007
};
18008-
exports.version = "19.3.0-native-fb-093b3246-20251113";
18008+
exports.version = "19.3.0-native-fb-93fc5740-20251113";

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOMProfiling-profiling.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<6ad53937bda6b110844aa928aa913ef5>>
10+
* @generated SignedSource<<4670ab115112abf251cf565636883e4a>>
1111
*/
1212

1313
/*
@@ -19843,14 +19843,14 @@ ReactDOMHydrationRoot.prototype.unstable_scheduleHydration = function (target) {
1984319843
};
1984419844
var isomorphicReactPackageVersion$jscomp$inline_2370 = React.version;
1984519845
if (
19846-
"19.3.0-native-fb-093b3246-20251113" !==
19846+
"19.3.0-native-fb-93fc5740-20251113" !==
1984719847
isomorphicReactPackageVersion$jscomp$inline_2370
1984819848
)
1984919849
throw Error(
1985019850
formatProdErrorMessage(
1985119851
527,
1985219852
isomorphicReactPackageVersion$jscomp$inline_2370,
19853-
"19.3.0-native-fb-093b3246-20251113"
19853+
"19.3.0-native-fb-93fc5740-20251113"
1985419854
)
1985519855
);
1985619856
ReactDOMSharedInternals.findDOMNode = function (componentOrElement) {
@@ -19872,10 +19872,10 @@ ReactDOMSharedInternals.findDOMNode = function (componentOrElement) {
1987219872
};
1987319873
var internals$jscomp$inline_2377 = {
1987419874
bundleType: 0,
19875-
version: "19.3.0-native-fb-093b3246-20251113",
19875+
version: "19.3.0-native-fb-93fc5740-20251113",
1987619876
rendererPackageName: "react-dom",
1987719877
currentDispatcherRef: ReactSharedInternals,
19878-
reconcilerVersion: "19.3.0-native-fb-093b3246-20251113",
19878+
reconcilerVersion: "19.3.0-native-fb-93fc5740-20251113",
1987919879
getLaneLabelMap: function () {
1988019880
for (
1988119881
var map = new Map(), lane = 1, index$336 = 0;
@@ -20151,7 +20151,7 @@ exports.useFormState = function (action, initialState, permalink) {
2015120151
exports.useFormStatus = function () {
2015220152
return ReactSharedInternals.H.useHostTransitionStatus();
2015320153
};
20154-
exports.version = "19.3.0-native-fb-093b3246-20251113";
20154+
exports.version = "19.3.0-native-fb-93fc5740-20251113";
2015520155
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
2015620156
"function" ===
2015720157
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

0 commit comments

Comments
 (0)