SIGN IN SIGN UP
facebook / react UNCLAIMED

The library for web and native user interfaces.

0 0 0 JavaScript

Limit the number of nested synchronous updates (#10178)

* Limit the number of nested synchronous updates

In Stack, an infinite update loop would result in a stack overflow. This
gives the same behavior to Fiber.

Conceptually, I think this check belongs in findNextUnitOfWork, since
that is what we call right before starting a new stack. I've put it
in scheduleUpdate for now so I have access to the component that
triggered the nested update. But we could track that explicitly instead.

I've chosen 1000 as the limit rather arbitrarily. Most legit use cases
should really have a much smaller limit, but a smaller limit could break
existing code. For now I'm only concerned with preventing an infinite
loop. We could add a warning that fires at the smaller limit.

* Move check to findNextUnitOfWork

Including the name of the component in the message probably isn't
necessary. The JS stack will include either componentDidUpdate or
componentWillUpdate. And the component that's updating won't
necessarily be the component whose lifecycle triggered it.

So let's move the infinite loop check to findNextUnitWork as I
originally wanted to.
A
Andrew Clark committed
4dabdd2a3048b5883cc71f8c91442a905c838b6d
Parent: 999df3e
Committed by GitHub <noreply@github.com> on 7/13/2017, 10:56:02 PM