Skip to content

Commit 2b003a5

Browse files
authored
Split out ServerReferenceMetadata into Id and Bound Arguments (#26351)
This is just moving some stuff around and renaming things. This tuple is opaque to the Flight implementation and we should probably encode it separately as a single string instead of a model object. The term "Metadata" isn't the same as when used for ClientReferences so it's not really the right term anyway. I also made it optional since a bound function with no arguments bound is technically different than a raw instance of that function (it's a clone). I also renamed the type ReactModel to ReactClientValue. This is the generic serializable type for something that can pass through the serializable boundary from server to client. There will be another one for client to server. I also filled in missing classes and ensure the serializable sub-types are explicit. E.g. Array and Thenable.
1 parent 62cd5af commit 2b003a5

24 files changed

Lines changed: 179 additions & 122 deletions

‎packages/react-client/src/ReactFlightClient.js‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import type {
1515
ClientReferenceMetadata,
1616
UninitializedModel,
1717
Response,
18-
BundlerConfig,
18+
SSRManifest,
1919
}from'./ReactFlightClientHostConfig';
2020

2121
import{
@@ -149,7 +149,7 @@ Chunk.prototype.then = function <T>(
149149
};
150150

151151
exporttypeResponseBase={
152-
_bundlerConfig: BundlerConfig,
152+
_bundlerConfig: SSRManifest,
153153
_callServer: CallServerCallback,
154154
_chunks: Map<number,SomeChunk<any>>,
155155
...
@@ -473,13 +473,16 @@ function createModelReject<T>(chunk: SomeChunk<T>): (error: mixed) => void {
473473

474474
function createServerReferenceProxy<A: Iterable<any>, T>(
475475
response: Response,
476-
metaData: {id: any,bound: Thenable<Array<any>>},
476+
metaData: {id: any,bound: null|Thenable<Array<any>>},
477477
): (...A) =>Promise<T>{
478478
constcallServer=response._callServer;
479479
constproxy=function(): Promise<T>{
480480
// $FlowFixMe[method-unbinding]
481481
constargs=Array.prototype.slice.call(arguments);
482482
constp=metaData.bound;
483+
if(!p){
484+
returncallServer(metaData.id,args);
485+
}
483486
if(p.status===INITIALIZED){
484487
const bound =p.value;
485488
returncallServer(metaData.id,bound.concat(args));
@@ -608,7 +611,7 @@ function missingCall() {
608611
}
609612

610613
exportfunctioncreateResponse(
611-
bundlerConfig: BundlerConfig,
614+
bundlerConfig: SSRManifest,
612615
callServer: void|CallServerCallback,
613616
): ResponseBase{
614617
constchunks: Map<number,SomeChunk<any>>=newMap();

‎packages/react-client/src/ReactFlightClientStream.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
importtype{CallServerCallback}from'./ReactFlightClient';
1111
importtype{Response}from'./ReactFlightClientHostConfigStream';
12-
importtype{BundlerConfig}from'./ReactFlightClientHostConfig';
12+
importtype{SSRManifest}from'./ReactFlightClientHostConfig';
1313

1414
import{
1515
resolveModule,
@@ -121,7 +121,7 @@ function createFromJSONCallback(response: Response) {
121121
}
122122

123123
exportfunctioncreateResponse(
124-
bundlerConfig: BundlerConfig,
124+
bundlerConfig: SSRManifest,
125125
callServer: void|CallServerCallback,
126126
): Response{
127127
// NOTE: CHECK THE COMPILER OUTPUT EACH TIME YOU CHANGE THIS.

‎packages/react-client/src/forks/ReactFlightClientHostConfig.custom.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
declarevar $$$hostConfig: any;
2727

2828
exporttypeResponse=any;
29-
exportopaquetypeBundlerConfig=mixed;
29+
exportopaquetypeSSRManifest=mixed;
3030
exportopaquetypeClientReferenceMetadata=mixed;
3131
exportopaquetypeClientReference<T>=mixed;// eslint-disable-line no-unused-vars
3232
exportconstresolveClientReference=$$$hostConfig.resolveClientReference;

‎packages/react-client/src/forks/ReactFlightClientHostConfig.dom-bun.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export * from 'react-client/src/ReactFlightClientHostConfigBrowser';
1111
export*from'react-client/src/ReactFlightClientHostConfigStream';
1212

1313
exporttypeResponse=any;
14-
exportopaquetypeBundlerConfig=mixed;
14+
exportopaquetypeSSRManifest=mixed;
1515
exportopaquetypeClientReferenceMetadata=mixed;
1616
exportopaquetypeClientReference<T>=mixed;// eslint-disable-line no-unused-vars
1717
exportconstresolveClientReference: any=null;

‎packages/react-noop-renderer/src/ReactNoopFlightServer.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* environment.
1515
*/
1616

17-
importtype{ReactModel}from'react-server/src/ReactFlightServer';
17+
importtype{ReactClientValue}from'react-server/src/ReactFlightServer';
1818
importtype{ServerContextJSONValue}from'shared/ReactTypes';
1919

2020
import{saveModule}from'react-noop-renderer/flight-modules';
@@ -71,7 +71,7 @@ type Options = {
7171
identifierPrefix?: string,
7272
};
7373

74-
functionrender(model: ReactModel,options?: Options): Destination{
74+
functionrender(model: ReactClientValue,options?: Options): Destination{
7575
constdestination: Destination=[];
7676
constbundlerConfig=undefined;
7777
constrequest=ReactNoopFlightServer.createRequest(

‎packages/react-server-dom-relay/src/ReactFlightDOMRelayClientHostConfig.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ import isArray from 'shared/isArray';
3131

3232
exporttype{ClientReferenceMetadata}from'ReactFlightDOMRelayClientIntegration';
3333

34-
exporttypeBundlerConfig=null;
34+
exporttypeSSRManifest=null;
3535

3636
exporttypeUninitializedModel=JSONValue;
3737

3838
exporttypeResponse=ResponseBase;
3939

4040
exportfunctionresolveClientReference<T>(
41-
bundlerConfig: BundlerConfig,
41+
bundlerConfig: SSRManifest,
4242
metadata: ClientReferenceMetadata,
4343
): ClientReference<T>{
4444
returnresolveClientReferenceImpl(metadata);

‎packages/react-server-dom-relay/src/ReactFlightDOMRelayServer.js‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
* @flow
88
*/
99

10-
importtype{ReactModel}from'react-server/src/ReactFlightServer';
10+
importtype{ReactClientValue}from'react-server/src/ReactFlightServer';
1111
importtype{
12-
BundlerConfig,
12+
ClientManifest,
1313
Destination,
1414
}from'./ReactFlightDOMRelayServerHostConfig';
1515

@@ -25,9 +25,9 @@ type Options = {
2525
};
2626

2727
functionrender(
28-
model: ReactModel,
28+
model: ReactClientValue,
2929
destination: Destination,
30-
config: BundlerConfig,
30+
config: ClientManifest,
3131
options?: Options,
3232
): void{
3333
const request =createRequest(

‎packages/react-server-dom-relay/src/ReactFlightDOMRelayServerHostConfig.js‎

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99

1010
importtype{RowEncoding,JSONValue}from'./ReactFlightDOMRelayProtocol';
1111

12-
importtype{Request,ReactModel}from'react-server/src/ReactFlightServer';
12+
importtype{
13+
Request,
14+
ReactClientValue,
15+
}from'react-server/src/ReactFlightServer';
1316

1417
importtype{JSResourceReference}from'JSResourceReference';
1518
importJSResourceReferenceImplfrom'JSResourceReferenceImpl';
@@ -23,7 +26,7 @@ export type ServerReferenceId = {};
2326

2427
importtype{
2528
Destination,
26-
BundlerConfig,
29+
BundlerConfigasClientManifest,
2730
ClientReferenceMetadata,
2831
}from'ReactFlightDOMRelayServerIntegration';
2932

@@ -37,7 +40,7 @@ import {
3740

3841
exporttype{
3942
Destination,
40-
BundlerConfig,
43+
BundlerConfigasClientManifest,
4144
ClientReferenceMetadata,
4245
}from'ReactFlightDOMRelayServerIntegration';
4346

@@ -60,16 +63,23 @@ export function getClientReferenceKey(
6063
}
6164

6265
exportfunctionresolveClientReferenceMetadata<T>(
63-
config: BundlerConfig,
66+
config: ClientManifest,
6467
resource: ClientReference<T>,
6568
): ClientReferenceMetadata{
6669
returnresolveClientReferenceMetadataImpl(config,resource);
6770
}
6871

69-
exportfunctionresolveServerReferenceMetadata<T>(
70-
config: BundlerConfig,
72+
exportfunctiongetServerReferenceId<T>(
73+
config: ClientManifest,
74+
resource: ServerReference<T>,
75+
): ServerReferenceId{
76+
thrownewError('Not implemented.');
77+
}
78+
79+
exportfunctiongetServerReferenceBoundArguments<T>(
80+
config: ClientManifest,
7181
resource: ServerReference<T>,
72-
): {id: ServerReferenceId,bound: Promise<Array<any>>}{
82+
): Array<ReactClientValue>{
7383
thrownewError('Not implemented.');
7484
}
7585

@@ -125,9 +135,9 @@ export function processErrorChunkDev(
125135

126136
functionconvertModelToJSON(
127137
request: Request,
128-
parent: {+[key: string]: ReactModel}|$ReadOnlyArray<ReactModel>,
138+
parent: {+[key: string]: ReactClientValue}|$ReadOnlyArray<ReactClientValue>,
129139
key: string,
130-
model: ReactModel,
140+
model: ReactClientValue,
131141
): JSONValue{
132142
constjson=resolveModelToJSON(request,parent,key,model);
133143
if(typeofjson==='object'&&json!==null){
@@ -160,7 +170,7 @@ function convertModelToJSON(
160170
exportfunctionprocessModelChunk(
161171
request: Request,
162172
id: number,
163-
model: ReactModel,
173+
model: ReactClientValue,
164174
): Chunk{
165175
// $FlowFixMe no good way to define an empty exact object
166176
constjson=convertModelToJSON(request,{},'',model);

‎packages/react-server-dom-webpack/src/ReactFlightClientNodeBundlerConfig.js‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,12 @@ import type {
1313
RejectedThenable,
1414
}from'shared/ReactTypes';
1515

16-
exporttypeWebpackSSRMap={
16+
exporttypeSSRManifest={
1717
[clientId: string]: {
1818
[clientExportName: string]: ClientReference<any>,
1919
},
2020
};
2121

22-
exporttypeBundlerConfig=WebpackSSRMap;
23-
2422
exportopaquetypeClientReferenceMetadata={
2523
id: string,
2624
chunks: Array<string>,
@@ -34,7 +32,7 @@ export opaque type ClientReference<T> = {
3432
};
3533

3634
exportfunctionresolveClientReference<T>(
37-
bundlerConfig: BundlerConfig,
35+
bundlerConfig: SSRManifest,
3836
metadata: ClientReferenceMetadata,
3937
): ClientReference<T>{
4038
const resolvedModuleData =bundlerConfig[metadata.id][metadata.name];

‎packages/react-server-dom-webpack/src/ReactFlightClientWebpackBundlerConfig.js‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,12 @@ import type {
1313
RejectedThenable,
1414
}from'shared/ReactTypes';
1515

16-
exporttypeWebpackSSRMap={
16+
exporttypeSSRManifest=null|{
1717
[clientId: string]: {
1818
[clientExportName: string]: ClientReferenceMetadata,
1919
},
2020
};
2121

22-
exporttypeBundlerConfig=null|WebpackSSRMap;
23-
2422
exportopaquetypeClientReferenceMetadata={
2523
id: string,
2624
chunks: Array<string>,
@@ -32,7 +30,7 @@ export opaque type ClientReferenceMetadata = {
3230
exportopaquetypeClientReference<T>=ClientReferenceMetadata;
3331

3432
exportfunctionresolveClientReference<T>(
35-
bundlerConfig: BundlerConfig,
33+
bundlerConfig: SSRManifest,
3634
metadata: ClientReferenceMetadata,
3735
): ClientReference<T>{
3836
if(bundlerConfig){

0 commit comments

Comments
 (0)