Skip to content

Commit ee437ed

Browse files
committed
Fixed DEV mode issue with synchronously caused event (i.e. by accessed ref) of the same type within a handler calling an original handler too (fixes facebook#8559)
1 parent 4a7e06b commit ee437ed

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

Diff for: src/renderers/shared/stack/reconciler/ReactCompositeComponent.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ var ReactCompositeComponent = {
568568
if (safely) {
569569
if (!skipLifecycle) {
570570
var name = this.getName() + '.componentWillUnmount()';
571-
ReactErrorUtils.invokeGuardedCallback(name, inst.componentWillUnmount.bind(inst));
571+
ReactErrorUtils.invokeGuardedCallbackWithCatch(name, inst.componentWillUnmount.bind(inst));
572572
}
573573
} else {
574574
if (__DEV__) {

Diff for: src/renderers/shared/utils/ReactErrorUtils.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,15 @@ if (__DEV__) {
7272
func: (a: A) => void,
7373
a: A,
7474
): void {
75-
var boundFunc = function() {
75+
var evtType = `react-${name}`;
76+
var boundFunc = () => {
77+
fakeNode.removeEventListener(evtType, boundFunc, false);
7678
func(a);
7779
};
78-
var evtType = `react-${name}`;
7980
fakeNode.addEventListener(evtType, boundFunc, false);
8081
var evt = document.createEvent('Event');
8182
evt.initEvent(evtType, false, false);
8283
fakeNode.dispatchEvent(evt);
83-
fakeNode.removeEventListener(evtType, boundFunc, false);
8484
};
8585
}
8686
}

Diff for: src/renderers/shared/utils/__tests__/ReactErrorUtils-test.js

+11
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ var ReactErrorUtils;
1616
describe('ReactErrorUtils', () => {
1717

1818
beforeEach(() => {
19+
jest.resetModules();
1920
ReactErrorUtils = require('ReactErrorUtils');
2021
});
2122

@@ -71,5 +72,15 @@ describe('ReactErrorUtils', () => {
7172
__DEV__ = true;
7273
global.process = oldProcess;
7374
});
75+
76+
it('shouldn\'t call the callback again while executing synchronously induced other call in development', () => {
77+
var callback = jest.fn(() => {
78+
ReactErrorUtils.invokeGuardedCallback('foo', callback2, 'arg', true);
79+
});
80+
var callback2 = jest.fn();
81+
ReactErrorUtils.invokeGuardedCallback('foo', callback, 'arg', true);
82+
expect(callback).toHaveBeenCalledTimes(1);
83+
expect(callback2).toHaveBeenCalledTimes(1);
84+
});
7485
});
7586
});

0 commit comments

Comments
 (0)