Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@

<PROJECT_ROOT>/fixtures/.*
<PROJECT_ROOT>/build/.*
<PROJECT_ROOT>/scripts/.*
<PROJECT_ROOT>/scripts/bench/.*

# These shims are copied into external projects:
<PROJECT_ROOT>/scripts/rollup/shims/facebook-www/.*
<PROJECT_ROOT>/scripts/rollup/shims/react-native/.*

# Note: intentionally *don't* ignore /scripts/rollup/shims/rollup/
# because it is part of the build and isn't external.

<PROJECT_ROOT>/.*/node_modules/y18n/.*
<PROJECT_ROOT>/node_modules/chrome-devtools-frontend/.*
<PROJECT_ROOT>/node_modules/devtools-timeline-model/.*
Expand Down
28 changes: 16 additions & 12 deletions packages/react-cs-renderer/src/ReactNativeCSFeatureFlags.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,21 @@
* @flow
*/

import type {FeatureFlags} from 'shared/ReactFeatureFlags';
import typeof * as FeatureFlagsType from 'shared/ReactFeatureFlags';
import typeof * as CSFeatureFlagsType from './ReactNativeCSFeatureFlags';

var ReactNativeCSFeatureFlags: FeatureFlags = {
enableAsyncSubtreeAPI: true,
enableAsyncSchedulingByDefaultInReactDOM: false,
enableReactFragment: false,
enableCreateRoot: false,
// React Native CS uses persistent reconciler.
enableMutatingReconciler: false,
enableNoopReconciler: false,
enablePersistentReconciler: true,
};
export const enableAsyncSubtreeAPI = true;
export const enableAsyncSchedulingByDefaultInReactDOM = false;
export const enableReactFragment = false;
export const enableCreateRoot = false;

export default ReactNativeCSFeatureFlags;
// React Native CS uses persistent reconciler.
export const enableMutatingReconciler = false;
export const enableNoopReconciler = false;
export const enablePersistentReconciler = true;

// 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<CSFeatureFlagsType, FeatureFlagsType>);
9 changes: 6 additions & 3 deletions packages/react-dom/src/client/ReactDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ import * as EventPluginHub from 'events/EventPluginHub';
import * as EventPluginRegistry from 'events/EventPluginRegistry';
import * as EventPropagators from 'events/EventPropagators';
import * as ReactInstanceMap from 'shared/ReactInstanceMap';
import ReactFeatureFlags from 'shared/ReactFeatureFlags';
import {
enableAsyncSchedulingByDefaultInReactDOM,
enableCreateRoot,
} from 'shared/ReactFeatureFlags';
import ReactVersion from 'shared/ReactVersion';
import * as ReactDOMFrameScheduling from 'shared/ReactDOMFrameScheduling';
import {ReactCurrentOwner} from 'shared/ReactGlobalSharedState';
Expand Down Expand Up @@ -633,7 +636,7 @@ var DOMRenderer = ReactFiberReconciler({

scheduleDeferredCallback: ReactDOMFrameScheduling.rIC,

useSyncScheduling: !ReactFeatureFlags.enableAsyncSchedulingByDefaultInReactDOM,
useSyncScheduling: !enableAsyncSchedulingByDefaultInReactDOM,
});

ReactGenericBatching.injection.injectFiberBatchedUpdates(
Expand Down Expand Up @@ -945,7 +948,7 @@ var ReactDOM: Object = {
},
};

