Skip to content

Commit

Permalink
Feature flag to disable legacy context for function components (#30319)
Browse files Browse the repository at this point in the history
While the goal is to remove legacy context completely, I think we can
already land the removal of legacy context for function components. I
didn't even know this feature existed until reading the code recently.

The win is just a couple of property lookups on function renders, but it
trims down the API already as the full removal will likely still take a
bit more time.

www: Starting with enabled test renderer and a feature flag for
production rollout.

RN: Not enabled, will follow up on this.

DiffTrain build for [af28f48](af28f48)
  • Loading branch information
kassens committed Jul 11, 2024
1 parent b71b43e commit 2a5d4d4
Show file tree
Hide file tree
Showing 34 changed files with 170 additions and 134 deletions.
2 changes: 1 addition & 1 deletion compiled/facebook-www/REVISION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
a09950ed418adb26a5e735b4ee9eca5e5282ffc7
af28f480e8e74ce71bb33259b61fef8a5a228f74
2 changes: 1 addition & 1 deletion compiled/facebook-www/REVISION_TRANSFORMS
Original file line number Diff line number Diff line change
@@ -1 +1 @@
a09950ed418adb26a5e735b4ee9eca5e5282ffc7
af28f480e8e74ce71bb33259b61fef8a5a228f74
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -1998,7 +1998,7 @@ __DEV__ &&
exports.useTransition = function () {
return resolveDispatcher().useTransition();
};
exports.version = "19.0.0-www-classic-a09950ed41-20240711";
exports.version = "19.0.0-www-classic-af28f480-20240711";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -1978,7 +1978,7 @@ __DEV__ &&
exports.useTransition = function () {
return resolveDispatcher().useTransition();
};
exports.version = "19.0.0-www-modern-a09950ed41-20240711";
exports.version = "19.0.0-www-modern-af28f480-20240711";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-prod.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -669,4 +669,4 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactSharedInternals.H.useTransition();
};
exports.version = "19.0.0-www-classic-a09950ed41-20240711";
exports.version = "19.0.0-www-classic-af28f480-20240711";
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-prod.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -669,4 +669,4 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactSharedInternals.H.useTransition();
};
exports.version = "19.0.0-www-modern-a09950ed41-20240711";
exports.version = "19.0.0-www-modern-af28f480-20240711";
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-profiling.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactSharedInternals.H.useTransition();
};
exports.version = "19.0.0-www-classic-a09950ed41-20240711";
exports.version = "19.0.0-www-classic-af28f480-20240711";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-profiling.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactSharedInternals.H.useTransition();
};
exports.version = "19.0.0-www-modern-a09950ed41-20240711";
exports.version = "19.0.0-www-modern-af28f480-20240711";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
18 changes: 11 additions & 7 deletions compiled/facebook-www/ReactART-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -6732,18 +6732,20 @@ __DEV__ &&
"%s uses the legacy contextTypes API which will be removed soon. Use React.createContext() with React.useContext() instead. (https://react.dev/link/legacy-context)",
componentName
))));
componentName = isContextProvider(Component)
? previousContext
: contextStackCursor$1.current;
componentName = getMaskedContext(workInProgress, componentName);
if (!disableLegacyContextForFunctionComponents) {
var context = isContextProvider(Component)
? previousContext
: contextStackCursor$1.current;
context = getMaskedContext(workInProgress, context);
}
prepareToReadContext(workInProgress, renderLanes);
enableSchedulingProfiler && markComponentRenderStarted(workInProgress);
Component = renderWithHooks(
current,
workInProgress,
Component,
nextProps,
componentName,
context,
renderLanes
);
enableSchedulingProfiler && markComponentRenderStopped();
Expand Down Expand Up @@ -14931,6 +14933,8 @@ __DEV__ &&
alwaysThrottleRetries = dynamicFeatureFlags.alwaysThrottleRetries,
disableDefaultPropsExceptForClasses =
dynamicFeatureFlags.disableDefaultPropsExceptForClasses,
disableLegacyContextForFunctionComponents =
dynamicFeatureFlags.disableLegacyContextForFunctionComponents,
disableSchedulerTimeoutInWorkLoop =
dynamicFeatureFlags.disableSchedulerTimeoutInWorkLoop,
enableDebugTracing = dynamicFeatureFlags.enableDebugTracing,
Expand Down Expand Up @@ -17017,14 +17021,14 @@ __DEV__ &&
scheduleRoot: scheduleRoot,
setRefreshHandler: setRefreshHandler,
getCurrentFiber: getCurrentFiberForDevTools,
reconcilerVersion: "19.0.0-www-classic-a09950ed41-20240711"
reconcilerVersion: "19.0.0-www-classic-af28f480-20240711"
});
})({
findFiberByHostInstance: function () {
return null;
},
bundleType: 1,
version: "19.0.0-www-classic-a09950ed41-20240711",
version: "19.0.0-www-classic-af28f480-20240711",
rendererPackageName: "react-art"
});
var ClippingRectangle = TYPES.CLIPPING_RECTANGLE,
Expand Down
4 changes: 2 additions & 2 deletions compiled/facebook-www/ReactART-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -16432,14 +16432,14 @@ __DEV__ &&
scheduleRoot: scheduleRoot,
setRefreshHandler: setRefreshHandler,
getCurrentFiber: getCurrentFiberForDevTools,
reconcilerVersion: "19.0.0-www-modern-a09950ed41-20240711"
reconcilerVersion: "19.0.0-www-modern-af28f480-20240711"
});
})({
findFiberByHostInstance: function () {
return null;
},
bundleType: 1,
version: "19.0.0-www-modern-a09950ed41-20240711",
version: "19.0.0-www-modern-af28f480-20240711",
rendererPackageName: "react-art"
});
var ClippingRectangle = TYPES.CLIPPING_RECTANGLE,
Expand Down
16 changes: 10 additions & 6 deletions compiled/facebook-www/ReactART-prod.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ var dynamicFeatureFlags = require("ReactFeatureFlags"),
alwaysThrottleRetries = dynamicFeatureFlags.alwaysThrottleRetries,
disableDefaultPropsExceptForClasses =
dynamicFeatureFlags.disableDefaultPropsExceptForClasses,
disableLegacyContextForFunctionComponents =
dynamicFeatureFlags.disableLegacyContextForFunctionComponents,
disableSchedulerTimeoutInWorkLoop =
dynamicFeatureFlags.disableSchedulerTimeoutInWorkLoop,
enableDebugTracing = dynamicFeatureFlags.enableDebugTracing,
Expand Down Expand Up @@ -4683,10 +4685,12 @@ function updateFunctionComponent(
nextProps,
renderLanes
) {
var context = isContextProvider(Component)
? previousContext
: contextStackCursor$1.current;
context = getMaskedContext(workInProgress, context);
if (!disableLegacyContextForFunctionComponents) {
var context = isContextProvider(Component)
? previousContext
: contextStackCursor$1.current;
context = getMaskedContext(workInProgress, context);
}
prepareToReadContext(workInProgress, renderLanes);
Component = renderWithHooks(
current,
Expand Down Expand Up @@ -10749,7 +10753,7 @@ var slice = Array.prototype.slice,
return null;
},
bundleType: 0,
version: "19.0.0-www-classic-a09950ed41-20240711",
version: "19.0.0-www-classic-af28f480-20240711",
rendererPackageName: "react-art"
};
var internals$jscomp$inline_1386 = {
Expand Down Expand Up @@ -10780,7 +10784,7 @@ var internals$jscomp$inline_1386 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "19.0.0-www-classic-a09950ed41-20240711"
reconcilerVersion: "19.0.0-www-classic-af28f480-20240711"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1387 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down
4 changes: 2 additions & 2 deletions compiled/facebook-www/ReactART-prod.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -10202,7 +10202,7 @@ var slice = Array.prototype.slice,
return null;
},
bundleType: 0,
version: "19.0.0-www-modern-a09950ed41-20240711",
version: "19.0.0-www-modern-af28f480-20240711",
rendererPackageName: "react-art"
};
var internals$jscomp$inline_1372 = {
Expand Down Expand Up @@ -10233,7 +10233,7 @@ var internals$jscomp$inline_1372 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "19.0.0-www-modern-a09950ed41-20240711"
reconcilerVersion: "19.0.0-www-modern-af28f480-20240711"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1373 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down
24 changes: 14 additions & 10 deletions compiled/facebook-www/ReactDOM-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -8732,18 +8732,20 @@ __DEV__ &&
"%s uses the legacy contextTypes API which will be removed soon. Use React.createContext() with React.useContext() instead. (https://react.dev/link/legacy-context)",
componentName
))));
componentName = isContextProvider(Component)
? previousContext
: contextStackCursor.current;
componentName = getMaskedContext(workInProgress, componentName);
if (!disableLegacyContextForFunctionComponents) {
var context = isContextProvider(Component)
? previousContext
: contextStackCursor.current;
context = getMaskedContext(workInProgress, context);
}
prepareToReadContext(workInProgress, renderLanes);
enableSchedulingProfiler && markComponentRenderStarted(workInProgress);
Component = renderWithHooks(
current,
workInProgress,
Component,
nextProps,
componentName,
context,
renderLanes
);
nextProps = checkDidRenderIdHook();
Expand Down Expand Up @@ -23980,6 +23982,8 @@ __DEV__ &&
alwaysThrottleRetries = dynamicFeatureFlags.alwaysThrottleRetries,
disableDefaultPropsExceptForClasses =
dynamicFeatureFlags.disableDefaultPropsExceptForClasses,
disableLegacyContextForFunctionComponents =
dynamicFeatureFlags.disableLegacyContextForFunctionComponents,
disableSchedulerTimeoutInWorkLoop =
dynamicFeatureFlags.disableSchedulerTimeoutInWorkLoop,
enableDebugTracing = dynamicFeatureFlags.enableDebugTracing,
Expand Down Expand Up @@ -27566,11 +27570,11 @@ __DEV__ &&
: flushSyncErrorInBuildsThatSupportLegacyMode;
(function () {
var isomorphicReactPackageVersion = React.version;
if ("19.0.0-www-classic-a09950ed41-20240711" !== isomorphicReactPackageVersion)
if ("19.0.0-www-classic-af28f480-20240711" !== isomorphicReactPackageVersion)
throw Error(
'Incompatible React versions: The "react" and "react-dom" packages must have the exact same version. Instead got:\n - react: ' +
(isomorphicReactPackageVersion +
"\n - react-dom: 19.0.0-www-classic-a09950ed41-20240711\nLearn more: https://react.dev/warnings/version-mismatch")
"\n - react-dom: 19.0.0-www-classic-af28f480-20240711\nLearn more: https://react.dev/warnings/version-mismatch")
);
})();
("function" === typeof Map &&
Expand Down Expand Up @@ -27636,12 +27640,12 @@ __DEV__ &&
scheduleRoot: scheduleRoot,
setRefreshHandler: setRefreshHandler,
getCurrentFiber: getCurrentFiberForDevTools,
reconcilerVersion: "19.0.0-www-classic-a09950ed41-20240711"
reconcilerVersion: "19.0.0-www-classic-af28f480-20240711"
});
})({
findFiberByHostInstance: getClosestInstanceFromNode,
bundleType: 1,
version: "19.0.0-www-classic-a09950ed41-20240711",
version: "19.0.0-www-classic-af28f480-20240711",
rendererPackageName: "react-dom"
}) &&
canUseDOM &&
Expand Down Expand Up @@ -28284,7 +28288,7 @@ __DEV__ &&
exports.useFormStatus = function () {
return resolveDispatcher().useHostTransitionStatus();
};
exports.version = "19.0.0-www-classic-a09950ed41-20240711";
exports.version = "19.0.0-www-classic-af28f480-20240711";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
10 changes: 5 additions & 5 deletions compiled/facebook-www/ReactDOM-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -26698,11 +26698,11 @@ __DEV__ &&
return_targetInst = null;
(function () {
var isomorphicReactPackageVersion = React.version;
if ("19.0.0-www-modern-a09950ed41-20240711" !== isomorphicReactPackageVersion)
if ("19.0.0-www-modern-af28f480-20240711" !== isomorphicReactPackageVersion)
throw Error(
'Incompatible React versions: The "react" and "react-dom" packages must have the exact same version. Instead got:\n - react: ' +
(isomorphicReactPackageVersion +
"\n - react-dom: 19.0.0-www-modern-a09950ed41-20240711\nLearn more: https://react.dev/warnings/version-mismatch")
"\n - react-dom: 19.0.0-www-modern-af28f480-20240711\nLearn more: https://react.dev/warnings/version-mismatch")
);
})();
("function" === typeof Map &&
Expand Down Expand Up @@ -26767,12 +26767,12 @@ __DEV__ &&
scheduleRoot: scheduleRoot,
setRefreshHandler: setRefreshHandler,
getCurrentFiber: getCurrentFiberForDevTools,
reconcilerVersion: "19.0.0-www-modern-a09950ed41-20240711"
reconcilerVersion: "19.0.0-www-modern-af28f480-20240711"
});
})({
findFiberByHostInstance: getClosestInstanceFromNode,
bundleType: 1,
version: "19.0.0-www-modern-a09950ed41-20240711",
version: "19.0.0-www-modern-af28f480-20240711",
rendererPackageName: "react-dom"
}) &&
canUseDOM &&
Expand Down Expand Up @@ -27368,7 +27368,7 @@ __DEV__ &&
exports.useFormStatus = function () {
return resolveDispatcher().useHostTransitionStatus();
};
exports.version = "19.0.0-www-modern-a09950ed41-20240711";
exports.version = "19.0.0-www-modern-af28f480-20240711";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
22 changes: 13 additions & 9 deletions compiled/facebook-www/ReactDOM-prod.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ var dynamicFeatureFlags = require("ReactFeatureFlags"),
alwaysThrottleRetries = dynamicFeatureFlags.alwaysThrottleRetries,
disableDefaultPropsExceptForClasses =
dynamicFeatureFlags.disableDefaultPropsExceptForClasses,
disableLegacyContextForFunctionComponents =
dynamicFeatureFlags.disableLegacyContextForFunctionComponents,
disableSchedulerTimeoutInWorkLoop =
dynamicFeatureFlags.disableSchedulerTimeoutInWorkLoop,
enableDebugTracing = dynamicFeatureFlags.enableDebugTracing,
Expand Down Expand Up @@ -5610,10 +5612,12 @@ function updateFunctionComponent(
nextProps,
renderLanes
) {
var context = isContextProvider(Component)
? previousContext
: contextStackCursor.current;
context = getMaskedContext(workInProgress, context);
if (!disableLegacyContextForFunctionComponents) {
var context = isContextProvider(Component)
? previousContext
: contextStackCursor.current;
context = getMaskedContext(workInProgress, context);
}
prepareToReadContext(workInProgress, renderLanes);
Component = renderWithHooks(
current,
Expand Down Expand Up @@ -17194,14 +17198,14 @@ function getCrossOriginStringAs(as, input) {
}
var isomorphicReactPackageVersion$jscomp$inline_1769 = React.version;
if (
"19.0.0-www-classic-a09950ed41-20240711" !==
"19.0.0-www-classic-af28f480-20240711" !==
isomorphicReactPackageVersion$jscomp$inline_1769
)
throw Error(
formatProdErrorMessage(
527,
isomorphicReactPackageVersion$jscomp$inline_1769,
"19.0.0-www-classic-a09950ed41-20240711"
"19.0.0-www-classic-af28f480-20240711"
)
);
function flushSyncFromReconciler(fn) {
Expand Down Expand Up @@ -17247,7 +17251,7 @@ Internals.Events = [
var devToolsConfig$jscomp$inline_1776 = {
findFiberByHostInstance: getClosestInstanceFromNode,
bundleType: 0,
version: "19.0.0-www-classic-a09950ed41-20240711",
version: "19.0.0-www-classic-af28f480-20240711",
rendererPackageName: "react-dom"
};
var internals$jscomp$inline_2220 = {
Expand Down Expand Up @@ -17277,7 +17281,7 @@ var internals$jscomp$inline_2220 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "19.0.0-www-classic-a09950ed41-20240711"
reconcilerVersion: "19.0.0-www-classic-af28f480-20240711"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_2221 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down Expand Up @@ -17741,4 +17745,4 @@ exports.useFormState = function (action, initialState, permalink) {
exports.useFormStatus = function () {
return ReactSharedInternals.H.useHostTransitionStatus();
};
exports.version = "19.0.0-www-classic-a09950ed41-20240711";
exports.version = "19.0.0-www-classic-af28f480-20240711";
Loading

0 comments on commit 2a5d4d4

Please sign in to comment.