Skip to content

Commit f1f9e20

Browse files
committed
Error if we can't complete the root synchronously
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.
1 parent 0e11bc6 commit f1f9e20

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

packages/react-dom/src/server/ReactDOMLegacyServerBrowser.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ function renderToString(
5151
fatalError = error;
5252
},
5353
};
54+
55+
let readyToStream = false;
56+
function onReadyToStream() {
57+
readyToStream = true;
58+
}
5459
const request = createRequest(
5560
children,
5661
destination,
@@ -59,7 +64,7 @@ function renderToString(
5964
Infinity,
6065
onError,
6166
undefined,
62-
undefined,
67+
onReadyToStream,
6368
);
6469
startWork(request);
6570
// If anything suspended and is still pending, we'll abort it before writing.
@@ -69,6 +74,13 @@ function renderToString(
6974
if (didFatal) {
7075
throw fatalError;
7176
}
77+
invariant(
78+
readyToStream,
79+
'A React component suspended while rendering, but no fallback UI was specified.\n' +
80+
'\n' +
81+
'Add a <Suspense fallback=...> component higher in the tree to ' +
82+
'provide a loading indicator or placeholder to display.',
83+
);
7284
return result;
7385
}
7486

0 commit comments

Comments
 (0)