Skip to content

Commit fc4307a

Browse files
committed
[compiler] @enablePreserveExistingMemoizationGuarantees on by default (#34689)
This enables `@enablePreserveExistingMemoizationGuarantees` by default. As of the previous PR (#34503), this mode now enables the following behaviors: - Treating variables referenced within a `useMemo()` or `useCallback()` as "frozen" (immutable) as of the start of the call. Ie, the compiler will assume that the values you reference are not mutated by the body of the useMemo, not are they mutated later. Directly modifying them (eg `var.property = true`) will be an error. - Similarly, the results of the useMemo/useCallback are treated as frozen (immutable) after the call. These two rules match the behavior for other hooks: this means that developers will see similar behavior to swapping out `useMemo()` for a custom `useMyMemo()` wrapper/alias. Additionally, as of #34503 the compiler uses information from the manual dependencies to know which variables are non-nullable. Even if a useMemo block conditionally accesses a nested property — `if (cond) { log(x.y.z) }` — where the compiler would not usually know that `x` is non-nullable, if the user specifies `x.y.z` as a manual dependency then the compiler knows that `x` and `x.y` are non-nullable and can infer a more precise dependency. Finally, this mode also ensures that we always memoize function calls that return primitives. See #34343 for more details. For now, I've explicitly opted out of this feature in all test fixtures where the behavior changed. DiffTrain build for [70b52be](70b52be)
1 parent e7a3c5c commit fc4307a

35 files changed

+87
-87
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32123,7 +32123,7 @@ const EnvironmentConfigSchema = zod.z.object({
3212332123
moduleTypeProvider: zod.z.nullable(zod.z.function().args(zod.z.string())).default(null),
3212432124
customMacros: zod.z.nullable(zod.z.array(MacroSchema)).default(null),
3212532125
enableResetCacheOnSourceFileChanges: zod.z.nullable(zod.z.boolean()).default(null),
32126-
enablePreserveExistingMemoizationGuarantees: zod.z.boolean().default(false),
32126+
enablePreserveExistingMemoizationGuarantees: zod.z.boolean().default(true),
3212732127
validatePreserveExistingMemoizationGuarantees: zod.z.boolean().default(true),
3212832128
enablePreserveExistingManualUseMemo: zod.z.boolean().default(false),
3212932129
enableForest: zod.z.boolean().default(false),

compiled/facebook-www/REVISION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
57d5a59748bbec1b507bb778c9fbe4bcb82b0a94
1+
70b52beca64aeac447a6cf57cfe1fda0691435c1
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
57d5a59748bbec1b507bb778c9fbe4bcb82b0a94
1+
70b52beca64aeac447a6cf57cfe1fda0691435c1

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1458,7 +1458,7 @@ __DEV__ &&
14581458
exports.useTransition = function () {
14591459
return resolveDispatcher().useTransition();
14601460
};
1461-
exports.version = "19.3.0-www-classic-57d5a597-20251002";
1461+
exports.version = "19.3.0-www-classic-70b52bec-20251002";
14621462
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
14631463
"function" ===
14641464
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1458,7 +1458,7 @@ __DEV__ &&
14581458
exports.useTransition = function () {
14591459
return resolveDispatcher().useTransition();
14601460
};
1461-
exports.version = "19.3.0-www-modern-57d5a597-20251002";
1461+
exports.version = "19.3.0-www-modern-70b52bec-20251002";
14621462
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
14631463
"function" ===
14641464
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,4 +604,4 @@ exports.useSyncExternalStore = function (
604604
exports.useTransition = function () {
605605
return ReactSharedInternals.H.useTransition();
606606
};
607-
exports.version = "19.3.0-www-classic-57d5a597-20251002";
607+
exports.version = "19.3.0-www-classic-70b52bec-20251002";

compiled/facebook-www/React-prod.modern.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,4 +604,4 @@ exports.useSyncExternalStore = function (
604604
exports.useTransition = function () {
605605
return ReactSharedInternals.H.useTransition();
606606
};
607-
exports.version = "19.3.0-www-modern-57d5a597-20251002";
607+
exports.version = "19.3.0-www-modern-70b52bec-20251002";

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ exports.useSyncExternalStore = function (
608608
exports.useTransition = function () {
609609
return ReactSharedInternals.H.useTransition();
610610
};
611-
exports.version = "19.3.0-www-classic-57d5a597-20251002";
611+
exports.version = "19.3.0-www-classic-70b52bec-20251002";
612612
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
613613
"function" ===
614614
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

compiled/facebook-www/React-profiling.modern.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ exports.useSyncExternalStore = function (
608608
exports.useTransition = function () {
609609
return ReactSharedInternals.H.useTransition();
610610
};
611-
exports.version = "19.3.0-www-modern-57d5a597-20251002";
611+
exports.version = "19.3.0-www-modern-70b52bec-20251002";
612612
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
613613
"function" ===
614614
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20303,10 +20303,10 @@ __DEV__ &&
2030320303
(function () {
2030420304
var internals = {
2030520305
bundleType: 1,
20306-
version: "19.3.0-www-classic-57d5a597-20251002",
20306+
version: "19.3.0-www-classic-70b52bec-20251002",
2030720307
rendererPackageName: "react-art",
2030820308
currentDispatcherRef: ReactSharedInternals,
20309-
reconcilerVersion: "19.3.0-www-classic-57d5a597-20251002"
20309+
reconcilerVersion: "19.3.0-www-classic-70b52bec-20251002"
2031020310
};
2031120311
internals.overrideHookState = overrideHookState;
2031220312
internals.overrideHookStateDeletePath = overrideHookStateDeletePath;
@@ -20341,7 +20341,7 @@ __DEV__ &&
2034120341
exports.Shape = Shape;
2034220342
exports.Surface = Surface;
2034320343
exports.Text = Text;
20344-
exports.version = "19.3.0-www-classic-57d5a597-20251002";
20344+
exports.version = "19.3.0-www-classic-70b52bec-20251002";
2034520345
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
2034620346
"function" ===
2034720347
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

0 commit comments

Comments
 (0)