mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
9209c30ff9
* The exported '<React.StrictMode>' tag remains the same and opts legacy subtrees into strict mode level one ('mode == StrictModeL1'). This mode enables DEV-only double rendering, double component lifecycles, string ref warnings, legacy context warnings, etc. The primary purpose of this mode is to help detected render phase side effects. No new behavior. Roots created with experimental 'createRoot' and 'createBlockingRoot' APIs will also (for now) continue to default to strict mode level 1.
In a subsequent commit I will add support for a 'level' attribute on the '<React.StrictMode>' tag (as well as a new option supported by ). This will be the way to opt into strict mode level 2 ('mode == StrictModeL2'). This mode will enable DEV-only double invoking of effects on initial mount. This will simulate future Offscreen API semantics for trees being mounted, then hidden, and then shown again. The primary purpose of this mode is to enable applications to prepare for compatibility with the new Offscreen API (more information to follow shortly).
For now, this commit changes no public facing behavior. The only mechanism for opting into strict mode level 2 is the pre-existing 'enableDoubleInvokingEffects' feature flag (only enabled within Facebook for now).
* Renamed strict mode constants
StrictModeL1 -> StrictLegacyMode and StrictModeL2 -> StrictEffectsMode
* Renamed tests
* Split strict effects mode into two flags
One flag ('enableStrictEffects') enables strict mode level 2. It is similar to 'debugRenderPhaseSideEffectsForStrictMode' which enables srtict mode level 1.
The second flag ('createRootStrictEffectsByDefault') controls the default strict mode level for 'createRoot' trees. For now, all 'createRoot' trees remain level 1 by default. We will experiment with level 2 within Facebook.
This is a prerequisite for adding a configurable option to 'createRoot' that enables choosing a different StrictMode level than the default.
* Add StrictMode 'unstable_level' prop and createRoot 'unstable_strictModeLevel' option
New StrictMode 'unstable_level' prop allows specifying which level of strict mode to use. If no level attribute is specified, StrictLegacyMode will be used to maintain backwards compatibility. Otherwise the following is true:
* Level 0 does nothing
* Level 1 selects StrictLegacyMode
* Level 2 selects StrictEffectsMode (which includes StrictLegacyMode)
Levels can be increased with nesting (0 -> 1 -> 2) but not decreased.
This commit also adds a new 'unstable_strictModeLevel' option to the createRoot and createBatchedRoot APIs. This option can be used to override default behavior to increase or decrease the StrictMode level of the root.
A subsequent commit will add additional DEV warnings:
* If a nested StrictMode tag attempts to explicitly decrease the level
* If a level attribute changes in an update
68 lines
2.9 KiB
JavaScript
68 lines
2.9 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 typeof * as FeatureFlagsType from 'shared/ReactFeatureFlags';
|
|
import typeof * as ExportsType from './ReactFeatureFlags.testing.www';
|
|
|
|
export const debugRenderPhaseSideEffectsForStrictMode = false;
|
|
export const enableDebugTracing = false;
|
|
export const enableSchedulingProfiler = false;
|
|
export const warnAboutDeprecatedLifecycles = true;
|
|
export const replayFailedUnitOfWorkWithInvokeGuardedCallback = false;
|
|
export const enableProfilerTimer = false;
|
|
export const enableProfilerCommitHooks = false;
|
|
export const enableProfilerNestedUpdatePhase = false;
|
|
export const enableProfilerNestedUpdateScheduledHook = false;
|
|
export const enableSchedulerTracing = false;
|
|
export const enableSuspenseServerRenderer = true;
|
|
export const enableSelectiveHydration = true;
|
|
export const enableLazyElements = false;
|
|
export const enableCache = false;
|
|
export const disableJavaScriptURLs = true;
|
|
export const disableInputAttributeSyncing = false;
|
|
export const enableSchedulerDebugging = false;
|
|
export const enableScopeAPI = true;
|
|
export const enableCreateEventHandleAPI = true;
|
|
export const warnAboutUnmockedScheduler = true;
|
|
export const enableSuspenseCallback = true;
|
|
export const warnAboutDefaultPropsOnFunctionComponents = false;
|
|
export const warnAboutStringRefs = false;
|
|
export const disableLegacyContext = __EXPERIMENTAL__;
|
|
export const disableSchedulerTimeoutBasedOnReactExpirationTime = false;
|
|
export const enableTrustedTypesIntegration = false;
|
|
export const disableTextareaChildren = __EXPERIMENTAL__;
|
|
export const disableModulePatternComponents = true;
|
|
export const warnUnstableRenderSubtreeIntoContainer = false;
|
|
export const warnAboutSpreadingKeyToJSX = false;
|
|
export const enableComponentStackLocations = true;
|
|
export const enableLegacyFBSupport = !__EXPERIMENTAL__;
|
|
export const enableFilterEmptyStringAttributesDOM = false;
|
|
export const disableNativeComponentFrames = false;
|
|
export const skipUnmountedBoundaries = true;
|
|
|
|
export const enableNewReconciler = false;
|
|
export const deferRenderPhaseUpdateToNextBatch = true;
|
|
export const decoupleUpdatePriorityFromScheduler = false;
|
|
export const enableDiscreteEventFlushingChange = true;
|
|
|
|
export const enableStrictEffects = false;
|
|
export const createRootStrictEffectsByDefault = false;
|
|
export const enableUseRefAccessWarning = false;
|
|
|
|
export const enableRecursiveCommitTraversal = false;
|
|
export const disableSchedulerTimeoutInWorkLoop = false;
|
|
export const enableDiscreteEventMicroTasks = false;
|
|
export const enableNativeEventPriorityInference = false;
|
|
|
|
// Flow magic to verify the exports of this file match the original version.
|
|
// eslint-disable-next-line no-unused-vars
|
|
type Check<_X, Y: _X, X: Y = _X> = null;
|
|
// eslint-disable-next-line no-unused-expressions
|
|
(null: Check<ExportsType, FeatureFlagsType>);
|