Skip to content

Commit

Permalink
[Flight] response.readRoot() -> use(response) (#25267)
Browse files Browse the repository at this point in the history
* [Flight] Move from suspensey readRoot() to use(thenable)

* Update noop tests

These are no longer sync so they need some more significant updating.

Some of these tests are written in a non-idiomatic form too which is not
great.

* Update Relay tests

I kept these as sync for now and just assume a sync Promise.

* Updated the main tests

* Gate tests

* We need to cast through any because Thenable doesn't support unknown strings
  • Loading branch information
sebmarkbage committed Sep 15, 2022
1 parent 60fbb7b commit 975b644
Show file tree
Hide file tree
Showing 13 changed files with 194 additions and 192 deletions.
2 changes: 1 addition & 1 deletion fixtures/flight-browser/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ <h1>Flight Example</h1>
}

function Shell({ data }) {
let model = data.readRoot();
let model = React.experimental_use(data);
return <div>
<Suspense fallback="...">
<h1>{model.title}</h1>
Expand Down
2 changes: 1 addition & 1 deletion fixtures/flight/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import ReactServerDOMReader from 'react-server-dom-webpack';
let data = ReactServerDOMReader.createFromFetch(fetch('http://localhost:3001'));

function Content() {
return data.readRoot();
return React.experimental_use(data);
}

ReactDOM.render(
Expand Down
7 changes: 2 additions & 5 deletions packages/react-client/src/ReactFlightClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ Chunk.prototype.then = function<T>(
export type ResponseBase = {
_bundlerConfig: BundlerConfig,
_chunks: Map<number, SomeChunk<any>>,
readRoot<T>(): T,
...
};

Expand Down Expand Up @@ -177,10 +176,9 @@ function readChunk<T>(chunk: SomeChunk<T>): T {
}
}

function readRoot<T>(): T {
const response: Response = this;
export function getRoot<T>(response: Response): Thenable<T> {
const chunk = getChunk(response, 0);
return readChunk(chunk);
return (chunk: any);
}

function createPendingChunk<T>(response: Response): PendingChunk<T> {
Expand Down Expand Up @@ -541,7 +539,6 @@ export function createResponse(bundlerConfig: BundlerConfig): ResponseBase {
const response = {
_bundlerConfig: bundlerConfig,
_chunks: chunks,
readRoot: readRoot,
};
return response;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/react-client/src/ReactFlightClientStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,4 @@ export function createResponse(bundlerConfig: BundlerConfig): Response {
return response;
}

export {reportGlobalError, close} from './ReactFlightClient';
export {reportGlobalError, getRoot, close} from './ReactFlightClient';
Loading

0 comments on commit 975b644

Please sign in to comment.