2018-03-30 02:45:41 +08:00
|
|
|
/**
|
2018-09-08 06:11:23 +08:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2018-03-30 02:45:41 +08:00
|
|
|
*
|
|
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
|
|
|
|
*
|
|
|
|
|
* @flow
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import {
|
2018-09-27 00:13:02 +08:00
|
|
|
REACT_CONCURRENT_MODE_TYPE,
|
2018-03-30 02:45:41 +08:00
|
|
|
REACT_CONTEXT_TYPE,
|
|
|
|
|
REACT_FORWARD_REF_TYPE,
|
2018-05-11 06:25:32 +08:00
|
|
|
REACT_FRAGMENT_TYPE,
|
|
|
|
|
REACT_PROFILER_TYPE,
|
|
|
|
|
REACT_PROVIDER_TYPE,
|
|
|
|
|
REACT_STRICT_MODE_TYPE,
|
2018-10-11 00:02:04 +08:00
|
|
|
REACT_SUSPENSE_TYPE,
|
2019-06-20 10:34:28 +08:00
|
|
|
REACT_SUSPENSE_LIST_TYPE,
|
2018-10-21 00:46:23 +08:00
|
|
|
REACT_MEMO_TYPE,
|
2018-10-19 10:57:12 +08:00
|
|
|
REACT_LAZY_TYPE,
|
2019-07-20 05:20:28 +08:00
|
|
|
REACT_FUNDAMENTAL_TYPE,
|
2019-07-24 06:46:44 +08:00
|
|
|
REACT_RESPONDER_TYPE,
|
2019-08-29 19:06:51 +08:00
|
|
|
REACT_SCOPE_TYPE,
|
2018-03-30 02:45:41 +08:00
|
|
|
} from 'shared/ReactSymbols';
|
|
|
|
|
|
|
|
|
|
export default function isValidElementType(type: mixed) {
|
|
|
|
|
return (
|
|
|
|
|
typeof type === 'string' ||
|
|
|
|
|
typeof type === 'function' ||
|
|
|
|
|
// Note: its typeof might be other than 'symbol' or 'number' if it's a polyfill.
|
|
|
|
|
type === REACT_FRAGMENT_TYPE ||
|
2018-09-27 00:13:02 +08:00
|
|
|
type === REACT_CONCURRENT_MODE_TYPE ||
|
2018-05-11 06:25:32 +08:00
|
|
|
type === REACT_PROFILER_TYPE ||
|
2018-03-30 02:45:41 +08:00
|
|
|
type === REACT_STRICT_MODE_TYPE ||
|
2018-10-11 00:02:04 +08:00
|
|
|
type === REACT_SUSPENSE_TYPE ||
|
2019-06-20 10:34:28 +08:00
|
|
|
type === REACT_SUSPENSE_LIST_TYPE ||
|
2018-03-30 02:45:41 +08:00
|
|
|
(typeof type === 'object' &&
|
|
|
|
|
type !== null &&
|
2018-10-19 10:57:12 +08:00
|
|
|
(type.$$typeof === REACT_LAZY_TYPE ||
|
2018-10-21 00:46:23 +08:00
|
|
|
type.$$typeof === REACT_MEMO_TYPE ||
|
Accept promise as element type (#13397)
* Accept promise as element type
On the initial render, the element will suspend as if a promise were
thrown from inside the body of the unresolved component. Siblings should
continue rendering and if the parent is a Placeholder, the promise
should be captured by that Placeholder.
When the promise resolves, rendering resumes. If the resolved value
has a `default` property, it is assumed to be the default export of
an ES module, and we use that as the component type. If it does not have
a `default` property, we use the resolved value itself.
The resolved value is stored as an expando on the promise/thenable.
* Use special types of work for lazy components
Because reconciliation is a hot path, this adds ClassComponentLazy,
FunctionalComponentLazy, and ForwardRefLazy as special types of work.
The other types are not supported, but wouldn't be placed into a
separate module regardless.
* Resolve defaultProps for lazy types
* Remove some calls to isContextProvider
isContextProvider checks the fiber tag, but it's typically called after
we've already refined the type of work. We should get rid of it. I
removed some of them in the previous commit, and deleted a few more
in this one. I left a few behind because the remaining ones would
require additional refactoring that feels outside the scope of this PR.
* Remove getLazyComponentTypeIfResolved
* Return baseProps instead of null
The caller compares the result to baseProps to see if anything changed.
* Avoid redundant checks by inlining getFiberTagFromObjectType
* Move tag resolution to ReactFiber module
* Pass next props to update* functions
We should do this with all types of work in the future.
* Refine component type before pushing/popping context
Removes unnecessary checks.
* Replace all occurrences of _reactResult with helper
* Move shared thenable logic to `shared` package
* Check type of wrapper object before resolving to `default` export
* Return resolved tag instead of reassigning
2018-08-17 00:21:59 +08:00
|
|
|
type.$$typeof === REACT_PROVIDER_TYPE ||
|
2018-03-30 02:45:41 +08:00
|
|
|
type.$$typeof === REACT_CONTEXT_TYPE ||
|
2019-03-15 01:02:42 +08:00
|
|
|
type.$$typeof === REACT_FORWARD_REF_TYPE ||
|
2019-07-24 06:46:44 +08:00
|
|
|
type.$$typeof === REACT_FUNDAMENTAL_TYPE ||
|
2019-08-29 19:06:51 +08:00
|
|
|
type.$$typeof === REACT_RESPONDER_TYPE ||
|
|
|
|
|
type.$$typeof === REACT_SCOPE_TYPE))
|
2018-03-30 02:45:41 +08:00
|
|
|
);
|
|
|
|
|
}
|