Skip to content

Commit

Permalink
Wire up generateStaticMarkup to static API entry points
Browse files Browse the repository at this point in the history
  • Loading branch information
sebmarkbage committed Jun 14, 2021
1 parent 38cdc26 commit b24fbf8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 7 deletions.
26 changes: 22 additions & 4 deletions packages/react-dom/src/server/ReactDOMLegacyServerBrowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ function onError() {
// Non-fatal errors are ignored.
}

function renderToString(
function renderToStringImpl(
children: ReactNodeList,
options?: ServerOptions,
options: void | ServerOptions,
generateStaticMarkup: boolean,
): string {
let didFatal = false;
let fatalError = null;
Expand All @@ -59,7 +60,10 @@ function renderToString(
const request = createRequest(
children,
destination,
createResponseState(false, options ? options.identifierPrefix : undefined),
createResponseState(
generateStaticMarkup,
options ? options.identifierPrefix : undefined,
),
createRootFormatContext(undefined),
Infinity,
onError,
Expand All @@ -84,6 +88,20 @@ function renderToString(
return result;
}

function renderToString(
children: ReactNodeList,
options?: ServerOptions,
): string {
return renderToStringImpl(children, options, false);
}

function renderToStaticMarkup(
children: ReactNodeList,
options?: ServerOptions,
): string {
return renderToStringImpl(children, options, true);
}

function renderToNodeStream() {
invariant(
false,
Expand All @@ -102,7 +120,7 @@ function renderToStaticNodeStream() {

export {
renderToString,
renderToString as renderToStaticMarkup,
renderToStaticMarkup,
renderToNodeStream,
renderToStaticNodeStream,
ReactVersion as version,
Expand Down
21 changes: 18 additions & 3 deletions packages/react-dom/src/server/ReactDOMLegacyServerNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ function onError() {
// Non-fatal errors are ignored.
}

function renderToNodeStream(
function renderToNodeStreamImpl(
children: ReactNodeList,
options?: ServerOptions,
options: void | ServerOptions,
generateStaticMarkup: boolean,
): Readable {
function onCompleteAll() {
// We wait until everything has loaded before starting to write.
Expand All @@ -89,10 +90,24 @@ function renderToNodeStream(
return destination;
}

function renderToNodeStream(
children: ReactNodeList,
options?: ServerOptions,
): Readable {
return renderToNodeStreamImpl(children, options, false);
}

function renderToStaticNodeStream(
children: ReactNodeList,
options?: ServerOptions,
): Readable {
return renderToNodeStreamImpl(children, options, true);
}

export {
renderToString,
renderToStaticMarkup,
renderToNodeStream,
renderToNodeStream as renderToStaticNodeStream,
renderToStaticNodeStream,
version,
};

0 comments on commit b24fbf8

Please sign in to comment.