@samitouri / QOS-React-2 / commits / 7d3db0e5ed
Fork 0

The library for web and native user interfaces.

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.

Pete Hunt committed Jul 3, 2013 at 11:38 UTC 7d3db0e5ed2964b89874246d0efc72d75af58ede
1 file changed +24 -19
src/core/ReactUpdates.js
+24 -19
@@ -36,29 +36,34 @@ function batchedUpdates(callback) {
36 );
37 isBatchingUpdates = true;
38
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 + }
57 }
58 }
59 }
60 + } catch (error) {
61 + // IE8 requires `catch` in order to use `finally`.
62 + throw error;
63 + } finally {
64 + dirtyComponents.length = 0;
65 + isBatchingUpdates = false;
66 }
59 - dirtyComponents.length = 0;
60 -
61 - isBatchingUpdates = false;
67 }
68
69 /**