dillon1000/react
Commit
Browse files Lazy components must use React.lazy (#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.Changed paths18 files
First-parent comparisonpackages/react-dom/src/__tests__/ReactServerRendering-test.js ModifiedM packages/react-dom/src/__tests__/ReactServerRenderingHydration-test.js ModifiedM packages/react-dom/src/server/ReactPartialRenderer.js ModifiedM packages/react-reconciler/src/ReactFiber.js ModifiedM packages/react-reconciler/src/ReactFiberBeginWork.js ModifiedM packages/react-reconciler/src/ReactFiberCompleteWork.js ModifiedM packages/react-reconciler/src/ReactFiberContext.js ModifiedM packages/react-reconciler/src/ReactFiberLazyComponent.js ModifiedM packages/react-reconciler/src/ReactFiberReconciler.js ModifiedM packages/react-reconciler/src/ReactFiberScheduler.js ModifiedA packages/react-reconciler/src/__tests__/ReactLazy-test.internal.js AddedM packages/react-reconciler/src/__tests__/ReactPure-test.internal.js ModifiedM packages/react-reconciler/src/__tests__/ReactSuspenseWithNoopRenderer-test.internal.js ModifiedM packages/react/src/ReactLazy.js ModifiedM packages/shared/ReactLazyComponent.js ModifiedM packages/shared/ReactSymbols.js ModifiedM packages/shared/getComponentName.js ModifiedM packages/shared/isValidElementType.js ModifiedPatch
Files changed
Rendering syntax-highlighted changes…