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
merged 1 commit into from Oct 19, 2018

Conversation

Projects
None yet
5 participants
@acdlite
Member

acdlite commented Oct 19, 2018

Note: This proposal has been discussed in reactjs/rfcs#64.

Removes support in master 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.

@sizebot

This comment has been minimized.

sizebot commented Oct 19, 2018

Details of bundled changes.

Comparing: 0648ca6...173ed32

scheduler

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
scheduler.development.js n/a n/a 0 B 19.17 KB 0 B 5.74 KB UMD_DEV
scheduler.production.min.js n/a n/a 0 B 3.16 KB 0 B 1.53 KB UMD_PROD

Generated by 🚫 dangerJS

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 acdlite merged commit d9659e4 into facebook:master Oct 19, 2018

1 check passed

ci/circleci Your tests passed on CircleCI!
Details

linjiajian999 pushed a commit to linjiajian999/react that referenced this pull request Oct 22, 2018

Andrew Clark linjiajian999
Lazy components must use React.lazy (facebook#13885)
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.

@gaearon gaearon referenced this pull request Oct 23, 2018

Merged

Add 16.6.0 changelog #13927

@wheelo

This comment has been minimized.

wheelo commented Oct 25, 2018

Awesome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment