@samitouri / QOS-React / commits / b8441ba955

Remove ForceUpdate effect

Go back to using a flag, instead. I removed it before because I thought we might want to get rid of the top-level UpdateQueue type and put the fields directly on the fiber, but since we're keeping UpdateQueue we can put hasForceUpdate on there.

Andrew Clark committed Dec 15, 2016 at 16:35 UTC b8441ba955e08f5ad0595625e233d28c04a77867
4 files changed +21 -18
src/renderers/shared/fiber/ReactFiberClassComponent.js
+2 -3
@@ -22,7 +22,6 @@ var {
22 beginUpdateQueue,
23 } = require('ReactFiberUpdateQueue');
24 var { hasContextChanged } = require('ReactFiberContext');
25 -var { ForceUpdate } = require('ReactTypeOfSideEffect');
25 var { getComponentName, isMounted } = require('ReactFiberTreeReflection');
26 var ReactInstanceMap = require('ReactInstanceMap');
27 var shallowEqual = require('shallowEqual');
@@ -60,7 +59,7 @@ module.exports = function(
59 };
60
61 function checkShouldComponentUpdate(workInProgress, oldProps, newProps, newState, newContext) {
63 - if (oldProps === null || (workInProgress.effectTag & ForceUpdate)) {
62 + if (oldProps === null || (workInProgress.updateQueue && workInProgress.updateQueue.hasForceUpdate)) {
63 // If the workInProgress already has an Update effect, return true
64 return true;
65 }
@@ -344,7 +343,7 @@ module.exports = function(
343 if (oldProps === newProps &&
344 oldState === newState &&
345 !hasContextChanged() &&
347 - !(workInProgress.effectTag & ForceUpdate)) {
346 + !(updateQueue && updateQueue.hasForceUpdate)) {
347 return false;
348 }
349
src/renderers/shared/fiber/ReactFiberScheduler.js
+1 -2
@@ -40,7 +40,6 @@ var {
40 Placement,
41 Update,
42 PlacementAndUpdate,
43 - ForceUpdate,
43 Deletion,
44 ContentReset,
45 Callback,
@@ -224,7 +223,7 @@ module.exports = function<T, P, I, TI, C, CX>(config : HostConfig<T, P, I, TI, C
223 // possible bitmap value, we remove the secondary effects from the
224 // effect tag and switch on that value.
225 let primaryEffectTag =
227 - nextEffect.effectTag & ~(ForceUpdate | Callback | Err | ContentReset);
226 + nextEffect.effectTag & ~(Callback | Err | ContentReset);
227 switch (primaryEffectTag) {
228 case Placement: {
229 commitPlacement(nextEffect);
src/renderers/shared/fiber/ReactFiberUpdateQueue.js
+9 -3
@@ -16,7 +16,6 @@ import type { Fiber } from 'ReactFiber';
16 import type { PriorityLevel } from 'ReactPriorityLevel';
17
18 const {
19 - ForceUpdate,
19 Callback: CallbackEffect,
20 } = require('ReactTypeOfSideEffect');
21
@@ -55,6 +54,7 @@ type Update = {
54 export type UpdateQueue = {
55 first: Update | null,
56 last: Update | null,
57 + hasForceUpdate: boolean,
58
59 // Dev only
60 isProcessing?: boolean,
@@ -99,12 +99,14 @@ function ensureUpdateQueue(fiber : Fiber) : UpdateQueue {
99 queue = {
100 first: null,
101 last: null,
102 + hasForceUpdate: false,
103 isProcessing: false,
104 };
105 } else {
106 queue = {
107 first: null,
108 last: null,
109 + hasForceUpdate: false,
110 };
111 }
112
@@ -124,6 +126,7 @@ function cloneUpdateQueue(alt : Fiber, fiber : Fiber) : UpdateQueue | null {
126 const altQueue = alt.updateQueue || {};
127 altQueue.first = sourceQueue.first;
128 altQueue.last = sourceQueue.last;
129 + altQueue.hasForceUpdate = sourceQueue.hasForceUpdate;
130 alt.updateQueue = altQueue;
131 return altQueue;
132 }
@@ -392,6 +395,8 @@ function beginUpdateQueue(
395 queue.isProcessing = true;
396 }
397
398 + queue.hasForceUpdate = false;
399 +
400 // Applies updates with matching priority to the previous state to create
401 // a new state object.
402 let state = prevState;
@@ -428,7 +433,7 @@ function beginUpdateQueue(
433 }
434 }
435 if (update.isForced) {
431 - workInProgress.effectTag |= ForceUpdate;
436 + queue.hasForceUpdate = true;
437 }
438 if (update.callback) {
439 if (callbackList && callbackList.last) {
@@ -438,6 +443,7 @@ function beginUpdateQueue(
443 callbackList = {
444 first: update,
445 last: update,
446 + hasForceUpdate: false,
447 };
448 }
449 workInProgress.effectTag |= CallbackEffect;
@@ -450,7 +456,7 @@ function beginUpdateQueue(
456 state = prevState;
457 }
458
453 - if (!queue.first) {
459 + if (!queue.first && !queue.hasForceUpdate) {
460 // Queue is now empty
461 workInProgress.updateQueue = null;
462 }
src/renderers/shared/fiber/ReactTypeOfSideEffect.js
+9 -10
@@ -12,16 +12,15 @@
12
13 'use strict';
14
15 -export type TypeOfSideEffect = 0 | 1 | 2 | 3 | 4 | 8 | 16 | 32 | 64;
15 +export type TypeOfSideEffect = 0 | 1 | 2 | 3 | 4 | 8 | 16 | 32;
16
17 module.exports = {
18 - NoEffect: 0, // 0b0000000
19 - Placement: 1, // 0b0000001
20 - Update: 2, // 0b0000010
21 - PlacementAndUpdate: 3, // 0b0000011
22 - ForceUpdate: 4, // 0b0000100
23 - Deletion: 8, // 0b0001000
24 - ContentReset: 16, // 0b0010000
25 - Callback: 32, // 0b0100000
26 - Err: 64, // 0b1000000
18 + NoEffect: 0, // 0b000000
19 + Placement: 1, // 0b000001
20 + Update: 2, // 0b000010
21 + PlacementAndUpdate: 3, // 0b000011
22 + Deletion: 4, // 0b000100
23 + ContentReset: 8, // 0b001000
24 + Callback: 16, // 0b010000
25 + Err: 32, // 0b100000
26 };