mirror of
https://github.com/zebrajr/react.git
synced 2025-12-06 12:20:20 +01:00
Remove feature flag enableRenderableContext (#33505)
The flag is fully rolled out.
This commit is contained in:
parent
56408a5b12
commit
6c86e56a0f
|
|
@ -18,13 +18,10 @@ import type {
|
|||
import type {LazyComponent} from 'react/src/ReactLazy';
|
||||
import type {TemporaryReferenceSet} from './ReactFlightTemporaryReferences';
|
||||
|
||||
import {enableRenderableContext} from 'shared/ReactFeatureFlags';
|
||||
|
||||
import {
|
||||
REACT_ELEMENT_TYPE,
|
||||
REACT_LAZY_TYPE,
|
||||
REACT_CONTEXT_TYPE,
|
||||
REACT_PROVIDER_TYPE,
|
||||
getIteratorFn,
|
||||
ASYNC_ITERATOR,
|
||||
} from 'shared/ReactSymbols';
|
||||
|
|
@ -699,10 +696,7 @@ export function processReply(
|
|||
return serializeTemporaryReferenceMarker();
|
||||
}
|
||||
if (__DEV__) {
|
||||
if (
|
||||
(value: any).$$typeof ===
|
||||
(enableRenderableContext ? REACT_CONTEXT_TYPE : REACT_PROVIDER_TYPE)
|
||||
) {
|
||||
if ((value: any).$$typeof === REACT_CONTEXT_TYPE) {
|
||||
console.error(
|
||||
'React Context Providers cannot be passed to Server Functions from the Client.%s',
|
||||
describeObjectForErrorMessage(parent, key),
|
||||
|
|
|
|||
16
packages/react-devtools-shared/src/utils.js
vendored
16
packages/react-devtools-shared/src/utils.js
vendored
|
|
@ -19,14 +19,12 @@ import {
|
|||
REACT_MEMO_TYPE,
|
||||
REACT_PORTAL_TYPE,
|
||||
REACT_PROFILER_TYPE,
|
||||
REACT_PROVIDER_TYPE,
|
||||
REACT_STRICT_MODE_TYPE,
|
||||
REACT_SUSPENSE_LIST_TYPE,
|
||||
REACT_SUSPENSE_TYPE,
|
||||
REACT_TRACING_MARKER_TYPE,
|
||||
REACT_VIEW_TRANSITION_TYPE,
|
||||
} from 'shared/ReactSymbols';
|
||||
import {enableRenderableContext} from 'shared/ReactFeatureFlags';
|
||||
import {
|
||||
TREE_OPERATION_ADD,
|
||||
TREE_OPERATION_REMOVE,
|
||||
|
|
@ -87,6 +85,9 @@ const encodedStringCache: LRUCache<string, Array<number>> = new LRU({
|
|||
max: 1000,
|
||||
});
|
||||
|
||||
// Previously, the type of `Context.Provider`.
|
||||
const LEGACY_REACT_PROVIDER_TYPE: symbol = Symbol.for('react.provider');
|
||||
|
||||
export function alphaSortKeys(
|
||||
a: string | number | symbol,
|
||||
b: string | number | symbol,
|
||||
|
|
@ -712,14 +713,7 @@ function typeOfWithLegacyElementSymbol(object: any): mixed {
|
|||
case REACT_MEMO_TYPE:
|
||||
return $$typeofType;
|
||||
case REACT_CONSUMER_TYPE:
|
||||
if (enableRenderableContext) {
|
||||
return $$typeofType;
|
||||
}
|
||||
// Fall through
|
||||
case REACT_PROVIDER_TYPE:
|
||||
if (!enableRenderableContext) {
|
||||
return $$typeofType;
|
||||
}
|
||||
return $$typeofType;
|
||||
// Fall through
|
||||
default:
|
||||
return $$typeof;
|
||||
|
|
@ -740,7 +734,7 @@ export function getDisplayNameForReactElement(
|
|||
switch (elementType) {
|
||||
case REACT_CONSUMER_TYPE:
|
||||
return 'ContextConsumer';
|
||||
case REACT_PROVIDER_TYPE:
|
||||
case LEGACY_REACT_PROVIDER_TYPE:
|
||||
return 'ContextProvider';
|
||||
case REACT_CONTEXT_TYPE:
|
||||
return 'Context';
|
||||
|
|
|
|||
|
|
@ -295,12 +295,6 @@ describe('ReactDOMServerIntegration', () => {
|
|||
});
|
||||
|
||||
itRenders('should treat Context as Context.Provider', async render => {
|
||||
// The `itRenders` helpers don't work with the gate pragma, so we have to do
|
||||
// this instead.
|
||||
if (gate(flags => !flags.enableRenderableContext)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const Theme = React.createContext('dark');
|
||||
const Language = React.createContext('french');
|
||||
|
||||
|
|
|
|||
|
|
@ -932,7 +932,6 @@ describe('ReactDOMServer', () => {
|
|||
]);
|
||||
});
|
||||
|
||||
// @gate enableRenderableContext || !__DEV__
|
||||
it('should warn if an invalid contextType is defined', () => {
|
||||
const Context = React.createContext();
|
||||
class ComponentA extends React.Component {
|
||||
|
|
|
|||
34
packages/react-is/src/ReactIs.js
vendored
34
packages/react-is/src/ReactIs.js
vendored
|
|
@ -18,7 +18,6 @@ import {
|
|||
REACT_MEMO_TYPE,
|
||||
REACT_PORTAL_TYPE,
|
||||
REACT_PROFILER_TYPE,
|
||||
REACT_PROVIDER_TYPE,
|
||||
REACT_CONSUMER_TYPE,
|
||||
REACT_STRICT_MODE_TYPE,
|
||||
REACT_SUSPENSE_TYPE,
|
||||
|
|
@ -30,7 +29,6 @@ import {
|
|||
} from 'shared/ReactSymbols';
|
||||
|
||||
import {
|
||||
enableRenderableContext,
|
||||
enableScopeAPI,
|
||||
enableTransitionTracing,
|
||||
enableLegacyHidden,
|
||||
|
|
@ -64,14 +62,7 @@ export function typeOf(object: any): mixed {
|
|||
case REACT_MEMO_TYPE:
|
||||
return $$typeofType;
|
||||
case REACT_CONSUMER_TYPE:
|
||||
if (enableRenderableContext) {
|
||||
return $$typeofType;
|
||||
}
|
||||
// Fall through
|
||||
case REACT_PROVIDER_TYPE:
|
||||
if (!enableRenderableContext) {
|
||||
return $$typeofType;
|
||||
}
|
||||
return $$typeofType;
|
||||
// Fall through
|
||||
default:
|
||||
return $$typeof;
|
||||
|
|
@ -85,12 +76,8 @@ export function typeOf(object: any): mixed {
|
|||
return undefined;
|
||||
}
|
||||
|
||||
export const ContextConsumer: symbol = enableRenderableContext
|
||||
? REACT_CONSUMER_TYPE
|
||||
: REACT_CONTEXT_TYPE;
|
||||
export const ContextProvider: symbol = enableRenderableContext
|
||||
? REACT_CONTEXT_TYPE
|
||||
: REACT_PROVIDER_TYPE;
|
||||
export const ContextConsumer: symbol = REACT_CONSUMER_TYPE;
|
||||
export const ContextProvider: symbol = REACT_CONTEXT_TYPE;
|
||||
export const Element = REACT_ELEMENT_TYPE;
|
||||
export const ForwardRef = REACT_FORWARD_REF_TYPE;
|
||||
export const Fragment = REACT_FRAGMENT_TYPE;
|
||||
|
|
@ -127,8 +114,7 @@ export function isValidElementType(type: mixed): boolean {
|
|||
type.$$typeof === REACT_LAZY_TYPE ||
|
||||
type.$$typeof === REACT_MEMO_TYPE ||
|
||||
type.$$typeof === REACT_CONTEXT_TYPE ||
|
||||
(!enableRenderableContext && type.$$typeof === REACT_PROVIDER_TYPE) ||
|
||||
(enableRenderableContext && type.$$typeof === REACT_CONSUMER_TYPE) ||
|
||||
type.$$typeof === REACT_CONSUMER_TYPE ||
|
||||
type.$$typeof === REACT_FORWARD_REF_TYPE ||
|
||||
// This needs to include all possible module reference object
|
||||
// types supported by any Flight configuration anywhere since
|
||||
|
|
@ -145,18 +131,10 @@ export function isValidElementType(type: mixed): boolean {
|
|||
}
|
||||
|
||||
export function isContextConsumer(object: any): boolean {
|
||||
if (enableRenderableContext) {
|
||||
return typeOf(object) === REACT_CONSUMER_TYPE;
|
||||
} else {
|
||||
return typeOf(object) === REACT_CONTEXT_TYPE;
|
||||
}
|
||||
return typeOf(object) === REACT_CONSUMER_TYPE;
|
||||
}
|
||||
export function isContextProvider(object: any): boolean {
|
||||
if (enableRenderableContext) {
|
||||
return typeOf(object) === REACT_CONTEXT_TYPE;
|
||||
} else {
|
||||
return typeOf(object) === REACT_PROVIDER_TYPE;
|
||||
}
|
||||
return typeOf(object) === REACT_CONTEXT_TYPE;
|
||||
}
|
||||
export function isElement(object: any): boolean {
|
||||
return (
|
||||
|
|
|
|||
23
packages/react-reconciler/src/ReactFiber.js
vendored
23
packages/react-reconciler/src/ReactFiber.js
vendored
|
|
@ -41,7 +41,6 @@ import {
|
|||
enableLegacyHidden,
|
||||
enableTransitionTracing,
|
||||
enableDO_NOT_USE_disableStrictPassiveEffect,
|
||||
enableRenderableContext,
|
||||
disableLegacyMode,
|
||||
enableObjectFiber,
|
||||
enableViewTransition,
|
||||
|
|
@ -101,7 +100,6 @@ import {
|
|||
REACT_FRAGMENT_TYPE,
|
||||
REACT_STRICT_MODE_TYPE,
|
||||
REACT_PROFILER_TYPE,
|
||||
REACT_PROVIDER_TYPE,
|
||||
REACT_CONTEXT_TYPE,
|
||||
REACT_CONSUMER_TYPE,
|
||||
REACT_SUSPENSE_TYPE,
|
||||
|
|
@ -638,25 +636,12 @@ export function createFiberFromTypeAndProps(
|
|||
default: {
|
||||
if (typeof type === 'object' && type !== null) {
|
||||
switch (type.$$typeof) {
|
||||
case REACT_PROVIDER_TYPE:
|
||||
if (!enableRenderableContext) {
|
||||
fiberTag = ContextProvider;
|
||||
break getTag;
|
||||
}
|
||||
// Fall through
|
||||
case REACT_CONTEXT_TYPE:
|
||||
if (enableRenderableContext) {
|
||||
fiberTag = ContextProvider;
|
||||
break getTag;
|
||||
} else {
|
||||
fiberTag = ContextConsumer;
|
||||
break getTag;
|
||||
}
|
||||
fiberTag = ContextProvider;
|
||||
break getTag;
|
||||
case REACT_CONSUMER_TYPE:
|
||||
if (enableRenderableContext) {
|
||||
fiberTag = ContextConsumer;
|
||||
break getTag;
|
||||
}
|
||||
fiberTag = ContextConsumer;
|
||||
break getTag;
|
||||
// Fall through
|
||||
case REACT_FORWARD_REF_TYPE:
|
||||
fiberTag = ForwardRef;
|
||||
|
|
|
|||
|
|
@ -116,7 +116,6 @@ import {
|
|||
enableLegacyHidden,
|
||||
enableCPUSuspense,
|
||||
enablePostpone,
|
||||
enableRenderableContext,
|
||||
disableLegacyMode,
|
||||
disableDefaultPropsExceptForClasses,
|
||||
enableHydrationLaneScheduling,
|
||||
|
|
@ -3591,12 +3590,7 @@ function updateContextProvider(
|
|||
workInProgress: Fiber,
|
||||
renderLanes: Lanes,
|
||||
) {
|
||||
let context: ReactContext<any>;
|
||||
if (enableRenderableContext) {
|
||||
context = workInProgress.type;
|
||||
} else {
|
||||
context = workInProgress.type._context;
|
||||
}
|
||||
const context: ReactContext<any> = workInProgress.type;
|
||||
const newProps = workInProgress.pendingProps;
|
||||
const newValue = newProps.value;
|
||||
|
||||
|
|
@ -3623,18 +3617,8 @@ function updateContextConsumer(
|
|||
workInProgress: Fiber,
|
||||
renderLanes: Lanes,
|
||||
) {
|
||||
let context: ReactContext<any>;
|
||||
if (enableRenderableContext) {
|
||||
const consumerType: ReactConsumerType<any> = workInProgress.type;
|
||||
context = consumerType._context;
|
||||
} else {
|
||||
context = workInProgress.type;
|
||||
if (__DEV__) {
|
||||
if ((context: any)._context !== undefined) {
|
||||
context = (context: any)._context;
|
||||
}
|
||||
}
|
||||
}
|
||||
const consumerType: ReactConsumerType<any> = workInProgress.type;
|
||||
const context: ReactContext<any> = consumerType._context;
|
||||
const newProps = workInProgress.pendingProps;
|
||||
const render = newProps.children;
|
||||
|
||||
|
|
@ -3878,12 +3862,7 @@ function attemptEarlyBailoutIfNoScheduledUpdate(
|
|||
break;
|
||||
case ContextProvider: {
|
||||
const newValue = workInProgress.memoizedProps.value;
|
||||
let context: ReactContext<any>;
|
||||
if (enableRenderableContext) {
|
||||
context = workInProgress.type;
|
||||
} else {
|
||||
context = workInProgress.type._context;
|
||||
}
|
||||
const context: ReactContext<any> = workInProgress.type;
|
||||
pushProvider(workInProgress, context, newValue);
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,7 +38,6 @@ import {
|
|||
enablePersistedModeClonedFlag,
|
||||
enableProfilerTimer,
|
||||
enableTransitionTracing,
|
||||
enableRenderableContext,
|
||||
passChildrenWhenCloningPersistedNodes,
|
||||
disableLegacyMode,
|
||||
enableViewTransition,
|
||||
|
|
@ -1667,12 +1666,7 @@ function completeWork(
|
|||
return null;
|
||||
case ContextProvider:
|
||||
// Pop provider fiber
|
||||
let context: ReactContext<any>;
|
||||
if (enableRenderableContext) {
|
||||
context = workInProgress.type;
|
||||
} else {
|
||||
context = workInProgress.type._context;
|
||||
}
|
||||
const context: ReactContext<any> = workInProgress.type;
|
||||
popProvider(context, workInProgress);
|
||||
bubbleProperties(workInProgress);
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -29,7 +29,6 @@ import {
|
|||
} from './ReactFiberFlags';
|
||||
|
||||
import is from 'shared/objectIs';
|
||||
import {enableRenderableContext} from 'shared/ReactFeatureFlags';
|
||||
import {getHostTransitionProvider} from './ReactFiberHostContext';
|
||||
|
||||
const valueCursor: StackCursor<mixed> = createCursor(null);
|
||||
|
|
@ -389,13 +388,7 @@ function propagateParentContextChanges(
|
|||
|
||||
const oldProps = currentParent.memoizedProps;
|
||||
if (oldProps !== null) {
|
||||
let context: ReactContext<any>;
|
||||
if (enableRenderableContext) {
|
||||
context = parent.type;
|
||||
} else {
|
||||
context = parent.type._context;
|
||||
}
|
||||
|
||||
const context: ReactContext<any> = parent.type;
|
||||
const newProps = parent.pendingProps;
|
||||
const newValue = newProps.value;
|
||||
|
||||
|
|
|
|||
10
packages/react-reconciler/src/ReactFiberScope.js
vendored
10
packages/react-reconciler/src/ReactFiberScope.js
vendored
|
|
@ -22,10 +22,7 @@ import {
|
|||
import {isFiberSuspenseAndTimedOut} from './ReactFiberTreeReflection';
|
||||
|
||||
import {HostComponent, ScopeComponent, ContextProvider} from './ReactWorkTags';
|
||||
import {
|
||||
enableScopeAPI,
|
||||
enableRenderableContext,
|
||||
} from 'shared/ReactFeatureFlags';
|
||||
import {enableScopeAPI} from 'shared/ReactFeatureFlags';
|
||||
|
||||
function getSuspenseFallbackChild(fiber: Fiber): Fiber | null {
|
||||
return ((((fiber.child: any): Fiber).sibling: any): Fiber).child;
|
||||
|
|
@ -116,10 +113,7 @@ function collectNearestContextValues<T>(
|
|||
context: ReactContext<T>,
|
||||
childContextValues: Array<T>,
|
||||
): void {
|
||||
if (
|
||||
node.tag === ContextProvider &&
|
||||
(enableRenderableContext ? node.type : node.type._context) === context
|
||||
) {
|
||||
if (node.tag === ContextProvider && node.type === context) {
|
||||
const contextValue = node.memoizedProps.value;
|
||||
childContextValues.push(contextValue);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -36,7 +36,6 @@ import {NoMode, ProfileMode} from './ReactTypeOfMode';
|
|||
import {
|
||||
enableProfilerTimer,
|
||||
enableTransitionTracing,
|
||||
enableRenderableContext,
|
||||
} from 'shared/ReactFeatureFlags';
|
||||
|
||||
import {popHostContainer, popHostContext} from './ReactFiberHostContext';
|
||||
|
|
@ -189,12 +188,7 @@ function unwindWork(
|
|||
popHostContainer(workInProgress);
|
||||
return null;
|
||||
case ContextProvider:
|
||||
let context: ReactContext<any>;
|
||||
if (enableRenderableContext) {
|
||||
context = workInProgress.type;
|
||||
} else {
|
||||
context = workInProgress.type._context;
|
||||
}
|
||||
const context: ReactContext<any> = workInProgress.type;
|
||||
popProvider(context, workInProgress);
|
||||
return null;
|
||||
case OffscreenComponent:
|
||||
|
|
@ -286,12 +280,7 @@ function unwindInterruptedWork(
|
|||
popSuspenseListContext(interruptedWork);
|
||||
break;
|
||||
case ContextProvider:
|
||||
let context: ReactContext<any>;
|
||||
if (enableRenderableContext) {
|
||||
context = interruptedWork.type;
|
||||
} else {
|
||||
context = interruptedWork.type._context;
|
||||
}
|
||||
const context: ReactContext<any> = interruptedWork.type;
|
||||
popProvider(context, interruptedWork);
|
||||
break;
|
||||
case OffscreenComponent:
|
||||
|
|
|
|||
|
|
@ -941,15 +941,11 @@ describe('ReactLazy', () => {
|
|||
</Suspense>,
|
||||
);
|
||||
await waitForThrow(
|
||||
gate('enableRenderableContext')
|
||||
? 'Element type is invalid. Received a promise that resolves to: Context.Provider. ' +
|
||||
'Lazy element type must resolve to a class or function.'
|
||||
: 'Element type is invalid. Received a promise that resolves to: Context.Consumer. ' +
|
||||
'Lazy element type must resolve to a class or function.',
|
||||
'Element type is invalid. Received a promise that resolves to: Context.Provider. ' +
|
||||
'Lazy element type must resolve to a class or function.',
|
||||
);
|
||||
});
|
||||
|
||||
// @gate enableRenderableContext
|
||||
it('throws with a useful error when wrapping Context.Consumer with lazy()', async () => {
|
||||
const Context = React.createContext(null);
|
||||
const BadLazy = lazy(() => fakeImport(Context.Consumer));
|
||||
|
|
|
|||
|
|
@ -1358,7 +1358,6 @@ describe('ReactNewContext', () => {
|
|||
);
|
||||
});
|
||||
|
||||
// @gate enableRenderableContext || !__DEV__
|
||||
it('warns when passed a consumer', async () => {
|
||||
const Context = React.createContext(0);
|
||||
function Foo() {
|
||||
|
|
@ -1657,7 +1656,6 @@ Context fuzz tester error! Copy and paste the following line into the test suite
|
|||
});
|
||||
});
|
||||
|
||||
// @gate enableRenderableContext
|
||||
it('should treat Context as Context.Provider', async () => {
|
||||
const BarContext = React.createContext({value: 'bar-initial'});
|
||||
expect(BarContext.Provider).toBe(BarContext);
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ import type {Fiber} from './ReactInternalTypes';
|
|||
import {
|
||||
disableLegacyMode,
|
||||
enableLegacyHidden,
|
||||
enableRenderableContext,
|
||||
enableViewTransition,
|
||||
} from 'shared/ReactFeatureFlags';
|
||||
|
||||
|
|
@ -91,21 +90,11 @@ export default function getComponentNameFromFiber(fiber: Fiber): string | null {
|
|||
case CacheComponent:
|
||||
return 'Cache';
|
||||
case ContextConsumer:
|
||||
if (enableRenderableContext) {
|
||||
const consumer: ReactConsumerType<any> = (type: any);
|
||||
return getContextName(consumer._context) + '.Consumer';
|
||||
} else {
|
||||
const context: ReactContext<any> = (type: any);
|
||||
return getContextName(context) + '.Consumer';
|
||||
}
|
||||
const consumer: ReactConsumerType<any> = (type: any);
|
||||
return getContextName(consumer._context) + '.Consumer';
|
||||
case ContextProvider:
|
||||
if (enableRenderableContext) {
|
||||
const context: ReactContext<any> = (type: any);
|
||||
return getContextName(context) + '.Provider';
|
||||
} else {
|
||||
const provider = (type: any);
|
||||
return getContextName(provider._context) + '.Provider';
|
||||
}
|
||||
const context: ReactContext<any> = (type: any);
|
||||
return getContextName(context) + '.Provider';
|
||||
case DehydratedFragment:
|
||||
return 'DehydratedFragment';
|
||||
case ForwardRef:
|
||||
|
|
|
|||
38
packages/react-server/src/ReactFizzServer.js
vendored
38
packages/react-server/src/ReactFizzServer.js
vendored
|
|
@ -163,7 +163,6 @@ import {
|
|||
REACT_FRAGMENT_TYPE,
|
||||
REACT_FORWARD_REF_TYPE,
|
||||
REACT_MEMO_TYPE,
|
||||
REACT_PROVIDER_TYPE,
|
||||
REACT_CONTEXT_TYPE,
|
||||
REACT_CONSUMER_TYPE,
|
||||
REACT_SCOPE_TYPE,
|
||||
|
|
@ -178,7 +177,6 @@ import {
|
|||
enableScopeAPI,
|
||||
enablePostpone,
|
||||
enableHalt,
|
||||
enableRenderableContext,
|
||||
disableDefaultPropsExceptForClasses,
|
||||
enableAsyncIterableChildren,
|
||||
enableViewTransition,
|
||||
|
|
@ -2959,38 +2957,16 @@ function renderElement(
|
|||
renderMemo(request, task, keyPath, type, props, ref);
|
||||
return;
|
||||
}
|
||||
case REACT_PROVIDER_TYPE: {
|
||||
if (!enableRenderableContext) {
|
||||
const context: ReactContext<any> = (type: any)._context;
|
||||
renderContextProvider(request, task, keyPath, context, props);
|
||||
return;
|
||||
}
|
||||
// Fall through
|
||||
}
|
||||
case REACT_CONTEXT_TYPE: {
|
||||
if (enableRenderableContext) {
|
||||
const context = type;
|
||||
renderContextProvider(request, task, keyPath, context, props);
|
||||
return;
|
||||
} else {
|
||||
let context: ReactContext<any> = (type: any);
|
||||
if (__DEV__) {
|
||||
if ((context: any)._context !== undefined) {
|
||||
context = (context: any)._context;
|
||||
}
|
||||
}
|
||||
renderContextConsumer(request, task, keyPath, context, props);
|
||||
return;
|
||||
}
|
||||
const context = type;
|
||||
renderContextProvider(request, task, keyPath, context, props);
|
||||
return;
|
||||
}
|
||||
case REACT_CONSUMER_TYPE: {
|
||||
if (enableRenderableContext) {
|
||||
const context: ReactContext<any> = (type: ReactConsumerType<any>)
|
||||
._context;
|
||||
renderContextConsumer(request, task, keyPath, context, props);
|
||||
return;
|
||||
}
|
||||
// Fall through
|
||||
const context: ReactContext<any> = (type: ReactConsumerType<any>)
|
||||
._context;
|
||||
renderContextConsumer(request, task, keyPath, context, props);
|
||||
return;
|
||||
}
|
||||
case REACT_LAZY_TYPE: {
|
||||
renderLazyComponent(request, task, keyPath, type, props, ref);
|
||||
|
|
|
|||
|
|
@ -7,14 +7,9 @@
|
|||
* @flow
|
||||
*/
|
||||
|
||||
import {
|
||||
REACT_PROVIDER_TYPE,
|
||||
REACT_CONSUMER_TYPE,
|
||||
REACT_CONTEXT_TYPE,
|
||||
} from 'shared/ReactSymbols';
|
||||
import {REACT_CONSUMER_TYPE, REACT_CONTEXT_TYPE} from 'shared/ReactSymbols';
|
||||
|
||||
import type {ReactContext} from 'shared/ReactTypes';
|
||||
import {enableRenderableContext} from 'shared/ReactFeatureFlags';
|
||||
|
||||
export function createContext<T>(defaultValue: T): ReactContext<T> {
|
||||
// TODO: Second argument used to be an optional `calculateChangedBits`
|
||||
|
|
@ -37,73 +32,11 @@ export function createContext<T>(defaultValue: T): ReactContext<T> {
|
|||
Consumer: (null: any),
|
||||
};
|
||||
|
||||
if (enableRenderableContext) {
|
||||
context.Provider = context;
|
||||
context.Consumer = {
|
||||
$$typeof: REACT_CONSUMER_TYPE,
|
||||
_context: context,
|
||||
};
|
||||
} else {
|
||||
(context: any).Provider = {
|
||||
$$typeof: REACT_PROVIDER_TYPE,
|
||||
_context: context,
|
||||
};
|
||||
if (__DEV__) {
|
||||
const Consumer: any = {
|
||||
$$typeof: REACT_CONTEXT_TYPE,
|
||||
_context: context,
|
||||
};
|
||||
Object.defineProperties(Consumer, {
|
||||
Provider: {
|
||||
get() {
|
||||
return context.Provider;
|
||||
},
|
||||
set(_Provider: any) {
|
||||
context.Provider = _Provider;
|
||||
},
|
||||
},
|
||||
_currentValue: {
|
||||
get() {
|
||||
return context._currentValue;
|
||||
},
|
||||
set(_currentValue: T) {
|
||||
context._currentValue = _currentValue;
|
||||
},
|
||||
},
|
||||
_currentValue2: {
|
||||
get() {
|
||||
return context._currentValue2;
|
||||
},
|
||||
set(_currentValue2: T) {
|
||||
context._currentValue2 = _currentValue2;
|
||||
},
|
||||
},
|
||||
_threadCount: {
|
||||
get() {
|
||||
return context._threadCount;
|
||||
},
|
||||
set(_threadCount: number) {
|
||||
context._threadCount = _threadCount;
|
||||
},
|
||||
},
|
||||
Consumer: {
|
||||
get() {
|
||||
return context.Consumer;
|
||||
},
|
||||
},
|
||||
displayName: {
|
||||
get() {
|
||||
return context.displayName;
|
||||
},
|
||||
set(displayName: void | string) {},
|
||||
},
|
||||
});
|
||||
(context: any).Consumer = Consumer;
|
||||
} else {
|
||||
(context: any).Consumer = context;
|
||||
}
|
||||
}
|
||||
|
||||
context.Provider = context;
|
||||
context.Consumer = {
|
||||
$$typeof: REACT_CONSUMER_TYPE,
|
||||
_context: context,
|
||||
};
|
||||
if (__DEV__) {
|
||||
context._currentRenderer = null;
|
||||
context._currentRenderer2 = null;
|
||||
|
|
|
|||
|
|
@ -490,7 +490,6 @@ describe('ReactContextValidator', () => {
|
|||
]);
|
||||
});
|
||||
|
||||
// @gate enableRenderableContext || !__DEV__
|
||||
it('should warn if an invalid contextType is defined', async () => {
|
||||
const Context = React.createContext();
|
||||
class ComponentA extends React.Component {
|
||||
|
|
|
|||
|
|
@ -204,9 +204,6 @@ export const enableReactTestRendererWarning = true;
|
|||
// before removing them in stable in the next Major
|
||||
export const disableLegacyMode = true;
|
||||
|
||||
// Make <Context> equivalent to <Context.Provider> instead of <Context.Consumer>
|
||||
export const enableRenderableContext = true;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Chopping Block
|
||||
//
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ export const REACT_PORTAL_TYPE: symbol = Symbol.for('react.portal');
|
|||
export const REACT_FRAGMENT_TYPE: symbol = Symbol.for('react.fragment');
|
||||
export const REACT_STRICT_MODE_TYPE: symbol = Symbol.for('react.strict_mode');
|
||||
export const REACT_PROFILER_TYPE: symbol = Symbol.for('react.profiler');
|
||||
export const REACT_PROVIDER_TYPE: symbol = Symbol.for('react.provider'); // TODO: Delete with enableRenderableContext
|
||||
export const REACT_CONSUMER_TYPE: symbol = Symbol.for('react.consumer');
|
||||
export const REACT_CONTEXT_TYPE: symbol = Symbol.for('react.context');
|
||||
export const REACT_FORWARD_REF_TYPE: symbol = Symbol.for('react.forward_ref');
|
||||
|
|
|
|||
|
|
@ -58,7 +58,6 @@ export const enableProfilerCommitHooks = __PROFILE__;
|
|||
export const enableProfilerNestedUpdatePhase = __PROFILE__;
|
||||
export const enableProfilerTimer = __PROFILE__;
|
||||
export const enableReactTestRendererWarning = false;
|
||||
export const enableRenderableContext = true;
|
||||
export const enableRetryLaneExpiration = false;
|
||||
export const enableSchedulingProfiler = __PROFILE__;
|
||||
export const enableComponentPerformanceTrack = false;
|
||||
|
|
|
|||
|
|
@ -43,7 +43,6 @@ export const enableObjectFiber = false;
|
|||
export const enablePersistedModeClonedFlag = false;
|
||||
export const enablePostpone = false;
|
||||
export const enableReactTestRendererWarning = false;
|
||||
export const enableRenderableContext = true;
|
||||
export const enableRetryLaneExpiration = false;
|
||||
export const enableSchedulingProfiler = __PROFILE__;
|
||||
export const enableComponentPerformanceTrack = false;
|
||||
|
|
|
|||
|
|
@ -89,7 +89,6 @@ export const enableFragmentRefs = false;
|
|||
export const disableLegacyMode = true;
|
||||
export const disableLegacyContext = true;
|
||||
export const disableLegacyContextForFunctionComponents = true;
|
||||
export const enableRenderableContext = true;
|
||||
export const enableReactTestRendererWarning = true;
|
||||
export const disableDefaultPropsExceptForClasses = true;
|
||||
|
||||
|
|
|
|||
|
|
@ -41,7 +41,6 @@ export const enableProfilerCommitHooks = __PROFILE__;
|
|||
export const enableProfilerNestedUpdatePhase = __PROFILE__;
|
||||
export const enableProfilerTimer = __PROFILE__;
|
||||
export const enableReactTestRendererWarning = false;
|
||||
export const enableRenderableContext = true;
|
||||
export const enableRetryLaneExpiration = false;
|
||||
export const enableSchedulingProfiler = __PROFILE__;
|
||||
export const enableComponentPerformanceTrack = false;
|
||||
|
|
|
|||
|
|
@ -38,7 +38,6 @@ export const enableUseEffectEventHook = false;
|
|||
export const favorSafetyOverHydrationPerf = true;
|
||||
export const enableLegacyFBSupport = false;
|
||||
export const enableMoveBefore = false;
|
||||
export const enableRenderableContext = false;
|
||||
export const enableHiddenSubtreeInsertionEffectCleanup = true;
|
||||
|
||||
export const enableRetryLaneExpiration = false;
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ export const enableDO_NOT_USE_disableStrictPassiveEffect = __VARIANT__;
|
|||
export const enableHiddenSubtreeInsertionEffectCleanup = __VARIANT__;
|
||||
export const enableNoCloningMemoCache = __VARIANT__;
|
||||
export const enableObjectFiber = __VARIANT__;
|
||||
export const enableRenderableContext = __VARIANT__;
|
||||
export const enableRetryLaneExpiration = __VARIANT__;
|
||||
export const enableTransitionTracing = __VARIANT__;
|
||||
export const favorSafetyOverHydrationPerf = __VARIANT__;
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ export const {
|
|||
enableInfiniteRenderLoopDetection,
|
||||
enableNoCloningMemoCache,
|
||||
enableObjectFiber,
|
||||
enableRenderableContext,
|
||||
enableRetryLaneExpiration,
|
||||
enableTransitionTracing,
|
||||
enableTrustedTypesIntegration,
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ import {
|
|||
REACT_PORTAL_TYPE,
|
||||
REACT_MEMO_TYPE,
|
||||
REACT_PROFILER_TYPE,
|
||||
REACT_PROVIDER_TYPE,
|
||||
REACT_STRICT_MODE_TYPE,
|
||||
REACT_SUSPENSE_TYPE,
|
||||
REACT_SUSPENSE_LIST_TYPE,
|
||||
|
|
@ -30,7 +29,6 @@ import {
|
|||
|
||||
import {
|
||||
enableTransitionTracing,
|
||||
enableRenderableContext,
|
||||
enableViewTransition,
|
||||
} from './ReactFeatureFlags';
|
||||
|
||||
|
|
@ -106,27 +104,12 @@ export default function getComponentNameFromType(type: mixed): string | null {
|
|||
switch (type.$$typeof) {
|
||||
case REACT_PORTAL_TYPE:
|
||||
return 'Portal';
|
||||
case REACT_PROVIDER_TYPE:
|
||||
if (enableRenderableContext) {
|
||||
return null;
|
||||
} else {
|
||||
const provider = (type: any);
|
||||
return getContextName(provider._context) + '.Provider';
|
||||
}
|
||||
case REACT_CONTEXT_TYPE:
|
||||
const context: ReactContext<any> = (type: any);
|
||||
if (enableRenderableContext) {
|
||||
return getContextName(context) + '.Provider';
|
||||
} else {
|
||||
return getContextName(context) + '.Consumer';
|
||||
}
|
||||
return getContextName(context) + '.Provider';
|
||||
case REACT_CONSUMER_TYPE:
|
||||
if (enableRenderableContext) {
|
||||
const consumer: ReactConsumerType<any> = (type: any);
|
||||
return getContextName(consumer._context) + '.Consumer';
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
const consumer: ReactConsumerType<any> = (type: any);
|
||||
return getContextName(consumer._context) + '.Consumer';
|
||||
case REACT_FORWARD_REF_TYPE:
|
||||
return getWrappedName(type, type.render, 'ForwardRef');
|
||||
case REACT_MEMO_TYPE:
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user