@samitouri / QOS-React / commits / ddc91af795

Decrease nested update limit from 1000 to 50 (#13163)

An infinite update loop can occur when an update is scheduled inside a lifecycle method, which causes a re-render, which schedules another update, and so on. Before the Fiber rewrite, this scenario resulted in a stack overflow. Because Fiber does not use the JavaScript stack, we maintain our own counter to track the number of nested, synchronous updates. We throw an error if the limit is exceeded. The nested update limit is currently 1000. I chose this number arbitrarily, certain that there was no valid reason for a component to schedule so many synchronous re-renders. I think we can go much lower. This commit decreases the limit to 50. I believe this is still comfortably above the reasonable number of synchronous re-renders a component may perform. This will make it easier for developers to debug infinite update bugs when they occur.

Andrew Clark committed Jul 6, 2018 at 15:50 UTC ddc91af7957f3cca6910a95cef71076897ebdb53
1 file changed +1 -1
packages/react-reconciler/src/ReactFiberScheduler.js
+1 -1
@@ -1544,7 +1544,7 @@ let currentRendererTime: ExpirationTime = msToExpirationTime(
1544 let currentSchedulerTime: ExpirationTime = currentRendererTime;
1545
1546 // Use these to prevent an infinite loop of nested updates
1547 -const NESTED_UPDATE_LIMIT = 1000;
1547 +const NESTED_UPDATE_LIMIT = 50;
1548 let nestedUpdateCount: number = 0;
1549 let lastCommittedRootDuringThisBatch: FiberRoot | null = null;
1550