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
Showing
4 changed files
with
130 additions
and
90 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
packages/react-dom/src/server/ReactDOMLegacyServerNode.classic.fb.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,19 @@ | ||
/** | ||
* 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, | ||
version, | ||
} from './ReactDOMServerLegacyPartialRendererBrowser'; | ||
|
||
export { | ||
renderToNodeStream, | ||
renderToStaticNodeStream, | ||
} from './ReactDOMLegacyServerNodeStream'; |
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
106 changes: 106 additions & 0 deletions
106
packages/react-dom/src/server/ReactDOMLegacyServerNodeStream.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,106 @@ | ||
/** | ||
* 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 './ReactDOMServerLegacyFormatConfig'; | ||
|
||
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, this); | ||
} | ||
} | ||
} | ||
|
||
function onError() { | ||
// Non-fatal errors are ignored. | ||
} | ||
|
||
function renderToNodeStreamImpl( | ||
children: ReactNodeList, | ||
options: void | ServerOptions, | ||
generateStaticMarkup: boolean, | ||
): Readable { | ||
function onAllReady() { | ||
// 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, destination); | ||
} | ||
const destination = new ReactMarkupReadableStream(); | ||
const request = createRequest( | ||
children, | ||
createResponseState(false, options ? options.identifierPrefix : undefined), | ||
createRootFormatContext(), | ||
Infinity, | ||
onError, | ||
onAllReady, | ||
undefined, | ||
undefined, | ||
); | ||
destination.request = request; | ||
startWork(request); | ||
return destination; | ||
} | ||
|
||
function renderToNodeStream( | ||
children: ReactNodeList, | ||
options?: ServerOptions, | ||
): Readable { | ||
if (__DEV__) { | ||
console.error( | ||
'renderToNodeStream is deprecated. Use renderToPipeableStream instead.', | ||
); | ||
} | ||
return renderToNodeStreamImpl(children, options, false); | ||
} | ||
|
||
function renderToStaticNodeStream( | ||
children: ReactNodeList, | ||
options?: ServerOptions, | ||
): Readable { | ||
return renderToNodeStreamImpl(children, options, true); | ||
} | ||
|
||
export {renderToNodeStream, renderToStaticNodeStream}; |
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