Skip to content

Commit 975b644

Browse files
authored
[Flight] response.readRoot() -> use(response) (#25267)
* [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
1 parent 60fbb7b commit 975b644

File tree

13 files changed

+194
-192
lines changed

13 files changed

+194
-192
lines changed

fixtures/flight-browser/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ <h1>Flight Example</h1>
8383
}
8484

8585
function Shell({ data }) {
86-
let model = data.readRoot();
86+
let model = React.experimental_use(data);
8787
return <div>
8888
<Suspense fallback="...">
8989
<h1>{model.title}</h1>

fixtures/flight/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import ReactServerDOMReader from 'react-server-dom-webpack';
66
let data = ReactServerDOMReader.createFromFetch(fetch('http://localhost:3001'));
77

88
function Content() {
9-
return data.readRoot();
9+
return React.experimental_use(data);
1010
}
1111

1212
ReactDOM.render(

packages/react-client/src/ReactFlightClient.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ Chunk.prototype.then = function<T>(
147147
export type ResponseBase = {
148148
_bundlerConfig: BundlerConfig,
149149
_chunks: Map<number, SomeChunk<any>>,
150-
readRoot<T>(): T,
151150
...
152151
};
153152

@@ -177,10 +176,9 @@ function readChunk<T>(chunk: SomeChunk<T>): T {
177176
}
178177
}
179178

180-
function readRoot<T>(): T {
181-
const response: Response = this;
179+
export function getRoot<T>(response: Response): Thenable<T> {
182180
const chunk = getChunk(response, 0);
183-
return readChunk(chunk);
181+
return (chunk: any);
184182
}
185183

186184
function createPendingChunk<T>(response: Response): PendingChunk<T> {
@@ -541,7 +539,6 @@ export function createResponse(bundlerConfig: BundlerConfig): ResponseBase {
541539
const response = {
542540
_bundlerConfig: bundlerConfig,
543541
_chunks: chunks,
544-
readRoot: readRoot,
545542
};
546543
return response;
547544
}

packages/react-client/src/ReactFlightClientStream.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,4 @@ export function createResponse(bundlerConfig: BundlerConfig): Response {
137137
return response;
138138
}
139139

140-
export {reportGlobalError, close} from './ReactFlightClient';
140+
export {reportGlobalError, getRoot, close} from './ReactFlightClient';

0 commit comments

Comments
 (0)