Skip to content

Commit

Permalink
Error if we can't complete the root synchronously
Browse files Browse the repository at this point in the history
Maybe this should always error but in the async forms we can just delay
the stream until it resolves so it does have some useful semantics.

In the synchronous form it's never useful though. I'm mostly adding the
error because we're testing this behavior for renderToString specifically.
  • Loading branch information
sebmarkbage committed Apr 27, 2021
1 parent 2213bf0 commit 6fdc530
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion packages/react-dom/src/server/ReactDOMLegacyServerBrowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ function renderToString(
fatalError = error;
},
};

let readyToStream = false;
function onReadyToStream() {
readyToStream = true;
}
const request = createRequest(
children,
destination,
Expand All @@ -59,7 +64,7 @@ function renderToString(
Infinity,
onError,
undefined,
undefined,
onReadyToStream,
);
startWork(request);
// If anything suspended and is still pending, we'll abort it before writing.
Expand All @@ -69,6 +74,13 @@ function renderToString(
if (didFatal) {
throw fatalError;
}
invariant(
readyToStream,
'A React component suspended while rendering, but no fallback UI was specified.\n' +
'\n' +
'Add a <Suspense fallback=...> component higher in the tree to ' +
'provide a loading indicator or placeholder to display.',
);
return result;
}

Expand Down

0 comments on commit 6fdc530

Please sign in to comment.