mirror of
https://github.com/facebook/react.git
synced 2026-02-24 12:43:00 +00:00
* [Offscreen] Mount/unmount layout effects Exposes the Offscreen component type and implements basic support for mount/unmounting layout effects when the visibility is toggled. Mostly it works the same way as hidden Suspense trees, which use the same internal fiber type. I had to add an extra bailout, though, that doesn't apply to the Suspense case but does apply to Offscreen components: a hidden Offscreen tree will eventually render at low priority, and when we it does, its `subtreeTag` will have effects scheduled on it. So I added a check to the layout phase where, if the subtree is hidden, we skip over the subtree entirely. An alternate design would be to clear the subtree flags in the render phase, but I prefer doing it this way since it's harder to mess up. We also need an API to enable the same thing for passive effects. This is not yet implemented. * Add test starting from hidden Co-authored-by: Rick Hanlon <rickhanlonii@gmail.com>
75 lines
2.1 KiB
JavaScript
75 lines
2.1 KiB
JavaScript
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @flow
|
|
*/
|
|
|
|
import {
|
|
REACT_CONTEXT_TYPE,
|
|
REACT_FORWARD_REF_TYPE,
|
|
REACT_FRAGMENT_TYPE,
|
|
REACT_PROFILER_TYPE,
|
|
REACT_PROVIDER_TYPE,
|
|
REACT_DEBUG_TRACING_MODE_TYPE,
|
|
REACT_STRICT_MODE_TYPE,
|
|
REACT_SUSPENSE_TYPE,
|
|
REACT_SUSPENSE_LIST_TYPE,
|
|
REACT_MEMO_TYPE,
|
|
REACT_LAZY_TYPE,
|
|
REACT_SCOPE_TYPE,
|
|
REACT_LEGACY_HIDDEN_TYPE,
|
|
REACT_OFFSCREEN_TYPE,
|
|
REACT_CACHE_TYPE,
|
|
} from 'shared/ReactSymbols';
|
|
import {enableScopeAPI, enableCache} from './ReactFeatureFlags';
|
|
|
|
let REACT_MODULE_REFERENCE: number | Symbol = 0;
|
|
if (typeof Symbol === 'function') {
|
|
REACT_MODULE_REFERENCE = Symbol.for('react.module.reference');
|
|
}
|
|
|
|
export default function isValidElementType(type: mixed) {
|
|
if (typeof type === 'string' || typeof type === 'function') {
|
|
return true;
|
|
}
|
|
|
|
// Note: typeof might be other than 'symbol' or 'number' (e.g. if it's a polyfill).
|
|
if (
|
|
type === REACT_FRAGMENT_TYPE ||
|
|
type === REACT_PROFILER_TYPE ||
|
|
type === REACT_DEBUG_TRACING_MODE_TYPE ||
|
|
type === REACT_STRICT_MODE_TYPE ||
|
|
type === REACT_SUSPENSE_TYPE ||
|
|
type === REACT_SUSPENSE_LIST_TYPE ||
|
|
type === REACT_LEGACY_HIDDEN_TYPE ||
|
|
type === REACT_OFFSCREEN_TYPE ||
|
|
(enableScopeAPI && type === REACT_SCOPE_TYPE) ||
|
|
(enableCache && type === REACT_CACHE_TYPE)
|
|
) {
|
|
return true;
|
|
}
|
|
|
|
if (typeof type === 'object' && type !== null) {
|
|
if (
|
|
type.$$typeof === REACT_LAZY_TYPE ||
|
|
type.$$typeof === REACT_MEMO_TYPE ||
|
|
type.$$typeof === REACT_PROVIDER_TYPE ||
|
|
type.$$typeof === REACT_CONTEXT_TYPE ||
|
|
type.$$typeof === REACT_FORWARD_REF_TYPE ||
|
|
// This needs to include all possible module reference object
|
|
// types supported by any Flight configuration anywhere since
|
|
// we don't know which Flight build this will end up being used
|
|
// with.
|
|
type.$$typeof === REACT_MODULE_REFERENCE ||
|
|
type.getModuleId !== undefined
|
|
) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|