Skip to content

Commit ed453cb

Browse files
committed
[eslint] Do not allow useEffectEvent fns to be called in arbitrary closures (facebook#33544)
Summary: useEffectEvent is meant to be used specifically in combination with useEffect, and using the feature in arbitrary closures can lead to surprising reactivity semantics. In order to minimize risk in the experimental rollout, we are going to restrict its usage to being called directly inside an effect or another useEffectEvent, effectively enforcing the function coloring statically. Without an effect system this is the best we can do. DiffTrain build for [97cdd5d](facebook@97cdd5d)
1 parent 05ec0aa commit ed453cb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+21232
-25888
lines changed

compiled/eslint-plugin-react-hooks/index.js

Lines changed: 5892 additions & 11718 deletions
Large diffs are not rendered by default.

compiled/facebook-www/JSXDEVRuntime-dev.classic.js

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,10 @@ __DEV__ &&
4848
) {
4949
case REACT_PORTAL_TYPE:
5050
return "Portal";
51-
case REACT_PROVIDER_TYPE:
52-
if (enableRenderableContext) break;
53-
else return (type._context.displayName || "Context") + ".Provider";
5451
case REACT_CONTEXT_TYPE:
55-
return enableRenderableContext
56-
? (type.displayName || "Context") + ".Provider"
57-
: (type.displayName || "Context") + ".Consumer";
52+
return type.displayName || "Context";
5853
case REACT_CONSUMER_TYPE:
59-
if (enableRenderableContext)
60-
return (type._context.displayName || "Context") + ".Consumer";
61-
break;
54+
return (type._context.displayName || "Context") + ".Consumer";
6255
case REACT_FORWARD_REF_TYPE:
6356
var innerType = type.render;
6457
type = type.displayName;
@@ -272,12 +265,6 @@ __DEV__ &&
272265
for (var propName in config)
273266
"key" !== propName && (maybeKey[propName] = config[propName]);
274267
} else maybeKey = config;
275-
if (!disableDefaultPropsExceptForClasses && type && type.defaultProps) {
276-
config = type.defaultProps;
277-
for (var _propName2 in config)
278-
void 0 === maybeKey[_propName2] &&
279-
(maybeKey[_propName2] = config[_propName2]);
280-
}
281268
children &&
282269
defineKeyPropWarningGetter(
283270
maybeKey,
@@ -305,9 +292,6 @@ __DEV__ &&
305292
}
306293
var React = require("react"),
307294
dynamicFeatureFlags = require("ReactFeatureFlags"),
308-
disableDefaultPropsExceptForClasses =
309-
dynamicFeatureFlags.disableDefaultPropsExceptForClasses,
310-
enableRenderableContext = dynamicFeatureFlags.enableRenderableContext,
311295
enableTransitionTracing = dynamicFeatureFlags.enableTransitionTracing,
312296
renameElementSymbol = dynamicFeatureFlags.renameElementSymbol,
313297
enableViewTransition = dynamicFeatureFlags.enableViewTransition;
@@ -319,7 +303,6 @@ __DEV__ &&
319303
REACT_FRAGMENT_TYPE = Symbol.for("react.fragment"),
320304
REACT_STRICT_MODE_TYPE = Symbol.for("react.strict_mode"),
321305
REACT_PROFILER_TYPE = Symbol.for("react.profiler"),
322-
REACT_PROVIDER_TYPE = Symbol.for("react.provider"),
323306
REACT_CONSUMER_TYPE = Symbol.for("react.consumer"),
324307
REACT_CONTEXT_TYPE = Symbol.for("react.context"),
325308
REACT_FORWARD_REF_TYPE = Symbol.for("react.forward_ref"),
@@ -341,13 +324,13 @@ __DEV__ &&
341324
return null;
342325
};
343326
React = {
344-
"react-stack-bottom-frame": function (callStackForError) {
327+
react_stack_bottom_frame: function (callStackForError) {
345328
return callStackForError();
346329
}
347330
};
348331
var specialPropKeyWarningShown;
349332
var didWarnAboutElementRef = {};
350-
var unknownOwnerDebugStack = React["react-stack-bottom-frame"].bind(
333+
var unknownOwnerDebugStack = React.react_stack_bottom_frame.bind(
351334
React,
352335
UnknownOwner
353336
)();

compiled/facebook-www/JSXDEVRuntime-dev.modern.js

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,10 @@ __DEV__ &&
4848
) {
4949
case REACT_PORTAL_TYPE:
5050
return "Portal";
51-
case REACT_PROVIDER_TYPE:
52-
if (enableRenderableContext) break;
53-
else return (type._context.displayName || "Context") + ".Provider";
5451
case REACT_CONTEXT_TYPE:
55-
return enableRenderableContext
56-
? (type.displayName || "Context") + ".Provider"
57-
: (type.displayName || "Context") + ".Consumer";
52+
return type.displayName || "Context";
5853
case REACT_CONSUMER_TYPE:
59-
if (enableRenderableContext)
60-
return (type._context.displayName || "Context") + ".Consumer";
61-
break;
54+
return (type._context.displayName || "Context") + ".Consumer";
6255
case REACT_FORWARD_REF_TYPE:
6356
var innerType = type.render;
6457
type = type.displayName;
@@ -272,12 +265,6 @@ __DEV__ &&
272265
for (var propName in config)
273266
"key" !== propName && (maybeKey[propName] = config[propName]);
274267
} else maybeKey = config;
275-
if (!disableDefaultPropsExceptForClasses && type && type.defaultProps) {
276-
config = type.defaultProps;
277-
for (var _propName2 in config)
278-
void 0 === maybeKey[_propName2] &&
279-
(maybeKey[_propName2] = config[_propName2]);
280-
}
281268
children &&
282269
defineKeyPropWarningGetter(
283270
maybeKey,
@@ -305,9 +292,6 @@ __DEV__ &&
305292
}
306293
var React = require("react"),
307294
dynamicFeatureFlags = require("ReactFeatureFlags"),
308-
disableDefaultPropsExceptForClasses =
309-
dynamicFeatureFlags.disableDefaultPropsExceptForClasses,
310-
enableRenderableContext = dynamicFeatureFlags.enableRenderableContext,
311295
enableTransitionTracing = dynamicFeatureFlags.enableTransitionTracing,
312296
renameElementSymbol = dynamicFeatureFlags.renameElementSymbol,
313297
enableViewTransition = dynamicFeatureFlags.enableViewTransition;
@@ -319,7 +303,6 @@ __DEV__ &&
319303
REACT_FRAGMENT_TYPE = Symbol.for("react.fragment"),
320304
REACT_STRICT_MODE_TYPE = Symbol.for("react.strict_mode"),
321305
REACT_PROFILER_TYPE = Symbol.for("react.profiler"),
322-
REACT_PROVIDER_TYPE = Symbol.for("react.provider"),
323306
REACT_CONSUMER_TYPE = Symbol.for("react.consumer"),
324307
REACT_CONTEXT_TYPE = Symbol.for("react.context"),
325308
REACT_FORWARD_REF_TYPE = Symbol.for("react.forward_ref"),
@@ -341,13 +324,13 @@ __DEV__ &&
341324
return null;
342325
};
343326
React = {
344-
"react-stack-bottom-frame": function (callStackForError) {
327+
react_stack_bottom_frame: function (callStackForError) {
345328
return callStackForError();
346329
}
347330
};
348331
var specialPropKeyWarningShown;
349332
var didWarnAboutElementRef = {};
350-
var unknownOwnerDebugStack = React["react-stack-bottom-frame"].bind(
333+
var unknownOwnerDebugStack = React.react_stack_bottom_frame.bind(
351334
React,
352335
UnknownOwner
353336
)();

compiled/facebook-www/REVISION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
d742611ce40545127032f4e221c78bf9f70eb437
1+
97cdd5d3c33eda77be4f96a43f72d6916d3badbb
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
d742611ce40545127032f4e221c78bf9f70eb437
1+
97cdd5d3c33eda77be4f96a43f72d6916d3badbb

compiled/facebook-www/React-dev.classic.js

Lines changed: 23 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -122,17 +122,10 @@ __DEV__ &&
122122
) {
123123
case REACT_PORTAL_TYPE:
124124
return "Portal";
125-
case REACT_PROVIDER_TYPE:
126-
if (enableRenderableContext) break;
127-
else return (type._context.displayName || "Context") + ".Provider";
128125
case REACT_CONTEXT_TYPE:
129-
return enableRenderableContext
130-
? (type.displayName || "Context") + ".Provider"
131-
: (type.displayName || "Context") + ".Consumer";
126+
return type.displayName || "Context";
132127
case REACT_CONSUMER_TYPE:
133-
if (enableRenderableContext)
134-
return (type._context.displayName || "Context") + ".Consumer";
135-
break;
128+
return (type._context.displayName || "Context") + ".Consumer";
136129
case REACT_FORWARD_REF_TYPE:
137130
var innerType = type.render;
138131
type = type.displayName;
@@ -319,12 +312,6 @@ __DEV__ &&
319312
for (var propName in config)
320313
"key" !== propName && (maybeKey[propName] = config[propName]);
321314
} else maybeKey = config;
322-
if (!disableDefaultPropsExceptForClasses && type && type.defaultProps) {
323-
config = type.defaultProps;
324-
for (var _propName2 in config)
325-
void 0 === maybeKey[_propName2] &&
326-
(maybeKey[_propName2] = config[_propName2]);
327-
}
328315
children &&
329316
defineKeyPropWarningGetter(
330317
maybeKey,
@@ -751,9 +738,6 @@ __DEV__ &&
751738
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart &&
752739
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
753740
var dynamicFeatureFlags = require("ReactFeatureFlags"),
754-
disableDefaultPropsExceptForClasses =
755-
dynamicFeatureFlags.disableDefaultPropsExceptForClasses,
756-
enableRenderableContext = dynamicFeatureFlags.enableRenderableContext,
757741
enableTransitionTracing = dynamicFeatureFlags.enableTransitionTracing,
758742
renameElementSymbol = dynamicFeatureFlags.renameElementSymbol,
759743
enableViewTransition = dynamicFeatureFlags.enableViewTransition;
@@ -765,7 +749,6 @@ __DEV__ &&
765749
REACT_FRAGMENT_TYPE = Symbol.for("react.fragment"),
766750
REACT_STRICT_MODE_TYPE = Symbol.for("react.strict_mode"),
767751
REACT_PROFILER_TYPE = Symbol.for("react.profiler"),
768-
REACT_PROVIDER_TYPE = Symbol.for("react.provider"),
769752
REACT_CONSUMER_TYPE = Symbol.for("react.consumer"),
770753
REACT_CONTEXT_TYPE = Symbol.for("react.context"),
771754
REACT_FORWARD_REF_TYPE = Symbol.for("react.forward_ref"),
@@ -853,13 +836,13 @@ __DEV__ &&
853836
return null;
854837
};
855838
fnName = {
856-
"react-stack-bottom-frame": function (callStackForError) {
839+
react_stack_bottom_frame: function (callStackForError) {
857840
return callStackForError();
858841
}
859842
};
860843
var specialPropKeyWarningShown, didWarnAboutOldJSXRuntime;
861844
var didWarnAboutElementRef = {};
862-
var unknownOwnerDebugStack = fnName["react-stack-bottom-frame"].bind(
845+
var unknownOwnerDebugStack = fnName.react_stack_bottom_frame.bind(
863846
fnName,
864847
UnknownOwner
865848
)();
@@ -1075,6 +1058,9 @@ __DEV__ &&
10751058
return fn.apply(null, arguments);
10761059
};
10771060
};
1061+
exports.cacheSignal = function () {
1062+
return null;
1063+
};
10781064
exports.cloneElement = function (element, config, children) {
10791065
if (null === element || void 0 === element)
10801066
throw Error(
@@ -1104,37 +1090,21 @@ __DEV__ &&
11041090
JSCompiler_inline_result && (owner = getOwner());
11051091
hasValidKey(config) &&
11061092
(checkKeyStringCoercion(config.key), (key = "" + config.key));
1107-
if (
1108-
!disableDefaultPropsExceptForClasses &&
1109-
element.type &&
1110-
element.type.defaultProps
1111-
)
1112-
var defaultProps = element.type.defaultProps;
11131093
for (propName in config)
11141094
!hasOwnProperty.call(config, propName) ||
11151095
"key" === propName ||
11161096
"__self" === propName ||
11171097
"__source" === propName ||
11181098
("ref" === propName && void 0 === config.ref) ||
1119-
(props[propName] =
1120-
disableDefaultPropsExceptForClasses ||
1121-
void 0 !== config[propName] ||
1122-
void 0 === defaultProps
1123-
? config[propName]
1124-
: defaultProps[propName]);
1099+
(props[propName] = config[propName]);
11251100
}
11261101
var propName = arguments.length - 2;
11271102
if (1 === propName) props.children = children;
11281103
else if (1 < propName) {
1129-
defaultProps = Array(propName);
1130-
for (
1131-
JSCompiler_inline_result = 0;
1132-
JSCompiler_inline_result < propName;
1133-
JSCompiler_inline_result++
1134-
)
1135-
defaultProps[JSCompiler_inline_result] =
1136-
arguments[JSCompiler_inline_result + 2];
1137-
props.children = defaultProps;
1104+
JSCompiler_inline_result = Array(propName);
1105+
for (var i = 0; i < propName; i++)
1106+
JSCompiler_inline_result[i] = arguments[i + 2];
1107+
props.children = JSCompiler_inline_result;
11381108
}
11391109
props = ReactElement(
11401110
element.type,
@@ -1151,74 +1121,22 @@ __DEV__ &&
11511121
return props;
11521122
};
11531123
exports.createContext = function (defaultValue) {
1154-
var context = {
1124+
defaultValue = {
11551125
$$typeof: REACT_CONTEXT_TYPE,
11561126
_currentValue: defaultValue,
11571127
_currentValue2: defaultValue,
11581128
_threadCount: 0,
11591129
Provider: null,
11601130
Consumer: null
11611131
};
1162-
enableRenderableContext
1163-
? ((context.Provider = context),
1164-
(context.Consumer = {
1165-
$$typeof: REACT_CONSUMER_TYPE,
1166-
_context: context
1167-
}))
1168-
: ((context.Provider = {
1169-
$$typeof: REACT_PROVIDER_TYPE,
1170-
_context: context
1171-
}),
1172-
(defaultValue = { $$typeof: REACT_CONTEXT_TYPE, _context: context }),
1173-
Object.defineProperties(defaultValue, {
1174-
Provider: {
1175-
get: function () {
1176-
return context.Provider;
1177-
},
1178-
set: function (_Provider) {
1179-
context.Provider = _Provider;
1180-
}
1181-
},
1182-
_currentValue: {
1183-
get: function () {
1184-
return context._currentValue;
1185-
},
1186-
set: function (_currentValue) {
1187-
context._currentValue = _currentValue;
1188-
}
1189-
},
1190-
_currentValue2: {
1191-
get: function () {
1192-
return context._currentValue2;
1193-
},
1194-
set: function (_currentValue2) {
1195-
context._currentValue2 = _currentValue2;
1196-
}
1197-
},
1198-
_threadCount: {
1199-
get: function () {
1200-
return context._threadCount;
1201-
},
1202-
set: function (_threadCount) {
1203-
context._threadCount = _threadCount;
1204-
}
1205-
},
1206-
Consumer: {
1207-
get: function () {
1208-
return context.Consumer;
1209-
}
1210-
},
1211-
displayName: {
1212-
get: function () {
1213-
return context.displayName;
1214-
},
1215-
set: function () {}
1216-
}
1217-
}),
1218-
(context.Consumer = defaultValue));
1219-
context._currentRenderer = null;
1220-
context._currentRenderer2 = null;
1221-
return context;
1132+
defaultValue.Provider = defaultValue;
1133+
defaultValue.Consumer = {
1134+
$$typeof: REACT_CONSUMER_TYPE,
1135+
_context: defaultValue
1136+
};
1137+
defaultValue._currentRenderer = null;
1138+
defaultValue._currentRenderer2 = null;
1139+
return defaultValue;
12221140
};
12231141
exports.createElement = function (type, config, children) {
12241142
for (var i = 2; i < arguments.length; i++)
@@ -1381,32 +1299,11 @@ __DEV__ &&
13811299
);
13821300
};
13831301
exports.lazy = function (ctor) {
1384-
var lazyType = {
1302+
return {
13851303
$$typeof: REACT_LAZY_TYPE,
13861304
_payload: { _status: -1, _result: ctor },
13871305
_init: lazyInitializer
13881306
};
1389-
if (!disableDefaultPropsExceptForClasses) {
1390-
var defaultProps;
1391-
Object.defineProperties(lazyType, {
1392-
defaultProps: {
1393-
configurable: !0,
1394-
get: function () {
1395-
return defaultProps;
1396-
},
1397-
set: function (newDefaultProps) {
1398-
console.error(
1399-
"It is not supported to assign `defaultProps` to a lazy component import. Either specify them where the component is defined, or create a wrapping component around it."
1400-
);
1401-
defaultProps = newDefaultProps;
1402-
Object.defineProperty(lazyType, "defaultProps", {
1403-
enumerable: !0
1404-
});
1405-
}
1406-
}
1407-
});
1408-
}
1409-
return lazyType;
14101307
};
14111308
exports.memo = function (type, compare) {
14121309
null == type &&
@@ -1537,7 +1434,7 @@ __DEV__ &&
15371434
exports.useTransition = function () {
15381435
return resolveDispatcher().useTransition();
15391436
};
1540-
exports.version = "19.2.0-www-classic-d742611c-20250603";
1437+
exports.version = "19.2.0-www-classic-97cdd5d3-20250710";
15411438
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
15421439
"function" ===
15431440
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

0 commit comments

Comments
 (0)