Skip to content

Commit 7d3db0e

Browse files
petehuntzpao
authored andcommitted
Add finally block for clearing ReactUpdates state
If any component throws during reconciliation any subsequent reconciliation will break badly because ReactUpdates will be in an inconsistent state. Add a finally block to prevent this.
1 parent 2869e5b commit 7d3db0e

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

src/core/ReactUpdates.js

+24-19
Original file line numberDiff line numberDiff line change
@@ -36,29 +36,34 @@ function batchedUpdates(callback) {
3636
);
3737
isBatchingUpdates = true;
3838

39-
callback();
40-
// TODO: Sort components by depth such that parent components update first
41-
for (var i = 0; i < dirtyComponents.length; i++) {
42-
// If a component is unmounted before pending changes apply, ignore them
43-
// TODO: Queue unmounts in the same list to avoid this happening at all
44-
var component = dirtyComponents[i];
45-
if (component.isMounted()) {
46-
// If performUpdateIfNecessary happens to enqueue any new updates, we
47-
// shouldn't execute the callbacks until the next render happens, so
48-
// stash the callbacks first
49-
var callbacks = component._pendingCallbacks;
50-
component._pendingCallbacks = null;
51-
component.performUpdateIfNecessary();
52-
if (callbacks) {
53-
for (var j = 0; j < callbacks.length; j++) {
54-
callbacks[j]();
39+
try {
40+
callback();
41+
// TODO: Sort components by depth such that parent components update first
42+
for (var i = 0; i < dirtyComponents.length; i++) {
43+
// If a component is unmounted before pending changes apply, ignore them
44+
// TODO: Queue unmounts in the same list to avoid this happening at all
45+
var component = dirtyComponents[i];
46+
if (component.isMounted()) {
47+
// If performUpdateIfNecessary happens to enqueue any new updates, we
48+
// shouldn't execute the callbacks until the next render happens, so
49+
// stash the callbacks first
50+
var callbacks = component._pendingCallbacks;
51+
component._pendingCallbacks = null;
52+
component.performUpdateIfNecessary();
53+
if (callbacks) {
54+
for (var j = 0; j < callbacks.length; j++) {
55+
callbacks[j]();
56+
}
5557
}
5658
}
5759
}
60+
} catch (error) {
61+
// IE8 requires `catch` in order to use `finally`.
62+
throw error;
63+
} finally {
64+
dirtyComponents.length = 0;
65+
isBatchingUpdates = false;
5866
}
59-
dirtyComponents.length = 0;
60-
61-
isBatchingUpdates = false;
6267
}
6368

6469
/**

0 commit comments

Comments
 (0)