Revert "[Old server renderer] Retry error on client (#22399)"

Going to revert this until we figure out error reporting. It looks like
our downstream infra already supports some type of error recovery so
we might not need it here.
This commit is contained in:
Andrew Clark 2021-09-22 12:31:17 -04:00
parent 5a06072780
commit 51e017c523
No known key found for this signature in database
GPG Key ID: 542E2C5D4AD706D4
3 changed files with 12 additions and 65 deletions

View File

@ -2671,32 +2671,4 @@ describe('ReactDOMServerPartialHydration', () => {
expect(ref.current).toBe(span);
expect(ref.current.innerHTML).toBe('Hidden child');
});
it('should retry on client if something throws', async () => {
let isServer = true;
function ThrowsOnServerOnly() {
if (isServer) {
throw new Error('Oops!');
}
return 'Yay!';
}
function App() {
return (
<React.Suspense fallback="Loading...">
<ThrowsOnServerOnly />
</React.Suspense>
);
}
const element = document.createElement('div');
element.innerHTML = ReactDOMServer.renderToString(<App />);
expect(element.textContent).toBe('Loading...');
isServer = false;
await act(async () => {
ReactDOM.hydrateRoot(element, <App />);
});
expect(element.textContent).toBe('Yay!');
});
});

View File

@ -115,20 +115,6 @@ describe('ReactDOMServerSuspense', () => {
expect(getVisibleChildren(c)).toEqual(<div>Fallback</div>);
});
it('should render the fallback when an error is thrown', async () => {
function Throws() {
throw new Error('Oops!');
}
const c = await serverRender(
<div>
<React.Suspense fallback={<Text text="Fallback" />}>
<Throws />
</React.Suspense>
</div>,
);
expect(getVisibleChildren(c)).toEqual(<div>Fallback</div>);
});
it('should work with nested suspense components', async () => {
const c = await serverRender(
<div>

View File

@ -969,33 +969,22 @@ class ReactDOMServerRenderer {
try {
outBuffer += this.render(child, frame.context, frame.domNamespace);
} catch (err) {
if (enableSuspenseServerRenderer) {
if (this.suspenseDepth > 0) {
// Regardless of whether this is an error or a suspense thenable,
// trigger the nearest Suspense boundary. We'll try to render this
// tree again on the client.
if (err != null && typeof err.then === 'function') {
if (enableSuspenseServerRenderer) {
invariant(
this.suspenseDepth > 0,
// TODO: include component name. This is a bit tricky with current factoring.
'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.',
);
suspended = true;
} else {
// Missing a Suspense boundary. This is a fatal error.
if (err != null && typeof err.then === 'function') {
invariant(
false,
// TODO: include component name. This is a bit tricky with current factoring.
'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.',
);
} else {
throw err;
}
invariant(false, 'ReactDOMServer does not yet support Suspense.');
}
} else {
if (err != null && typeof err.then === 'function') {
invariant(false, 'ReactDOMServer does not yet support Suspense.');
} else {
throw err;
}
throw err;
}
} finally {
if (__DEV__) {