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

useTransition improvements #17418

Closed
wants to merge 5 commits into from

Commits on Jan 21, 2020

  1. Replace useTransition update queue w/ forked impl

    The `isPending` state managed by the `useTransition` queue can be
    modeled using the same queue as useState/useReducer; that's how it's
    implemented today. However, since there's only ever a single pending
    transition per `useTransition` hook, and the most recent one always
    wins, we don't really need to maintain an entire queue structure.
    
    This replaces the internal `useState` queue with a specialized
    implementation. It tracks the most recent transition expiration time
    on shared instance object, and the last processed expiration time on
    each hook copy. When the processed expiration time catches up to the
    pending one, we know that the transition is no longer pending. At a
    high level, this is also how the `useState` queue works, but without
    the overhead of an actual queue.
    
    The implementation is also inspired by Suspense boundaries, which also
    have an internal state for whether the boundary is displaying a
    fallback, but does not use an actual queue to manage that state.
    acdlite committed Jan 21, 2020
    Configuration menu
    Copy the full SHA
    0ab31d8 View commit details
    Browse the repository at this point in the history
  2. Only most recent transition is pending, per queue

    When multiple transitions update the same queue, only the most recent
    one should be considered pending.
    
    Example: If I switch tabs multiple times, only the last tab I click
    should display a pending state (e.g. an inline spinner).
    acdlite committed Jan 21, 2020
    Configuration menu
    Copy the full SHA
    1865f23 View commit details
    Browse the repository at this point in the history
  3. Only show most recent transition, per queue

    When multiple transitions update the same queue, only the most recent
    one should be allowed to finish. Do not display intermediate states.
    
    For example, if you click on multiple tabs in quick succession, we
    should not switch to any tab that isn't the last one you clicked.
    acdlite committed Jan 21, 2020
    Configuration menu
    Copy the full SHA
    55f5f0f View commit details
    Browse the repository at this point in the history
  4. Decouple expiration times and transition timeouts

    We currently use the expiration time to represent the timeout of a
    transition. Since we intend to stop treating work priority as a
    timeline, we can no longer use this trick.
    
    In this commit, I've changed it to store the event time on the update
    object instead. Long term, we will store event time on the root as a map
    of transition -> event time. I'm only storing it on the update object
    as a temporary workaround to unblock the rest of the changes.
    acdlite committed Jan 21, 2020
    Configuration menu
    Copy the full SHA
    edd241f View commit details
    Browse the repository at this point in the history
  5. Prevent intermediate transition states

    When multiple transitions update the same queue, only the most recent
    one should be allowed to finish. Do not display intermediate states.
    
    For example, if you click on multiple tabs in quick succession, we
    should not switch to any tab that isn't the last one you clicked.
    acdlite committed Jan 21, 2020
    Configuration menu
    Copy the full SHA
    734285d View commit details
    Browse the repository at this point in the history