Skip to content

Commit a8f5e77

Browse files
authored
Remove invokeGuardedCallback from commit phase (facebook#21666)
* Remove invokeGuardedCallback from commit phase * Sync fork
1 parent dbe3363 commit a8f5e77

File tree

4 files changed

+172
-636
lines changed

4 files changed

+172
-636
lines changed

packages/react-dom/src/__tests__/ReactDOM-test.js

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -408,49 +408,6 @@ describe('ReactDOM', () => {
408408
}
409409
});
410410

411-
it('throws in DEV if jsdom is destroyed by the time setState() is called', () => {
412-
class App extends React.Component {
413-
state = {x: 1};
414-
componentDidUpdate() {}
415-
render() {
416-
return <div />;
417-
}
418-
}
419-
const container = document.createElement('div');
420-
const instance = ReactDOM.render(<App />, container);
421-
const documentDescriptor = Object.getOwnPropertyDescriptor(
422-
global,
423-
'document',
424-
);
425-
try {
426-
// Emulate jsdom environment cleanup.
427-
// This is roughly what happens if the test finished and then
428-
// an asynchronous callback tried to setState() after this.
429-
delete global.document;
430-
431-
// The error we're interested in is thrown by invokeGuardedCallback, which
432-
// in DEV is used 1) to replay a failed begin phase, or 2) when calling
433-
// lifecycle methods. We're triggering the second case here.
434-
const fn = () => instance.setState({x: 2});
435-
if (__DEV__) {
436-
expect(fn).toThrow(
437-
'The `document` global was defined when React was initialized, but is not ' +
438-
'defined anymore. This can happen in a test environment if a component ' +
439-
'schedules an update from an asynchronous callback, but the test has already ' +
440-
'finished running. To solve this, you can either unmount the component at ' +
441-
'the end of your test (and ensure that any asynchronous operations get ' +
442-
'canceled in `componentWillUnmount`), or you can change the test itself ' +
443-
'to be asynchronous.',
444-
);
445-
} else {
446-
expect(fn).not.toThrow();
447-
}
448-
} finally {
449-
// Don't break other tests.
450-
Object.defineProperty(global, 'document', documentDescriptor);
451-
}
452-
});
453-
454411
it('reports stacks with re-entrant renderToString() calls on the client', () => {
455412
function Child2(props) {
456413
return <span ariaTypo3="no">{props.children}</span>;

0 commit comments

Comments
 (0)