mirror of
https://github.com/facebook/react.git
synced 2026-02-25 05:03:03 +00:00
* Timeout component Adds Timeout component. If a promise is thrown from inside a Timeout component, React will suspend the in-progress render from committing. When the promise resolves, React will retry. If the render is suspended for longer than the maximum threshold, the Timeout switches to a placeholder state. The timeout threshold is defined as the minimum of: - The expiration time of the current render - The `ms` prop given to each Timeout component in the ancestor path of the thrown promise. * Add a test for nested fallbacks Co-authored-by: Andrew Clark <acdlite@fb.com> * Resume on promise rejection React should resume rendering regardless of whether it resolves or rejects. * Wrap Suspense code in feature flag * Children of a Timeout must be strict mode compatible Async is not required for Suspense, but strict mode is. * Simplify list of pending work Some of this was added with "soft expiration" in mind, but now with our revised model for how soft expiration will work, this isn't necessary. It would be nice to remove more of this, but I think the list itself is inherent because we need a way to track the start times, for <Timeout ms={ms} />. * Only use the Timeout update queue to store promises, not for state It already worked this way in practice. * Wrap more Suspense-only paths in the feature flag * Attach promise listener immediately on suspend Instead of waiting for commit phase. * Infer approximate start time using expiration time * Remove list of pending priority levels We can replicate almost all the functionality by tracking just five separate levels: the highest/lowest priority pending levels, the highest/lowest priority suspended levels, and the lowest pinged level. We lose a bit of granularity, in that if there are multiple levels of pending updates, only the first and last ones are known. But in practice this likely isn't a big deal. These heuristics are almost entirely isolated to a single module and can be adjusted later, without API changes, if necessary. Non-IO-bound work is not affected at all. * ReactFiberPendingWork -> ReactFiberPendingPriority * Renaming method names from "pending work" to "pending priority" * Get rid of SuspenseThenable module Idk why I thought this was neccessary * Nits based on Sebastian's feedback * More naming nits + comments * Add test for hiding a suspended tree to unblock * Revert change to expiration time rounding This means you have to account for the start time approximation heuristic when writing Suspense tests, but that's going to be true regardless. When updating the tests, I also made a fix related to offscreen priority. We should never timeout inside a hidden tree. * palceholder -> placeholder
38 lines
1.0 KiB
JavaScript
38 lines
1.0 KiB
JavaScript
/**
|
|
* Copyright (c) 2016-present, Facebook, Inc.
|
|
*
|
|
* 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_ASYNC_MODE_TYPE,
|
|
REACT_CONTEXT_TYPE,
|
|
REACT_FORWARD_REF_TYPE,
|
|
REACT_FRAGMENT_TYPE,
|
|
REACT_PROFILER_TYPE,
|
|
REACT_PROVIDER_TYPE,
|
|
REACT_STRICT_MODE_TYPE,
|
|
REACT_TIMEOUT_TYPE,
|
|
} 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 ||
|
|
type === REACT_ASYNC_MODE_TYPE ||
|
|
type === REACT_PROFILER_TYPE ||
|
|
type === REACT_STRICT_MODE_TYPE ||
|
|
type === REACT_TIMEOUT_TYPE ||
|
|
(typeof type === 'object' &&
|
|
type !== null &&
|
|
(type.$$typeof === REACT_PROVIDER_TYPE ||
|
|
type.$$typeof === REACT_CONTEXT_TYPE ||
|
|
type.$$typeof === REACT_FORWARD_REF_TYPE))
|
|
);
|
|
}
|