Skip to content

Commit 8206b4b

Browse files
authored
Wire up bundler configs (#18334)
This allows different flight server and clients to have different configs depending on bundler to serialize and resolve modules.
1 parent 6b7281e commit 8206b4b

26 files changed

Lines changed: 266 additions & 32 deletions

.eslintrc.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,13 @@ module.exports = {
157157
nativeFabricUIManager: true,
158158
},
159159
},
160+
{
161+
files: ['packages/react-flight-dom-webpack/**/*.js'],
162+
globals: {
163+
'__webpack_chunk_load__': true,
164+
'__webpack_require__': true,
165+
},
166+
},
160167
],
161168

162169
globals: {

packages/react-client/src/ReactFlightClient.js

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

1010
import {REACT_ELEMENT_TYPE} from 'shared/ReactSymbols';
1111

12+
// import type {ModuleMetaData} from './ReactFlightClientHostConfig';
13+
14+
// import {
15+
// preloadModule,
16+
// requireModule,
17+
// } from './ReactFlightClientHostConfig';
18+
1219
export type ReactModelRoot<T> = {|
1320
model: T,
1421
|};
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
export type StringDecoder = void;
11+
12+
export const supportsBinaryStreams = false;
13+
14+
export function createStringDecoder(): void {
15+
throw new Error('Should never be called');
16+
}
17+
18+
export function readPartialStringChunk(
19+
decoder: StringDecoder,
20+
buffer: Uint8Array,
21+
): string {
22+
throw new Error('Should never be called');
23+
}
24+
25+
export function readFinalStringChunk(
26+
decoder: StringDecoder,
27+
buffer: Uint8Array,
28+
): string {
29+
throw new Error('Should never be called');
30+
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
// really an argument to a top-level wrapping function.
2525

2626
declare var $$$hostConfig: any;
27+
28+
export opaque type ModuleMetaData = mixed; // eslint-disable-line no-undef
29+
export const preloadModule = $$$hostConfig.preloadModule;
30+
export const requireModule = $$$hostConfig.requireModule;
31+
2732
export opaque type Source = mixed; // eslint-disable-line no-undef
2833
export opaque type StringDecoder = mixed; // eslint-disable-line no-undef
2934

packages/react-client/src/forks/ReactFlightClientHostConfig.dom-browser.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88
*/
99

1010
export * from 'react-client/src/ReactFlightClientHostConfigBrowser';
11+
export * from 'react-flight-dom-webpack/src/ReactFlightClientWebpackBundlerConfig';

packages/react-client/src/forks/ReactFlightClientHostConfig.dom-relay.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88
*/
99

1010
export * from 'react-flight-dom-relay/src/ReactFlightDOMRelayClientHostConfig';
11+
export * from '../ReactFlightClientHostConfigNoStream';

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88
*/
99

1010
export * from 'react-client/src/ReactFlightClientHostConfigBrowser';
11+
export * from 'react-flight-dom-webpack/src/ReactFlightClientWebpackBundlerConfig';

packages/react-flight-dom-relay/src/ReactFlightDOMRelayClientHostConfig.js

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

10-
export type StringDecoder = void;
10+
export {
11+
preloadModule,
12+
requireModule,
13+
} from 'ReactFlightDOMRelayClientIntegration';
1114

12-
export const supportsBinaryStreams = false;
13-
14-
export function createStringDecoder(): void {
15-
throw new Error('Should never be called');
16-
}
17-
18-
export function readPartialStringChunk(
19-
decoder: StringDecoder,
20-
buffer: Uint8Array,
21-
): string {
22-
throw new Error('Should never be called');
23-
}
24-
25-
export function readFinalStringChunk(
26-
decoder: StringDecoder,
27-
buffer: Uint8Array,
28-
): string {
29-
throw new Error('Should never be called');
30-
}
15+
export type {ModuleMetaData} from 'ReactFlightDOMRelayClientIntegration';

packages/react-flight-dom-relay/src/ReactFlightDOMRelayServer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import type {Destination} from './ReactFlightDOMRelayServerHostConfig';
1313
import {createRequest, startWork} from 'react-server/src/ReactFlightServer';
1414

1515
function render(model: ReactModel, destination: Destination): void {
16-
let request = createRequest(model, destination);
16+
let request = createRequest(model, destination, undefined);
1717
startWork(request);
1818
}
1919

packages/react-flight-dom-relay/src/ReactFlightDOMRelayServerHostConfig.js

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,34 @@
99

1010
import type {Request, ReactModel} from 'react-server/src/ReactFlightServer';
1111

12-
import type {Destination} from 'ReactFlightDOMRelayServerIntegration';
12+
import type {
13+
Destination,
14+
ModuleReference,
15+
ModuleMetaData,
16+
} from 'ReactFlightDOMRelayServerIntegration';
1317

1418
import {resolveModelToJSON} from 'react-server/src/ReactFlightServer';
1519

16-
import {emitModel, emitError} from 'ReactFlightDOMRelayServerIntegration';
17-
18-
export type {Destination} from 'ReactFlightDOMRelayServerIntegration';
20+
import {
21+
emitModel,
22+
emitError,
23+
resolveResourceMetaData,
24+
} from 'ReactFlightDOMRelayServerIntegration';
25+
26+
export type {
27+
Destination,
28+
ModuleReference,
29+
ModuleMetaData,
30+
} from 'ReactFlightDOMRelayServerIntegration';
31+
32+
export type BundlerConfig = void;
33+
34+
export function resolveModuleMetaData(
35+
config: BundlerConfig,
36+
resource: ModuleReference,
37+
): ModuleMetaData {
38+
return resolveResourceMetaData(resource);
39+
}
1940

2041
type JSONValue =
2142
| string

0 commit comments

Comments
 (0)