-
Notifications
You must be signed in to change notification settings - Fork 47.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This allows different flight server and clients to have different configs depending on bundler to serialize and resolve modules.
- Loading branch information
1 parent
aae83a4
commit 0d94205
Showing
26 changed files
with
259 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
packages/react-client/src/ReactFlightClientHostConfigNoStream.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
export type StringDecoder = void; | ||
|
||
export const supportsBinaryStreams = false; | ||
|
||
export function createStringDecoder(): void { | ||
throw new Error('Should never be called'); | ||
} | ||
|
||
export function readPartialStringChunk( | ||
decoder: StringDecoder, | ||
buffer: Uint8Array, | ||
): string { | ||
throw new Error('Should never be called'); | ||
} | ||
|
||
export function readFinalStringChunk( | ||
decoder: StringDecoder, | ||
buffer: Uint8Array, | ||
): string { | ||
throw new Error('Should never be called'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
packages/react-flight-dom-relay/src/__mocks__/ReactFlightDOMRelayClientIntegration.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
function getFakeModule() { | ||
return function FakeModule(props, data) { | ||
return data; | ||
}; | ||
} | ||
|
||
const ReactFlightDOMRelayClientIntegration = { | ||
requireModuleIfAvailable(jsResource) { | ||
return getFakeModule(); | ||
}, | ||
waitForModule(jsResource) { | ||
return Promise.resolve(getFakeModule()); | ||
}, | ||
}; | ||
|
||
module.exports = ReactFlightDOMRelayClientIntegration; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
packages/react-flight-dom-webpack/src/ReactFlightClientWebpackBundlerConfig.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
export type ModuleMetaData = { | ||
id: string, | ||
chunks: Array<Array<string>>, | ||
}; | ||
|
||
export type Thenable = { | ||
then(resolve: () => mixed, reject: (mixed) => mixed): mixed, | ||
... | ||
}; | ||
|
||
export function requireModuleIfAvailable<T>( | ||
moduleData: ModuleMetaData, | ||
): T | null { | ||
let entry = require.cache[moduleData.id]; | ||
if (entry) { | ||
return entry.exports.default; | ||
} | ||
// Ideally Webpack would let us inspect that all chunks have loaded and | ||
// just call require synchronously here. Unfortunately, the chunk cache | ||
// doesn't expose this information without creating a Promise first. | ||
// This causes an unfortunate exponential many-pass render since each | ||
// level in the tree will restart to initialize that module. | ||
// This will lead to unacceptable performance in React and will need | ||
// changes to Webpack. | ||
return null; | ||
} | ||
|
||
export function waitForModule(moduleData: ModuleMetaData): Thenable { | ||
let chunks = moduleData.chunks[0]; // First candidate | ||
if (chunks.length === 1) { | ||
return __webpack_chunk_load__(chunks[0]); | ||
} else { | ||
let promises = []; | ||
for (let i = 0; i < chunks.length; i++) { | ||
promises.push(__webpack_chunk_load__(chunks[i])); | ||
} | ||
return Promise.all(promises); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
packages/react-flight-dom-webpack/src/ReactFlightServerWebpackBundlerConfig.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
type WebpackMap = { | ||
[filename: string]: ModuleMetaData, | ||
}; | ||
|
||
export type BundlerConfig = WebpackMap; | ||
|
||
export type ModuleReference = string; | ||
|
||
export type ModuleMetaData = { | ||
id: string, | ||
chunks: Array<Array<string>>, | ||
}; | ||
|
||
export function resolveModuleMetaData( | ||
config: BundlerConfig, | ||
modulePath: ModuleReference, | ||
): ModuleMetaData { | ||
return config[modulePath]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
packages/react-server/src/ReactFlightServerBundlerConfigCustom.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
declare var $$$hostConfig: any; | ||
|
||
export opaque type BundlerConfig = mixed; // eslint-disable-line no-undef | ||
export opaque type ModuleReference = mixed; // eslint-disable-line no-undef | ||
export opaque type ModuleMetaData = mixed; // eslint-disable-line no-undef | ||
export const resolveModuleMetaData = $$$hostConfig.resolveModuleMetaData; |
Oops, something went wrong.