Skip to content

Fix state leaking when a function component throws on server render #19212

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 8, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use expect...toThrow instead of try/catch in test
  • Loading branch information
pmaccart committed Jul 7, 2020
commit e8dfb2908b42abf02d3104fdd1c35a7282c2fc18
Original file line number Diff line number Diff line change
Expand Up @@ -889,20 +889,16 @@ describe('ReactDOMServerHooks', () => {
return <div>{count}</div>;
}

const container = document.createElement('div');

// First, render a component that will throw an error during a re-render triggered
// by a dispatch call.
try {
container.innerHTML = ReactDOMServer.renderToString(
<ThrowingComponent />,
);
} catch (e) {}
expect(container.children.length).toEqual(0);
expect(() => ReactDOMServer.renderToString(<ThrowingComponent />)).toThrow(
'Error from ThrowingComponent',
);

// Next, assert that we can render a function component using hooks immediately
// after an error occurred, which indictates the internal hooks state has been
// reset.
const container = document.createElement('div');
container.innerHTML = ReactDOMServer.renderToString(
<NonThrowingComponent />,
);
Expand Down