-
Notifications
You must be signed in to change notification settings - Fork 45.7k
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
test: Add regression test for hooks after error boundaries #20002
test: Add regression test for hooks after error boundaries #20002
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit e5972d6:
|
great regression test! can this test be pushed down to react-reconciler and use the test or noop renderer? that's closer to where the regression was introduced/fixed, and that's where the ReactIncrementalErrorHandling-test currently is. |
I'll take a look over the week. Thanks for the suggestion! |
@matthargett Running /**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @emails react-core
*/
'use strict';
let React;
let ReactFeatureFlags;
let ReactNoop;
let Scheduler;
describe('ReactIncrementalErrorReplay', () => {
beforeEach(() => {
jest.resetModules();
ReactFeatureFlags = require('shared/ReactFeatureFlags');
ReactFeatureFlags.enableNewScheduler = false;
React = require('react');
ReactNoop = require('react-noop-renderer');
Scheduler = require('scheduler');
});
it('should preserve hook order if errors are caught', () => {
function ErrorThrower() {
React.useMemo(() => undefined, []);
throw new Error('expected');
}
function StatefulComponent() {
React.useState(null);
return null;
}
class ErrorHandler extends React.Component {
state = {error: null};
componentDidCatch(error) {
return this.setState({error});
}
render() {
if (this.state.error !== null) {
return <p>Handled error: {this.state.error.message}</p>;
}
return this.props.children;
}
}
function App(props) {
return (
<React.Fragment>
<ErrorHandler>
<ErrorThrower />
</ErrorHandler>
<StatefulComponent />
</React.Fragment>
);
}
ReactNoop.render(<App />);
Scheduler.flushAll();
ReactNoop.render(<App />);
Scheduler.flushAll();
});
}); right before #15387 (which was 4e59d4f) does not throw. There were some react-dom specific test branches removed (https://github.com/facebook/react/pull/15387/files#diff-67f2b3ded286ca57e398e1d05ad22e024b2dd7f91fb1016538756af542f9b9e1) so react-dom might've been the only renderer affected by this bug. |
Thanks! |
…20002) * test: Add regression test for hooks after error boundaries * fix lint
Summary
Closes #15301
Closes #15219
The issue itself is fixed starting with
16.9.0
. It was fixed in #15387.Adding it to
./packages/react-dom/src/__tests__/ReactErrorBoundaries-test.internal.js
is not sufficient since the test is passing inv16.8.6
withreplayFailedUnitOfWorkWithInvokeGuardedCallback = false
Test Plan
bisect.sh