[WIP] Fix for fiber root scheduling memory leak (#11644)
* Fix for root memory leak * forgot to add code
Dominic Gannaway committed
Nov 28, 2017 at 20:57 UTC
363f4f14dc12a5073367086ef4edc7fc0b16aa8e
1 file changed
+24
-14
packages/react-reconciler/src/ReactFiberScheduler.js
+24
-14
@@ -1168,6 +1168,27 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
1168
return scheduleWorkImpl(fiber, expirationTime, false);
1169
}
1170
1171
+ function checkRootNeedsClearing(
1172
+ root: FiberRoot,
1173
+ fiber: Fiber,
1174
+ expirationTime: ExpirationTime,
1175
+ ) {
1176
+ if (
1177
+ !isWorking &&
1178
+ root === nextRoot &&
1179
+ expirationTime < nextRenderExpirationTime
1180
+ ) {
1181
+ // Restart the root from the top.
1182
+ if (nextUnitOfWork !== null) {
1183
+ // This is an interruption. (Used for performance tracking.)
1184
+ interruptedBy = fiber;
1185
+ }
1186
+ nextRoot = null;
1187
+ nextUnitOfWork = null;
1188
+ nextRenderExpirationTime = NoWork;
1189
+ }
1190
+ }
1191
+
1192
function scheduleWorkImpl(
1193
fiber: Fiber,
1194
expirationTime: ExpirationTime,
@@ -1203,21 +1224,10 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
1224
if (node.return === null) {
1225
if (node.tag === HostRoot) {
1226
const root: FiberRoot = (node.stateNode: any);
1206
- if (
1207
- !isWorking &&
1208
- root === nextRoot &&
1209
- expirationTime < nextRenderExpirationTime
1210
- ) {
1211
- // Restart the root from the top.
1212
- if (nextUnitOfWork !== null) {
1213
- // This is an interruption. (Used for performance tracking.)
1214
- interruptedBy = fiber;
1215
- }
1216
- nextRoot = null;
1217
- nextUnitOfWork = null;
1218
- nextRenderExpirationTime = NoWork;
1219
- }
1227
+
1228
+ checkRootNeedsClearing(root, fiber, expirationTime);
1229
requestWork(root, expirationTime);
1230
+ checkRootNeedsClearing(root, fiber, expirationTime);
1231
} else {
1232
if (__DEV__) {
1233
if (!isErrorRecovery && fiber.tag === ClassComponent) {