Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow useReducer to bail out of rendering by returning previous state #14569

Merged
merged 4 commits into from
Jan 17, 2019

Commits on Jan 17, 2019

  1. Allow useReducer to bail out of rendering by returning previous state

    This is conceptually similar to `shouldComponentUpdate`, except because
    there could be multiple useReducer (or useState) Hooks in a single
    component, we can only bail out if none of the Hooks produce a new
    value. We also can't bail out if any the other types of inputs — state
    and context — have changed.
    
    These optimizations rely on the constraint that components are pure
    functions of props, state, and context.
    
    In some cases, we can bail out without entering the render phase by
    eagerly computing the next state and comparing it to the current one.
    This only works if we are absolutely certain that the queue is empty at
    the time of the update. In concurrent mode, this is difficult to
    determine, because there could be multiple copies of the queue and we
    don't know which one is current without doing lots of extra work, which
    would defeat the purpose of the optimization. However, in our
    implementation, there are at most only two copies of the queue, and if
    *both* are empty then we know that the current queue must be.
    acdlite committed Jan 17, 2019
    Configuration menu
    Copy the full SHA
    1aaea28 View commit details
    Browse the repository at this point in the history
  2. Add test for context consumers inside hidden subtree

    Should not bail out during subsequent update. (This isn't directly
    related to this PR because we should have had this test, anyway.)
    acdlite committed Jan 17, 2019
    Configuration menu
    Copy the full SHA
    535d76c View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    667f163 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    6c9ae30 View commit details
    Browse the repository at this point in the history