Skip to content

Commit e7a3c5c

Browse files
committed
[compiler] enablePreserveMemo treats manual deps as non-nullable (#34503)
The `@enablePreserveExistingMemoizationGuarantees` mode can still fail to preserve manual memoization due to mismtached dependencies. Specifically, where the user's dependencies are more precise than the compiler infers bc the compiler is being conservative about what might be nullable. In this mode though we're intentionally using information from the manual memoization and can also rely on the deps as a signal for what's non-nullable. The idea of the PR is that we treat manual memo deps just like other inferred-as-non-nullable objects during PropagateScopeDeps. We're careful to not treat the full path as non-nullable, only up to the last property index. So `x.y.z` as a manual dep treats `x` and `x.y` as non-nullable, allowing us to preserve a conditional dependency on `x.y.z`. Optionals within manual dependencies are a bit trickier and aren't handled yet, but hopefully that's less common and something we can improve in a follow-up. Not handling them just means that developers may hit false positives on validating existing memoization if they use optional chains in manual dependencies. --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/facebook/react/pull/34503). * #34689 * __->__ #34503 DiffTrain build for [57d5a59](57d5a59)
1 parent 87f0469 commit e7a3c5c

35 files changed

+109
-86
lines changed

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45363,6 +45363,29 @@ function collectNonNullsInBlocks(fn, context) {
4536345363
}
4536445364
}
4536545365
}
45366+
else if (fn.env.config.enablePreserveExistingMemoizationGuarantees &&
45367+
instr.value.kind === 'StartMemoize' &&
45368+
instr.value.deps != null) {
45369+
for (const dep of instr.value.deps) {
45370+
if (dep.root.kind === 'NamedLocal') {
45371+
if (!isImmutableAtInstr(dep.root.value.identifier, instr.id, context)) {
45372+
continue;
45373+
}
45374+
for (let i = 0; i < dep.path.length; i++) {
45375+
const pathEntry = dep.path[i];
45376+
if (pathEntry.optional) {
45377+
break;
45378+
}
45379+
const depNode = context.registry.getOrCreateProperty({
45380+
identifier: dep.root.value.identifier,
45381+
path: dep.path.slice(0, i),
45382+
reactive: dep.root.value.reactive,
45383+
});
45384+
assumedNonNullObjects.add(depNode);
45385+
}
45386+
}
45387+
}
45388+
}
4536645389
}
4536745390
nodes.set(block.id, {
4536845391
block,

compiled/facebook-www/REVISION

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

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-d74f061b-20251001";
1461+
exports.version = "19.3.0-www-classic-57d5a597-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-d74f061b-20251001";
1461+
exports.version = "19.3.0-www-modern-57d5a597-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-d74f061b-20251001";
607+
exports.version = "19.3.0-www-classic-57d5a597-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-d74f061b-20251001";
607+
exports.version = "19.3.0-www-modern-57d5a597-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-d74f061b-20251001";
611+
exports.version = "19.3.0-www-classic-57d5a597-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-d74f061b-20251001";
611+
exports.version = "19.3.0-www-modern-57d5a597-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-d74f061b-20251001",
20306+
version: "19.3.0-www-classic-57d5a597-20251002",
2030720307
rendererPackageName: "react-art",
2030820308
currentDispatcherRef: ReactSharedInternals,
20309-
reconcilerVersion: "19.3.0-www-classic-d74f061b-20251001"
20309+
reconcilerVersion: "19.3.0-www-classic-57d5a597-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-d74f061b-20251001";
20344+
exports.version = "19.3.0-www-classic-57d5a597-20251002";
2034520345
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
2034620346
"function" ===
2034720347
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

0 commit comments

Comments
 (0)