Skip to content

Commit

Permalink
Remove XHR support from Flight (facebook#26827)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sebmarkbage authored and AndyPengc12 committed Apr 15, 2024
1 parent 60653f9 commit 7ca9e6b
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 34 deletions.
6 changes: 0 additions & 6 deletions fixtures/flight-browser/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,6 @@ <h1>Flight Example</h1>
let data = ReactServerDOMClient.createFromFetch(
fetch(url)
);
// The client also supports XHR streaming.
// var xhr = new XMLHttpRequest();
// xhr.open('GET', url);
// let data = ReactServerDOMClient.createFromXHR(xhr);
// xhr.send();

renderResult(data);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
createResponse,
getRoot,
reportGlobalError,
processStringChunk,
processBinaryChunk,
close,
} from 'react-client/src/ReactFlightClient';
Expand Down Expand Up @@ -92,32 +91,6 @@ function createFromFetch<T>(
return getRoot(response);
}

function createFromXHR<T>(
request: XMLHttpRequest,
options?: Options,
): Thenable<T> {
const response: FlightResponse = createResponseFromOptions(options);
let processedLength = 0;
function progress(e: ProgressEvent): void {
const chunk = request.responseText;
processStringChunk(response, chunk, processedLength);
processedLength = chunk.length;
}
function load(e: ProgressEvent): void {
progress(e);
close(response);
}
function error(e: ProgressEvent): void {
reportGlobalError(response, new TypeError('Network error'));
}
request.addEventListener('progress', progress);
request.addEventListener('load', load);
request.addEventListener('error', error);
request.addEventListener('abort', error);
request.addEventListener('timeout', error);
return getRoot(response);
}
function encodeReply(
value: ReactServerValue,
): Promise<
Expand All @@ -129,7 +102,6 @@ function encodeReply(
}

export {
createFromXHR,
createFromFetch,
createFromReadableStream,
encodeReply,
Expand Down

0 comments on commit 7ca9e6b

Please sign in to comment.