Skip to content

Clean up the flag for renderable context #28437

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
7 changes: 1 addition & 6 deletions packages/react-client/src/ReactFlightReplyClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@ import type {
RejectedThenable,
ReactCustomFormAction,
} from 'shared/ReactTypes';
import {enableRenderableContext} from 'shared/ReactFeatureFlags';

import {
REACT_ELEMENT_TYPE,
REACT_LAZY_TYPE,
REACT_CONTEXT_TYPE,
REACT_PROVIDER_TYPE,
getIteratorFn,
} from 'shared/ReactSymbols';

Expand Down Expand Up @@ -304,10 +302,7 @@ export function processReply(
'React Lazy cannot be passed to Server Functions from the Client.%s',
describeObjectForErrorMessage(parent, key),
);
} else if (
(value: any).$$typeof ===
(enableRenderableContext ? REACT_CONTEXT_TYPE : REACT_PROVIDER_TYPE)
) {
} else 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),
Expand Down
6 changes: 1 addition & 5 deletions packages/react-debug-tools/src/ReactDebugHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -953,11 +953,7 @@ function setupContexts(contextMap: Map<ReactContext<any>, any>, fiber: Fiber) {
let current: null | Fiber = fiber;
while (current) {
if (current.tag === ContextProvider) {
let context: ReactContext<any> = current.type;
if ((context: any)._context !== undefined) {
// Support inspection of pre-19+ providers.
context = (context: any)._context;
}
const context: ReactContext<any> = current.type;
if (!contextMap.has(context)) {
// Store the current value that we're going to restore later.
contextMap.set(context, context._currentValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,6 @@ describe('ReactDOMServer', () => {
]);
});

// @gate enableRenderableContext || !__DEV__
it('should warn if an invalid contextType is defined', () => {
const Context = React.createContext();
class ComponentA extends React.Component {
Expand Down
33 changes: 5 additions & 28 deletions packages/react-is/src/ReactIs.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ import {
REACT_MEMO_TYPE,
REACT_PORTAL_TYPE,
REACT_PROFILER_TYPE,
REACT_PROVIDER_TYPE,
REACT_CONSUMER_TYPE,
REACT_STRICT_MODE_TYPE,
REACT_SUSPENSE_TYPE,
REACT_SUSPENSE_LIST_TYPE,
} from 'shared/ReactSymbols';
import isValidElementType from 'shared/isValidElementType';
import {enableRenderableContext} from 'shared/ReactFeatureFlags';

export function typeOf(object: any): mixed {
if (typeof object === 'object' && object !== null) {
Expand All @@ -49,17 +47,8 @@ export function typeOf(object: any): mixed {
case REACT_FORWARD_REF_TYPE:
case REACT_LAZY_TYPE:
case REACT_MEMO_TYPE:
return $$typeofType;
case REACT_CONSUMER_TYPE:
if (enableRenderableContext) {
return $$typeofType;
}
// Fall through
case REACT_PROVIDER_TYPE:
if (!enableRenderableContext) {
return $$typeofType;
}
// Fall through
return $$typeofType;
default:
return $$typeof;
}
Expand All @@ -72,12 +61,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 = REACT_CONSUMER_TYPE;
export const ContextProvider = REACT_CONTEXT_TYPE;
export const Element = REACT_ELEMENT_TYPE;
export const ForwardRef = REACT_FORWARD_REF_TYPE;
export const Fragment = REACT_FRAGMENT_TYPE;
Expand All @@ -92,18 +77,10 @@ export const SuspenseList = REACT_SUSPENSE_LIST_TYPE;
export {isValidElementType};

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 (
Expand Down
25 changes: 5 additions & 20 deletions packages/react-reconciler/src/ReactFiber.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import {
enableDebugTracing,
enableFloat,
enableDO_NOT_USE_disableStrictPassiveEffect,
enableRenderableContext,
} from 'shared/ReactFeatureFlags';
import {NoFlags, Placement, StaticMask} from './ReactFiberFlags';
import {ConcurrentRoot} from './ReactRootTags';
Expand Down Expand Up @@ -95,7 +94,6 @@ import {
REACT_DEBUG_TRACING_MODE_TYPE,
REACT_STRICT_MODE_TYPE,
REACT_PROFILER_TYPE,
REACT_PROVIDER_TYPE,
REACT_CONTEXT_TYPE,
REACT_CONSUMER_TYPE,
REACT_SUSPENSE_TYPE,
Expand Down Expand Up @@ -581,26 +579,13 @@ 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;
}
// Fall through
// This is a consumer
fiberTag = ContextConsumer;
break getTag;
case REACT_FORWARD_REF_TYPE:
fiberTag = ForwardRef;
if (__DEV__) {
Expand Down
30 changes: 5 additions & 25 deletions packages/react-reconciler/src/ReactFiberBeginWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ import {
enableFormActions,
enableAsyncActions,
enablePostpone,
enableRenderableContext,
enableRefAsProp,
} from 'shared/ReactFeatureFlags';
import isArray from 'shared/isArray';
Expand Down Expand Up @@ -3434,12 +3433,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 oldProps = workInProgress.memoizedProps;

Expand Down Expand Up @@ -3496,18 +3490,9 @@ 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 = consumerType._context;

const newProps = workInProgress.pendingProps;
const render = newProps.children;

Expand Down Expand Up @@ -3757,12 +3742,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;
}
Expand Down
8 changes: 1 addition & 7 deletions packages/react-reconciler/src/ReactFiberCompleteWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import {
enableCache,
enableTransitionTracing,
enableFloat,
enableRenderableContext,
passChildrenWhenCloningPersistedNodes,
} from 'shared/ReactFeatureFlags';

Expand Down Expand Up @@ -1476,12 +1475,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;
Expand Down
8 changes: 1 addition & 7 deletions packages/react-reconciler/src/ReactFiberNewContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ import {
enableLazyContextPropagation,
enableFormActions,
enableAsyncActions,
enableRenderableContext,
} from 'shared/ReactFeatureFlags';
import {
getHostTransitionProvider,
Expand Down Expand Up @@ -562,12 +561,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;
Expand Down
10 changes: 2 additions & 8 deletions packages/react-reconciler/src/ReactFiberScope.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
15 changes: 2 additions & 13 deletions packages/react-reconciler/src/ReactFiberUnwindWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import {
enableProfilerTimer,
enableCache,
enableTransitionTracing,
enableRenderableContext,
} from 'shared/ReactFeatureFlags';

import {popHostContainer, popHostContext} from './ReactFiberHostContext';
Expand Down Expand Up @@ -161,12 +160,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:
Expand Down Expand Up @@ -256,12 +250,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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1341,7 +1341,6 @@ describe('ReactNewContext', () => {
);
});

// @gate enableRenderableContext || !__DEV__
it('warns when passed a consumer', async () => {
const Context = React.createContext(0);
function Foo() {
Expand Down Expand Up @@ -1638,7 +1637,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);
Expand Down
23 changes: 5 additions & 18 deletions packages/react-reconciler/src/getComponentNameFromFiber.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
import type {ReactContext, ReactConsumerType} from 'shared/ReactTypes';
import type {Fiber} from './ReactInternalTypes';

import {
enableLegacyHidden,
enableRenderableContext,
} from 'shared/ReactFeatureFlags';
import {enableLegacyHidden} from 'shared/ReactFeatureFlags';

import {
FunctionComponent,
Expand Down Expand Up @@ -71,21 +68,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:
Expand Down
Loading