MCPcopy Index your code
hub / github.com/react/react / renderToStringImpl

Function renderToStringImpl

packages/react-dom/src/server/ReactDOMLegacyServerImpl.js:35–101  ·  view source on GitHub ↗
(
  children: ReactNodeList,
  options: void | ServerOptions,
  generateStaticMarkup: boolean,
  abortReason: string,
)

Source from the content-addressed store, hash-verified

33}
34
35function renderToStringImpl(
36 children: ReactNodeList,
37 options: void | ServerOptions,
38 generateStaticMarkup: boolean,
39 abortReason: string,
40): string {
41 let didFatal = false;
42 let fatalError = null;
43 let result = '';
44 const destination = {
45 // $FlowFixMe[missing-local-annot]
46 push(chunk) {
47 if (chunk !== null) {
48 result += chunk;
49 }
50 return true;
51 },
52 // $FlowFixMe[missing-local-annot]
53 destroy(error) {
54 didFatal = true;
55 fatalError = error;
56 },
57 };
58
59 let readyToStream = false;
60 function onShellReady() {
61 readyToStream = true;
62 }
63 const resumableState = createResumableState(
64 options ? options.identifierPrefix : undefined,
65 undefined,
66 );
67 const request = createRequest(
68 children,
69 resumableState,
70 createRenderState(resumableState, generateStaticMarkup),
71 createRootFormatContext(),
72 Infinity,
73 onError,
74 undefined,
75 onShellReady,
76 undefined,
77 undefined,
78 undefined,
79 );
80 startWork(request);
81 // If anything suspended and is still pending, we'll abort it before writing.
82 // That way we write only client-rendered boundaries from the start.
83 abort(request, abortReason);
84 startFlowing(request, destination);
85 if (didFatal && fatalError !== abortReason) {
86 throw fatalError;
87 }
88
89 if (!readyToStream) {
90 // Note: This error message is the one we use on the client. It doesn't
91 // really make sense here. But this is the legacy server renderer, anyway.
92 // We're going to delete it soon.

Callers 4

renderToStringFunction · 0.90
renderToStaticMarkupFunction · 0.90
renderToStringFunction · 0.90
renderToStaticMarkupFunction · 0.90

Calls 7

createRequestFunction · 0.90
createRenderStateFunction · 0.90
startWorkFunction · 0.90
abortFunction · 0.90
startFlowingFunction · 0.90
createResumableStateFunction · 0.85
createRootFormatContextFunction · 0.50

Tested by

no test coverage detected