if (ReactFeatureFlags.enableCreateRoot) {
if (enableCreateRoot) {
ReactDOM.createRoot = function createRoot(
container: DOMContainer,
options?: RootOptions,
Expand Down
4 changes: 2 additions & 2 deletions packages/react-noop-renderer/src/ReactNoop.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import type {UpdateQueue} from 'react-reconciler/src/ReactFiberUpdateQueue';
import ReactFiberInstrumentation
from 'react-reconciler/src/ReactFiberInstrumentation';
import ReactFiberReconciler from 'react-reconciler';
import ReactFeatureFlags from 'shared/ReactFeatureFlags';
import {enablePersistentReconciler} from 'shared/ReactFeatureFlags';
import * as ReactInstanceMap from 'shared/ReactInstanceMap';
import emptyObject from 'fbjs/lib/emptyObject';
import expect from 'expect';
Expand Down Expand Up @@ -213,7 +213,7 @@ var NoopRenderer = ReactFiberReconciler({
},
});

var PersistentNoopRenderer = ReactFeatureFlags.enablePersistentReconciler
var PersistentNoopRenderer = enablePersistentReconciler
? ReactFiberReconciler({
...SharedHostConfig,
persistence: {
Expand Down
4 changes: 2 additions & 2 deletions packages/react-reconciler/src/ReactChildFiber.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type {
ExpirationTime,
} from 'react-reconciler/src/ReactFiberExpirationTime';

import ReactFeatureFlags from 'shared/ReactFeatureFlags';
import {enableReactFragment} from 'shared/ReactFeatureFlags';
import {NoEffect, Placement, Deletion} from 'shared/ReactTypeOfSideEffect';
import {
FunctionalComponent,
Expand Down Expand Up @@ -1426,7 +1426,7 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
// This leads to an ambiguity between <>{[...]}</> and <>...</>.
// We treat the ambiguous cases above the same.
if (
ReactFeatureFlags.enableReactFragment &&
enableReactFragment &&
typeof newChild === 'object' &&
newChild !== null &&
newChild.type === REACT_FRAGMENT_TYPE &&
Expand Down
4 changes: 2 additions & 2 deletions packages/react-reconciler/src/ReactFiberClassComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type {Fiber} from './ReactFiber';
import type {ExpirationTime} from './ReactFiberExpirationTime';

import {Update} from 'shared/ReactTypeOfSideEffect';
import ReactFeatureFlags from 'shared/ReactFeatureFlags';
import {enableAsyncSubtreeAPI} from 'shared/ReactFeatureFlags';
import {isMounted} from 'shared/ReactFiberTreeReflection';
import * as ReactInstanceMap from 'shared/ReactInstanceMap';
import emptyObject from 'fbjs/lib/emptyObject';
Expand Down Expand Up @@ -450,7 +450,7 @@ export default function(
instance.context = getMaskedContext(workInProgress, unmaskedContext);

if (
ReactFeatureFlags.enableAsyncSubtreeAPI &&
enableAsyncSubtreeAPI &&
workInProgress.type != null &&
workInProgress.type.prototype != null &&
workInProgress.type.prototype.unstable_isAsyncReactComponent === true
Expand Down
20 changes: 9 additions & 11 deletions packages/react-reconciler/src/ReactFiberCommitWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
import type {HostConfig} from 'react-reconciler';
import type {Fiber} from './ReactFiber';

import ReactFeatureFlags from 'shared/ReactFeatureFlags';
import {
enableMutatingReconciler,
enableNoopReconciler,
enablePersistentReconciler,
} from 'shared/ReactFeatureFlags';
import {
ClassComponent,
HostRoot,
Expand Down Expand Up @@ -218,12 +222,9 @@ export default function<T, P, I, TI, PI, C, CC, CX, PL>(
// TODO: this is recursive.
// We are also not using this parent because
// the portal will get pushed immediately.
if (ReactFeatureFlags.enableMutatingReconciler && mutation) {
if (enableMutatingReconciler && mutation) {
unmountHostComponents(current);
} else if (
ReactFeatureFlags.enablePersistentReconciler &&
persistence
) {
} else if (enablePersistentReconciler && persistence) {
emptyPortalContainer(current);
}
return;
Expand Down Expand Up @@ -324,10 +325,7 @@ export default function<T, P, I, TI, PI, C, CC, CX, PL>(
// Noop
};
}
if (
ReactFeatureFlags.enablePersistentReconciler ||
ReactFeatureFlags.enableNoopReconciler
) {
if (enablePersistentReconciler || enableNoopReconciler) {
return {
commitResetTextContent(finishedWork: Fiber) {},
commitPlacement(finishedWork: Fiber) {},
Expand Down Expand Up @@ -660,7 +658,7 @@ export default function<T, P, I, TI, PI, C, CC, CX, PL>(
resetTextContent(current.stateNode);
}

if (ReactFeatureFlags.enableMutatingReconciler) {
if (enableMutatingReconciler) {
return {
commitResetTextContent,
commitPlacement,
Expand Down
12 changes: 8 additions & 4 deletions packages/react-reconciler/src/ReactFiberCompleteWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ import type {HostContext} from './ReactFiberHostContext';
import type {HydrationContext} from './ReactFiberHydrationContext';
import type {FiberRoot} from './ReactFiberRoot';

import ReactFeatureFlags from 'shared/ReactFeatureFlags';
import {
enableMutatingReconciler,
enablePersistentReconciler,
enableNoopReconciler,
} from 'shared/ReactFeatureFlags';
import {
IndeterminateComponent,
FunctionalComponent,
Expand Down Expand Up @@ -180,7 +184,7 @@ export default function<T, P, I, TI, PI, C, CC, CX, PL>(
let updateHostComponent;
let updateHostText;
if (mutation) {
if (ReactFeatureFlags.enableMutatingReconciler) {
if (enableMutatingReconciler) {
// Mutation mode
updateHostContainer = function(workInProgress: Fiber) {
// Noop
Expand Down Expand Up @@ -217,7 +221,7 @@ export default function<T, P, I, TI, PI, C, CC, CX, PL>(
invariant(false, 'Mutating reconciler is disabled.');
}
} else if (persistence) {
if (ReactFeatureFlags.enablePersistentReconciler) {
if (enablePersistentReconciler) {
// Persistent host tree mode
const {
cloneInstance,
Expand Down Expand Up @@ -354,7 +358,7 @@ export default function<T, P, I, TI, PI, C, CC, CX, PL>(
invariant(false, 'Persistent reconciler is disabled.');
}
} else {
if (ReactFeatureFlags.enableNoopReconciler) {
if (enableNoopReconciler) {
// No host operations
updateHostContainer = function(workInProgress: Fiber) {
// Noop
Expand Down
4 changes: 2 additions & 2 deletions packages/react-reconciler/src/ReactFiberReconciler.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type {Fiber} from './ReactFiber';
import type {FiberRoot} from './ReactFiberRoot';
import type {ReactNodeList} from 'shared/ReactTypes';

import ReactFeatureFlags from 'shared/ReactFeatureFlags';
import {enableAsyncSubtreeAPI} from 'shared/ReactFeatureFlags';
import {
findCurrentHostFiber,
findCurrentHostFiberWithNoPortals,
Expand Down Expand Up @@ -303,7 +303,7 @@ export default function<T, P, I, TI, PI, C, CC, CX, PL>(
// treat updates to the root as async. This is a bit weird but lets us
// avoid a separate `renderAsync` API.
if (
ReactFeatureFlags.enableAsyncSubtreeAPI &&
enableAsyncSubtreeAPI &&
element != null &&
element.type != null &&
element.type.prototype != null &&
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/React.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import assign from 'object-assign';
import ReactVersion from 'shared/ReactVersion';
import ReactFeatureFlags from 'shared/ReactFeatureFlags';
import {enableReactFragment} from 'shared/ReactFeatureFlags';

import {Component, PureComponent, AsyncComponent} from './ReactBaseClasses';
import {forEach, map, count, toArray, only} from './ReactChildren';
Expand Down Expand Up @@ -58,7 +58,7 @@ var React = {
},
};

if (ReactFeatureFlags.enableReactFragment) {
if (enableReactFragment) {
React.Fragment = REACT_FRAGMENT_TYPE;
}

Expand Down
43 changes: 12 additions & 31 deletions packages/shared/ReactFeatureFlags.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,16 @@
* @flow
*/

export type FeatureFlags = {|
enableAsyncSubtreeAPI: boolean,
enableAsyncSchedulingByDefaultInReactDOM: boolean,
enableMutatingReconciler: boolean,
enableNoopReconciler: boolean,
enablePersistentReconciler: boolean,
enableReactFragment: boolean,
enableCreateRoot: boolean,
|};
export const enableAsyncSubtreeAPI = true;
export const enableAsyncSchedulingByDefaultInReactDOM = false;
// Exports React.Fragment
export const enableReactFragment = false;
// Exports ReactDOM.createRoot
export const enableCreateRoot = false;

var ReactFeatureFlags: FeatureFlags = {
enableAsyncSubtreeAPI: true,
enableAsyncSchedulingByDefaultInReactDOM: false,
// Mutating mode (React DOM, React ART, React Native):
enableMutatingReconciler: true,
// Experimental noop mode (currently unused):
enableNoopReconciler: false,
// Experimental persistent mode (CS):
enablePersistentReconciler: false,
// Exports React.Fragment
enableReactFragment: false,
// Exports ReactDOM.createRoot
enableCreateRoot: false,
};

if (__DEV__) {
if (Object.freeze) {
Object.freeze(ReactFeatureFlags);
}
}

export default ReactFeatureFlags;
// Mutating mode (React DOM, React ART, React Native):
export const enableMutatingReconciler = true;
// Experimental noop mode (currently unused):
export const enableNoopReconciler = false;
// Experimental persistent mode (CS):
export const enablePersistentReconciler = false;
5 changes: 5 additions & 0 deletions scripts/flow/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@
declare var __REACT_DEVTOOLS_GLOBAL_HOOK__: any; /*?{
inject: ?((stuff: Object) => void)
};*/

// ReactFeatureFlags rollup shim for www imports the www implementation.
declare module 'ReactFeatureFlags' {
declare module.exports: any;
}
9 changes: 3 additions & 6 deletions scripts/jest/setup.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
'use strict';

// We want to globally mock this but jest doesn't let us do that by default
// for a file that already exists. So we have to explicitly mock it.
jest.mock('shared/ReactFeatureFlags', () => {
const flags = require.requireActual('shared/ReactFeatureFlags').default;
return Object.assign({}, flags, {
disableNewFiberFeatures: true,
});
// We can alter flags based on environment here
// (e.g. for CI runs with different flags).
return require.requireActual('shared/ReactFeatureFlags');
});

// Error logging varies between Fiber and Stack;
Expand Down
Loading