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

Lazy components must use React.lazy #13885

Merged

Commits on Oct 19, 2018

  1. Lazy components must use React.lazy

    Removes support for using arbitrary promises as the type of a React
    element. Instead, promises must be wrapped in React.lazy. This gives us
    flexibility later if we need to change the protocol.
    
    The reason is that promises do not provide a way to call their
    constructor multiple times. For example:
    
    const promiseForA = new Promise(resolve => {
      fetchA(a => resolve(a));
    });
    
    Given a reference to `promiseForA`, there's no way to call `fetchA`
    again. Calling `then` on the promise doesn't run the constructor again;
    it only attaches another listener.
    
    In the future we will likely introduce an API like `React.eager` that
    is similar to `lazy` but eagerly calls the constructor. That gives us
    the ability to call the constructor multiple times. E.g. to increase
    the priority, or to retry if the first operation failed.
    acdlite committed Oct 19, 2018
    Configuration menu
    Copy the full SHA
    173ed32 View commit details
    Browse the repository at this point in the history