-
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
6b7281e
commit 8206b4b
Showing
26 changed files
with
266 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 = { | ||
preloadModule(jsResource) { | ||
return null; | ||
}, | ||
requireModule(jsResource) { | ||
return 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
53 changes: 53 additions & 0 deletions
53
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,53 @@ | ||
/** | ||
* 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<string>, | ||
}; | ||
|
||
type Thenable = { | ||
then(resolve: () => mixed, reject: (mixed) => mixed): mixed, | ||
... | ||
}; | ||
|
||
// The chunk cache contains all the chunks we've preloaded so far. | ||
// If they're still pending they're a thenable. This map also exists | ||
// in Webpack but unfortunately it's not exposed so we have to | ||
// replicate it in user space. null means that it has already loaded. | ||
const chunkCache: Map<string, null | Thenable> = new Map(); | ||
|
||
// Returning null means that all dependencies are fulfilled and we | ||
// can synchronously require the module now. A thenable is returned | ||
// that when resolved, means we can try again. | ||
export function preloadModule(moduleData: ModuleMetaData): null | Thenable { | ||
let moduleEntry = require.cache[moduleData.id]; | ||
if (moduleEntry) { | ||
// Fast exit if this module has already been loaded. | ||
return null; | ||
} | ||
let chunks = moduleData.chunks; | ||
let anyRemainingThenable = null; | ||
for (let i = 0; i < chunks.length; i++) { | ||
let chunkId = chunks[i]; | ||
let entry = chunkCache.get(chunkId); | ||
if (entry === undefined) { | ||
anyRemainingThenable = __webpack_chunk_load__(chunkId); | ||
chunkCache.set(chunkId, anyRemainingThenable); | ||
anyRemainingThenable.then(chunkCache.set.bind(chunkCache, chunkId, null)); | ||
} else if (entry !== null) { | ||
anyRemainingThenable = entry; | ||
} | ||
} | ||
return anyRemainingThenable; | ||
} | ||
|
||
export function requireModule<T>(moduleData: ModuleMetaData): T { | ||
return __webpack_require__(moduleData.id).default; | ||
} |
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<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
Oops, something went wrong.