Compare commits

...

1 Commits

Author SHA1 Message Date
Dan Abramov
ed30b1494e Revert "Add a feature flag for new behavior"
This reverts commit c86765f81847f7dc7fefff8d09da84c95fb66a6b.
2024-02-25 20:26:34 +00:00
27 changed files with 45 additions and 289 deletions

View File

@@ -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';
@@ -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),

View File

@@ -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);

View File

@@ -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');

View File

@@ -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 {

View File

@@ -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) {
@@ -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;
}
@@ -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;
@@ -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 (

View File

@@ -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';
@@ -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,
@@ -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__) {

View File

@@ -109,7 +109,6 @@ import {
enableFormActions,
enableAsyncActions,
enablePostpone,
enableRenderableContext,
enableRefAsProp,
} from 'shared/ReactFeatureFlags';
import isArray from 'shared/isArray';
@@ -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;
@@ -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;
@@ -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;
}

View File

@@ -39,7 +39,6 @@ import {
enableCache,
enableTransitionTracing,
enableFloat,
enableRenderableContext,
passChildrenWhenCloningPersistedNodes,
} from 'shared/ReactFeatureFlags';
@@ -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;

View File

@@ -46,7 +46,6 @@ import {
enableLazyContextPropagation,
enableFormActions,
enableAsyncActions,
enableRenderableContext,
} from 'shared/ReactFeatureFlags';
import {
getHostTransitionProvider,
@@ -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;

View File

@@ -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 {

View File

@@ -35,7 +35,6 @@ import {
enableProfilerTimer,
enableCache,
enableTransitionTracing,
enableRenderableContext,
} from 'shared/ReactFeatureFlags';
import {popHostContainer, popHostContext} from './ReactFiberHostContext';
@@ -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:
@@ -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:

View File

@@ -1341,7 +1341,6 @@ describe('ReactNewContext', () => {
);
});
// @gate enableRenderableContext || !__DEV__
it('warns when passed a consumer', async () => {
const Context = React.createContext(0);
function Foo() {
@@ -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);

View File

@@ -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,
@@ -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:

View File

@@ -128,7 +128,6 @@ import {
REACT_FRAGMENT_TYPE,
REACT_FORWARD_REF_TYPE,
REACT_MEMO_TYPE,
REACT_PROVIDER_TYPE,
REACT_CONTEXT_TYPE,
REACT_CONSUMER_TYPE,
REACT_SCOPE_TYPE,
@@ -144,7 +143,6 @@ import {
enableFloat,
enableCache,
enablePostpone,
enableRenderableContext,
enableRefAsProp,
} from 'shared/ReactFeatureFlags';
@@ -1724,9 +1722,10 @@ function renderContextConsumer(
request: Request,
task: Task,
keyPath: KeyNode,
context: ReactContext<any>,
type: ReactConsumerType<any>,
props: Object,
): void {
const context = type._context;
const render = props.children;
if (__DEV__) {
@@ -1906,38 +1905,13 @@ 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;
}
renderContextProvider(request, task, keyPath, type, 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
renderContextConsumer(request, task, keyPath, type, props);
return;
}
case REACT_LAZY_TYPE: {
renderLazyComponent(request, task, keyPath, type, props);

View File

@@ -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,72 +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;

View File

@@ -467,7 +467,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 {

View File

@@ -121,8 +121,6 @@ export const passChildrenWhenCloningPersistedNodes = false;
export const enableUseDeferredValueInitialArg = __EXPERIMENTAL__;
export const enableRenderableContext = false;
export const enableServerComponentLogs = __EXPERIMENTAL__;
/**

View File

@@ -17,7 +17,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');

View File

@@ -66,7 +66,6 @@ export const enableClientRenderFallbackOnTextMismatch = true;
export const enableLegacyFBSupport = false;
export const enableFilterEmptyStringAttributesDOM = true;
export const enableGetInspectorDataForInstanceInProduction = true;
export const enableRenderableContext = false;
export const enableRetryLaneExpiration = false;
export const retryLaneExpirationMs = 5000;

View File

@@ -49,7 +49,6 @@ export const enableComponentStackLocations = false;
export const enableLegacyFBSupport = false;
export const enableFilterEmptyStringAttributesDOM = true;
export const enableGetInspectorDataForInstanceInProduction = false;
export const enableRenderableContext = false;
export const enableRetryLaneExpiration = false;
export const retryLaneExpirationMs = 5000;

View File

@@ -49,7 +49,6 @@ export const enableComponentStackLocations = true;
export const enableLegacyFBSupport = false;
export const enableFilterEmptyStringAttributesDOM = true;
export const enableGetInspectorDataForInstanceInProduction = false;
export const enableRenderableContext = false;
export const enableRetryLaneExpiration = false;
export const retryLaneExpirationMs = 5000;

View File

@@ -51,7 +51,6 @@ export const enableUseEffectEventHook = false;
export const enableClientRenderFallbackOnTextMismatch = true;
export const enableUseRefAccessWarning = false;
export const enableInfiniteRenderLoopDetection = false;
export const enableRenderableContext = false;
export const enableRetryLaneExpiration = false;
export const retryLaneExpirationMs = 5000;

View File

@@ -49,7 +49,6 @@ export const enableComponentStackLocations = true;
export const enableLegacyFBSupport = false;
export const enableFilterEmptyStringAttributesDOM = true;
export const enableGetInspectorDataForInstanceInProduction = false;
export const enableRenderableContext = false;
export const enableRetryLaneExpiration = false;
export const retryLaneExpirationMs = 5000;

View File

@@ -27,7 +27,6 @@ export const enableDeferRootSchedulingToMicrotask = __VARIANT__;
export const alwaysThrottleRetries = __VARIANT__;
export const enableDO_NOT_USE_disableStrictPassiveEffect = __VARIANT__;
export const enableUseDeferredValueInitialArg = __VARIANT__;
export const enableRenderableContext = __VARIANT__;
export const useModernStrictMode = __VARIANT__;
export const enableRefAsProp = __VARIANT__;
export const enableClientRenderFallbackOnTextMismatch = __VARIANT__;

View File

@@ -35,7 +35,6 @@ export const {
syncLaneExpirationMs,
transitionLaneExpirationMs,
enableInfiniteRenderLoopDetection,
enableRenderableContext,
useModernStrictMode,
enableRefAsProp,
enableClientRenderFallbackOnTextMismatch,

View File

@@ -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,
@@ -27,11 +26,7 @@ import {
REACT_TRACING_MARKER_TYPE,
} from 'shared/ReactSymbols';
import {
enableTransitionTracing,
enableCache,
enableRenderableContext,
} from './ReactFeatureFlags';
import {enableTransitionTracing, enableCache} from './ReactFeatureFlags';
// Keep in sync with react-reconciler/getComponentNameFromFiber
function getWrappedName(
@@ -103,27 +98,12 @@ export default function getComponentNameFromType(type: mixed): string | null {
}
}
switch (type.$$typeof) {
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:

View File

@@ -10,7 +10,6 @@
import {
REACT_CONTEXT_TYPE,
REACT_CONSUMER_TYPE,
REACT_PROVIDER_TYPE,
REACT_FORWARD_REF_TYPE,
REACT_FRAGMENT_TYPE,
REACT_PROFILER_TYPE,
@@ -32,7 +31,6 @@ import {
enableTransitionTracing,
enableDebugTracing,
enableLegacyHidden,
enableRenderableContext,
} from './ReactFeatureFlags';
const REACT_CLIENT_REFERENCE: symbol = Symbol.for('react.client.reference');
@@ -64,8 +62,7 @@ export default 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