-
Notifications
You must be signed in to change notification settings - Fork 46.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
91e6bad
commit 917563e
Showing
17 changed files
with
388 additions
and
5 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
packages/react-client/src/forks/ReactFlightClientHostConfig.dom-legacy.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,12 @@ | ||
/** | ||
* 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 * from 'react-client/src/ReactFlightClientHostConfigBrowser'; | ||
export * from 'react-client/src/ReactFlightClientHostConfigStream'; | ||
export * from 'react-server-dom-webpack/src/ReactFlightClientWebpackBundlerConfig'; |
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,16 @@ | ||
/** | ||
* 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 { | ||
renderToString, | ||
renderToStaticMarkup, | ||
renderToNodeStream, | ||
renderToStaticNodeStream, | ||
version, | ||
} from './src/server/ReactDOMServerBrowser'; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* 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 { | ||
renderToString, | ||
renderToStaticMarkup, | ||
renderToNodeStream, | ||
renderToStaticNodeStream, | ||
version, | ||
} from './src/server/ReactDOMServerBrowser'; |
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,17 @@ | ||
/** | ||
* 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 | ||
*/ | ||
|
||
// For some reason Flow doesn't like export * in this file. I don't know why. | ||
export { | ||
renderToString, | ||
renderToStaticMarkup, | ||
renderToNodeStream, | ||
renderToStaticNodeStream, | ||
version, | ||
} from './src/server/ReactDOMServerNode'; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* 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 | ||
*/ | ||
|
||
// For some reason Flow doesn't like export * in this file. I don't know why. | ||
export { | ||
renderToString, | ||
renderToStaticMarkup, | ||
renderToNodeStream, | ||
renderToStaticNodeStream, | ||
version, | ||
} from './src/server/ReactDOMServerNode'; |
97 changes: 97 additions & 0 deletions
97
packages/react-dom/src/server/ReactDOMLegacyServerBrowser.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,97 @@ | ||
/** | ||
* 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 | ||
*/ | ||
|
||
import ReactVersion from 'shared/ReactVersion'; | ||
import invariant from 'shared/invariant'; | ||
|
||
import type {ReactNodeList} from 'shared/ReactTypes'; | ||
|
||
import { | ||
createRequest, | ||
startWork, | ||
startFlowing, | ||
abort, | ||
} from 'react-server/src/ReactFizzServer'; | ||
|
||
import { | ||
createResponseState, | ||
createRootFormatContext, | ||
} from './ReactDOMServerFormatConfig'; | ||
|
||
type ServerOptions = { | ||
identifierPrefix?: string, | ||
}; | ||
|
||
function onError() { | ||
// Non-fatal errors are ignored. | ||
} | ||
|
||
function renderToString( | ||
children: ReactNodeList, | ||
options?: ServerOptions, | ||
): string { | ||
let didFatal = false; | ||
let fatalError = null; | ||
const result = []; | ||
const destination = { | ||
push(chunk) { | ||
if (chunk) { | ||
result.push(chunk); | ||
} | ||
return true; | ||
}, | ||
destroy(error) { | ||
didFatal = true; | ||
fatalError = error; | ||
}, | ||
}; | ||
const request = createRequest( | ||
children, | ||
destination, | ||
createResponseState(options ? options.identifierPrefix : undefined), | ||
createRootFormatContext(undefined), | ||
Infinity, | ||
onError, | ||
undefined, | ||
undefined, | ||
); | ||
startWork(request); | ||
// If anything suspended and is still pending, we'll abort it before writing. | ||
// That way we write only client-rendered boundaries from the start. | ||
abort(request); | ||
startFlowing(request); | ||
if (didFatal) { | ||
throw fatalError; | ||
} | ||
return result.join(''); | ||
} | ||
|
||
function renderToNodeStream() { | ||
invariant( | ||
false, | ||
'ReactDOMServer.renderToNodeStream(): The streaming API is not available ' + | ||
'in the browser. Use ReactDOMServer.renderToString() instead.', | ||
); | ||
} | ||
|
||
function renderToStaticNodeStream() { | ||
invariant( | ||
false, | ||
'ReactDOMServer.renderToStaticNodeStream(): The streaming API is not available ' + | ||
'in the browser. Use ReactDOMServer.renderToStaticMarkup() instead.', | ||
); | ||
} | ||
|
||
export { | ||
renderToString, | ||
renderToString as renderToStaticMarkup, | ||
renderToNodeStream, | ||
renderToStaticNodeStream, | ||
ReactVersion as version, | ||
}; |
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,98 @@ | ||
/** | ||
* 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 | ||
*/ | ||
|
||
import type {ReactNodeList} from 'shared/ReactTypes'; | ||
|
||
import type {Request} from 'react-server/src/ReactFizzServer'; | ||
|
||
import { | ||
createRequest, | ||
startWork, | ||
startFlowing, | ||
abort, | ||
} from 'react-server/src/ReactFizzServer'; | ||
|
||
import { | ||
createResponseState, | ||
createRootFormatContext, | ||
} from './ReactDOMServerFormatConfig'; | ||
|
||
import { | ||
version, | ||
renderToString, | ||
renderToStaticMarkup, | ||
} from './ReactDOMLegacyServerBrowser'; | ||
|
||
import {Readable} from 'stream'; | ||
|
||
type ServerOptions = { | ||
identifierPrefix?: string, | ||
}; | ||
|
||
class ReactMarkupReadableStream extends Readable { | ||
request: Request; | ||
startedFlowing: boolean; | ||
constructor() { | ||
// Calls the stream.Readable(options) constructor. Consider exposing built-in | ||
// features like highWaterMark in the future. | ||
super({}); | ||
this.request = (null: any); | ||
this.startedFlowing = false; | ||
} | ||
|
||
_destroy(err, callback) { | ||
abort(this.request); | ||
// $FlowFixMe: The type definition for the callback should allow undefined and null. | ||
callback(err); | ||
} | ||
|
||
_read(size) { | ||
if (this.startedFlowing) { | ||
startFlowing(this.request); | ||
} | ||
} | ||
} | ||
|
||
function onError() { | ||
// Non-fatal errors are ignored. | ||
} | ||
|
||
function renderToNodeStream( | ||
children: ReactNodeList, | ||
options?: ServerOptions, | ||
): Readable { | ||
function onCompleteAll() { | ||
// We wait until everything has loaded before starting to write. | ||
// That way we only end up with fully resolved HTML even if we suspend. | ||
destination.startedFlowing = true; | ||
startFlowing(request); | ||
} | ||
const destination = new ReactMarkupReadableStream(); | ||
const request = createRequest( | ||
children, | ||
destination, | ||
createResponseState(options ? options.identifierPrefix : undefined), | ||
createRootFormatContext(undefined), | ||
Infinity, | ||
onError, | ||
onCompleteAll, | ||
undefined, | ||
); | ||
destination.request = request; | ||
startWork(request); | ||
return destination; | ||
} | ||
|
||
export { | ||
renderToString, | ||
renderToStaticMarkup, | ||
renderToNodeStream, | ||
renderToNodeStream as renderToStaticNodeStream, | ||
version, | ||
}; |
51 changes: 51 additions & 0 deletions
51
packages/react-dom/src/server/ReactDOMLegacyServerStreamConfig.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,51 @@ | ||
/** | ||
* 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 Destination = { | ||
push(chunk: string | null): boolean, | ||
destroy(error: Error): mixed, | ||
... | ||
}; | ||
|
||
export type PrecomputedChunk = string; | ||
export type Chunk = string; | ||
|
||
export function scheduleWork(callback: () => void) { | ||
callback(); | ||
} | ||
|
||
export function flushBuffered(destination: Destination) {} | ||
|
||
export function beginWriting(destination: Destination) {} | ||
|
||
export function writeChunk( | ||
destination: Destination, | ||
chunk: Chunk | PrecomputedChunk, | ||
): boolean { | ||
return destination.push(chunk); | ||
} | ||
|
||
export function completeWriting(destination: Destination) {} | ||
|
||
export function close(destination: Destination) { | ||
destination.push(null); | ||
} | ||
|
||
export function stringToChunk(content: string): Chunk { | ||
return content; | ||
} | ||
|
||
export function stringToPrecomputedChunk(content: string): PrecomputedChunk { | ||
return content; | ||
} | ||
|
||
export function closeWithError(destination: Destination, error: mixed): void { | ||
// $FlowFixMe: This is an Error object or the destination accepts other types. | ||
destination.destroy(error); | ||
} |
10 changes: 10 additions & 0 deletions
10
packages/react-reconciler/src/forks/ReactFiberHostConfig.dom-legacy.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,10 @@ | ||
/** | ||
* 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 * from 'react-dom/src/client/ReactDOMHostConfig'; |
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
11 changes: 11 additions & 0 deletions
11
packages/react-server/src/forks/ReactFlightServerConfig.dom-legacy.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,11 @@ | ||
/** | ||
* 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 * from '../ReactFlightServerConfigStream'; | ||
export * from 'react-server-dom-webpack/src/ReactFlightServerWebpackBundlerConfig'; |
10 changes: 10 additions & 0 deletions
10
packages/react-server/src/forks/ReactServerFormatConfig.dom-legacy.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,10 @@ | ||
/** | ||
* 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 * from 'react-dom/src/server/ReactDOMServerFormatConfig'; |
10 changes: 10 additions & 0 deletions
10
packages/react-server/src/forks/ReactServerStreamConfig.dom-legacy.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,10 @@ | ||
/** | ||
* 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 * from 'react-dom/src/server/ReactDOMLegacyServerStreamConfig'; |
Oops, something went wrong.