Upgrade to Pro — share decks privately, control downloads, hide ads and more …

The Future of React with Fiber

The Future of React with Fiber

Avatar for Sidhartha Chatterjee

Sidhartha Chatterjee

September 10, 2017
Tweet

More Decks by Sidhartha Chatterjee

Other Decks in Programming

Transcript

  1. Introduction • React is awesome • New reconciliation algorithm, Fiber

    is now in beta • Async Scheduling • Powerful new primitives
  2. Why Fiber? • Reconciliation of non-vital elements is costly •

    Especially with things like animations • Prioritize work and speed up the overall frame rate
  3. What is a Fiber? • A virtual stack frame •

    Pausable / Prioritizable / Memoizable / Abortable • A unit of “work"
  4. Fiber Prioritization ReactPriorityLevel { NoWork: 0, SynchronousPriority: 1, AnimationPriority: 2,

    HighPriority: 3, LowPriority: 4, OffscreenPriority: 5, }; // No work is pending. // For controlled text inputs. Synchronous side-effects. // Needs to complete before the next frame. // Interaction that needs to complete pretty soon to feel responsive. // Data fetching, or result from updating stores. // Won't be visible but do the work in case it becomes visible.
  5. requestIdleCallback --- working asynchronously using requestIdleCallback ------------------------------------------------- | ------- Fiber

    --------------- ------- Fiber --------------- ------ Fiber --------------- | | | beginWork -> completeWork | -> | beginWork -> completeWork | -> | beginWork -> completeWork | ... | ↓↓↓ ----------------------------------------------------------------------- | commitAllWork(flush side effects computed in the above to the host) | -----------------------------------------------------------------------