@samitouri / QOS-React / commits / e6fae308e9

Remove XHR support from Flight (#26827)

We currently support passing an XHR request to Flight for broader compat and possibly better perf than `fetch()`. However, it's a little tricky because ideally the RSC protocol is really meant to support binary data too. XHR does support binary but it doesn't support it while also streaming. We could maybe support this only when you know it's going to be only text streams but it has some limitations in how we can encode separators if we can't use binary. Nobody is really asking for this so we might as well delete it.

Sebastian Markbåge committed Jun 3, 2023 at 16:03 UTC e6fae308e9300ca545003ac147cc7e4e541f561c
2 files changed -34
fixtures/flight-browser/index.html
-6
@@ -73,12 +73,6 @@
73 let data = ReactServerDOMClient.createFromFetch(
74 fetch(url)
75 );
76 - // The client also supports XHR streaming.
77 - // var xhr = new XMLHttpRequest();
78 - // xhr.open('GET', url);
79 - // let data = ReactServerDOMClient.createFromXHR(xhr);
80 - // xhr.send();
81 -
76 renderResult(data);
77 }
78
packages/react-server-dom-webpack/src/ReactFlightDOMClientBrowser.js
-28
@@ -17,7 +17,6 @@ import {
17 createResponse,
18 getRoot,
19 reportGlobalError,
20 - processStringChunk,
20 processBinaryChunk,
21 close,
22 } from 'react-client/src/ReactFlightClient';
@@ -92,32 +91,6 @@ function createFromFetch<T>(
91 return getRoot(response);
92 }
93
95 -function createFromXHR<T>(
96 - request: XMLHttpRequest,
97 - options?: Options,
98 -): Thenable<T> {
99 - const response: FlightResponse = createResponseFromOptions(options);
100 - let processedLength = 0;
101 - function progress(e: ProgressEvent): void {
102 - const chunk = request.responseText;
103 - processStringChunk(response, chunk, processedLength);
104 - processedLength = chunk.length;
105 - }
106 - function load(e: ProgressEvent): void {
107 - progress(e);
108 - close(response);
109 - }
110 - function error(e: ProgressEvent): void {
111 - reportGlobalError(response, new TypeError('Network error'));
112 - }
113 - request.addEventListener('progress', progress);
114 - request.addEventListener('load', load);
115 - request.addEventListener('error', error);
116 - request.addEventListener('abort', error);
117 - request.addEventListener('timeout', error);
118 - return getRoot(response);
119 -}
120 -
94 function encodeReply(
95 value: ReactServerValue,
96 ): Promise<
@@ -129,7 +102,6 @@ function encodeReply(
102 }
103
104 export {
132 - createFromXHR,
105 createFromFetch,
106 createFromReadableStream,
107 encodeReply,