Skip to content

Commit

Permalink
[Fresh] Always reset useMemoCache on Fast Refresh (#30700)
Browse files Browse the repository at this point in the history
Stacked on #30662.

Alternative to #30663 and
#30677.

During a Fast Refresh, we always want to evict the memo cache, same as
we do with normal `useMemo`. The mechanism used by `useMemo` and other
Hooks is this module-level variable:

https://github.com/facebook/react/blob/fca5d655d78917400a2722287351c20938166669/packages/react-reconciler/src/ReactFiberHooks.js#L304-L307

which has DEV-only behavior as if the dependencies are always different:

https://github.com/facebook/react/blob/fca5d655d78917400a2722287351c20938166669/packages/react-reconciler/src/ReactFiberHooks.js#L451-L460

The `useMemoCache` Hook doesn't use a dependency array but conceptually
I think we want the same behavior.

## Test Plan

The test passes.

---------

Co-authored-by: Lauren Tan <[email protected]>

DiffTrain build for commit 7e8a06c.
  • Loading branch information
gaearon committed Aug 15, 2024
1 parent 7a7933b commit 220e25c
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 47 deletions.
2 changes: 1 addition & 1 deletion compiled-rn/VERSION_NATIVE_FB
Original file line number Diff line number Diff line change
@@ -1 +1 @@
19.0.0-native-fb-5fb67fa2-20240801
19.0.0-native-fb-7e8a06cf-20240815
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<fda434fa15a0692f5d5d9b1129466284>>
* @generated SignedSource<<709784b8044777eadcd1169a6cb4e85c>>
*/

"use strict";
Expand Down Expand Up @@ -3863,7 +3863,7 @@ __DEV__ &&
(currentlyRenderingFiber$1.updateQueue = updateQueue));
updateQueue.memoCache = memoCache;
updateQueue = memoCache.data[memoCache.index];
if (void 0 === updateQueue)
if (void 0 === updateQueue || ignorePreviousDependencies)
for (
updateQueue = memoCache.data[memoCache.index] = Array(size),
current = 0;
Expand Down Expand Up @@ -14925,11 +14925,11 @@ __DEV__ &&
(function () {
var internals = {
bundleType: 1,
version: "19.0.0-native-fb-5fb67fa2-20240801",
version: "19.0.0-native-fb-7e8a06cf-20240815",
rendererPackageName: "react-test-renderer",
currentDispatcherRef: ReactSharedInternals,
findFiberByHostInstance: getInstanceFromNode,
reconcilerVersion: "19.0.0-native-fb-5fb67fa2-20240801"
reconcilerVersion: "19.0.0-native-fb-7e8a06cf-20240815"
};
internals.overrideHookState = overrideHookState;
internals.overrideHookStateDeletePath = overrideHookStateDeletePath;
Expand Down Expand Up @@ -15074,5 +15074,5 @@ __DEV__ &&
flushSyncWorkAcrossRoots_impl(!0));
}
};
exports.version = "19.0.0-native-fb-5fb67fa2-20240801";
exports.version = "19.0.0-native-fb-7e8a06cf-20240815";
})();
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<3ef605a8a3bfd7b98e0fbc94b47f8826>>
* @generated SignedSource<<35e0b6f59493e93296e377a87335df79>>
*/

"use strict";
Expand Down Expand Up @@ -9311,14 +9311,14 @@ function wrapFiber(fiber) {
}
var internals$jscomp$inline_1206 = {
bundleType: 0,
version: "19.0.0-native-fb-5fb67fa2-20240801",
version: "19.0.0-native-fb-7e8a06cf-20240815",
rendererPackageName: "react-test-renderer",
currentDispatcherRef: ReactSharedInternals,
findFiberByHostInstance: function (mockNode) {
mockNode = nodeToInstanceMap.get(mockNode);
return void 0 !== mockNode ? mockNode.internalInstanceHandle : null;
},
reconcilerVersion: "19.0.0-native-fb-5fb67fa2-20240801"
reconcilerVersion: "19.0.0-native-fb-7e8a06cf-20240815"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1207 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down Expand Up @@ -9454,4 +9454,4 @@ exports.unstable_batchedUpdates = function (fn, a) {
flushSyncWorkAcrossRoots_impl(!0));
}
};
exports.version = "19.0.0-native-fb-5fb67fa2-20240801";
exports.version = "19.0.0-native-fb-7e8a06cf-20240815";
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<0085c47726e639d7465c75af71cebff4>>
* @generated SignedSource<<5f2ca724c7c6335f8cf5b28a36cf936b>>
*/

"use strict";
Expand Down Expand Up @@ -9924,14 +9924,14 @@ function wrapFiber(fiber) {
}
var internals$jscomp$inline_1115 = {
bundleType: 0,
version: "19.0.0-native-fb-5fb67fa2-20240801",
version: "19.0.0-native-fb-7e8a06cf-20240815",
rendererPackageName: "react-test-renderer",
currentDispatcherRef: ReactSharedInternals,
findFiberByHostInstance: function (mockNode) {
mockNode = nodeToInstanceMap.get(mockNode);
return void 0 !== mockNode ? mockNode.internalInstanceHandle : null;
},
reconcilerVersion: "19.0.0-native-fb-5fb67fa2-20240801",
reconcilerVersion: "19.0.0-native-fb-7e8a06cf-20240815",
getLaneLabelMap: function () {
for (
var map = new Map(), lane = 1, index$148 = 0;
Expand Down Expand Up @@ -10082,4 +10082,4 @@ exports.unstable_batchedUpdates = function (fn, a) {
flushSyncWorkAcrossRoots_impl(!0));
}
};
exports.version = "19.0.0-native-fb-5fb67fa2-20240801";
exports.version = "19.0.0-native-fb-7e8a06cf-20240815";
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<52cf17cbc5add4fd22d0fe54c8c9a8a6>>
* @generated SignedSource<<340eac70a970c418f335628535538be3>>
*/

"use strict";
Expand Down Expand Up @@ -1705,7 +1705,7 @@ __DEV__ &&
exports.useTransition = function () {
return resolveDispatcher().useTransition();
};
exports.version = "19.0.0-native-fb-5fb67fa2-20240801";
exports.version = "19.0.0-native-fb-7e8a06cf-20240815";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<f041831c8eef834a48a31ddb57f52e08>>
* @generated SignedSource<<f9c75d83123822d0402c69efbfb87dfe>>
*/

"use strict";
Expand Down Expand Up @@ -580,4 +580,4 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactSharedInternals.H.useTransition();
};
exports.version = "19.0.0-native-fb-5fb67fa2-20240801";
exports.version = "19.0.0-native-fb-7e8a06cf-20240815";
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<c28478d97dcaaac2fc95f2efeb6f9e01>>
* @generated SignedSource<<a84757798efc294e9c41e96a3f6dc537>>
*/

"use strict";
Expand Down Expand Up @@ -584,7 +584,7 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactSharedInternals.H.useTransition();
};
exports.version = "19.0.0-native-fb-5fb67fa2-20240801";
exports.version = "19.0.0-native-fb-7e8a06cf-20240815";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5fb67fa25c4ea8be046c6d9af41047f3cc379279
7e8a06cf4c628be45171da52c1a8e97f9869b7ee
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<3f990e5fd99baa100025988a07806f74>>
* @generated SignedSource<<72d78919ee72618db0d4a8cd8b3bfb26>>
*/

"use strict";
Expand Down Expand Up @@ -4765,7 +4765,7 @@ __DEV__ &&
(currentlyRenderingFiber$1.updateQueue = updateQueue));
updateQueue.memoCache = memoCache;
updateQueue = memoCache.data[memoCache.index];
if (void 0 === updateQueue)
if (void 0 === updateQueue || ignorePreviousDependencies)
for (
updateQueue = memoCache.data[memoCache.index] = Array(size),
current = 0;
Expand Down Expand Up @@ -16916,11 +16916,11 @@ __DEV__ &&
(function () {
var internals = {
bundleType: 1,
version: "19.0.0-native-fb-5fb67fa2-20240801",
version: "19.0.0-native-fb-7e8a06cf-20240815",
rendererPackageName: "react-native-renderer",
currentDispatcherRef: ReactSharedInternals,
findFiberByHostInstance: getInstanceFromNode,
reconcilerVersion: "19.0.0-native-fb-5fb67fa2-20240801"
reconcilerVersion: "19.0.0-native-fb-7e8a06cf-20240815"
};
null !== extraDevToolsConfig &&
(internals.rendererConfig = extraDevToolsConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<0d7285a9657bcb42e3fdbf39b4d4f69c>>
* @generated SignedSource<<9bb282155807973f9b66c87edc348406>>
*/

"use strict";
Expand Down Expand Up @@ -10816,11 +10816,11 @@ batchedUpdatesImpl = function (fn, a) {
var roots = new Map(),
internals$jscomp$inline_1144 = {
bundleType: 0,
version: "19.0.0-native-fb-5fb67fa2-20240801",
version: "19.0.0-native-fb-7e8a06cf-20240815",
rendererPackageName: "react-native-renderer",
currentDispatcherRef: ReactSharedInternals,
findFiberByHostInstance: getInstanceFromNode,
reconcilerVersion: "19.0.0-native-fb-5fb67fa2-20240801"
reconcilerVersion: "19.0.0-native-fb-7e8a06cf-20240815"
};
null !== extraDevToolsConfig &&
(internals$jscomp$inline_1144.rendererConfig = extraDevToolsConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<ac20c35f19f3379a2f08375288c04bdb>>
* @generated SignedSource<<552cec6ba214a5af386fd4fc2752f29f>>
*/

"use strict";
Expand Down Expand Up @@ -11519,11 +11519,11 @@ batchedUpdatesImpl = function (fn, a) {
var roots = new Map(),
internals$jscomp$inline_1226 = {
bundleType: 0,
version: "19.0.0-native-fb-5fb67fa2-20240801",
version: "19.0.0-native-fb-7e8a06cf-20240815",
rendererPackageName: "react-native-renderer",
currentDispatcherRef: ReactSharedInternals,
findFiberByHostInstance: getInstanceFromNode,
reconcilerVersion: "19.0.0-native-fb-5fb67fa2-20240801"
reconcilerVersion: "19.0.0-native-fb-7e8a06cf-20240815"
};
null !== extraDevToolsConfig &&
(internals$jscomp$inline_1226.rendererConfig = extraDevToolsConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<e7d2cd534c1bc73735e6e8624354984f>>
* @generated SignedSource<<f957ea4381c374ddc6829a72b97b9287>>
*/

"use strict";
Expand Down Expand Up @@ -4912,7 +4912,7 @@ __DEV__ &&
(currentlyRenderingFiber$1.updateQueue = updateQueue));
updateQueue.memoCache = memoCache;
updateQueue = memoCache.data[memoCache.index];
if (void 0 === updateQueue)
if (void 0 === updateQueue || ignorePreviousDependencies)
for (
updateQueue = memoCache.data[memoCache.index] = Array(size),
current = 0;
Expand Down Expand Up @@ -17067,11 +17067,11 @@ __DEV__ &&
shouldSuspendImpl = newShouldSuspendImpl;
};
var isomorphicReactPackageVersion = React.version;
if ("19.0.0-native-fb-5fb67fa2-20240801" !== isomorphicReactPackageVersion)
if ("19.0.0-native-fb-7e8a06cf-20240815" !== isomorphicReactPackageVersion)
throw Error(
'Incompatible React versions: The "react" and "react-native-renderer" packages must have the exact same version. Instead got:\n - react: ' +
(isomorphicReactPackageVersion +
"\n - react-native-renderer: 19.0.0-native-fb-5fb67fa2-20240801\nLearn more: https://react.dev/warnings/version-mismatch")
"\n - react-native-renderer: 19.0.0-native-fb-7e8a06cf-20240815\nLearn more: https://react.dev/warnings/version-mismatch")
);
if (
"function" !==
Expand All @@ -17097,11 +17097,11 @@ __DEV__ &&
(function () {
var internals = {
bundleType: 1,
version: "19.0.0-native-fb-5fb67fa2-20240801",
version: "19.0.0-native-fb-7e8a06cf-20240815",
rendererPackageName: "react-native-renderer",
currentDispatcherRef: ReactSharedInternals,
findFiberByHostInstance: getInstanceFromTag,
reconcilerVersion: "19.0.0-native-fb-5fb67fa2-20240801"
reconcilerVersion: "19.0.0-native-fb-7e8a06cf-20240815"
};
null !== extraDevToolsConfig &&
(internals.rendererConfig = extraDevToolsConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<1dff940faa025cb7c7941c4589882d0f>>
* @generated SignedSource<<41b429710fd5163112ce35bf5ab230ee>>
*/

"use strict";
Expand Down Expand Up @@ -10926,11 +10926,11 @@ function updateContainer(element, container, parentComponent, callback) {
return lane;
}
var isomorphicReactPackageVersion = React.version;
if ("19.0.0-native-fb-5fb67fa2-20240801" !== isomorphicReactPackageVersion)
if ("19.0.0-native-fb-7e8a06cf-20240815" !== isomorphicReactPackageVersion)
throw Error(
'Incompatible React versions: The "react" and "react-native-renderer" packages must have the exact same version. Instead got:\n - react: ' +
(isomorphicReactPackageVersion +
"\n - react-native-renderer: 19.0.0-native-fb-5fb67fa2-20240801\nLearn more: https://react.dev/warnings/version-mismatch")
"\n - react-native-renderer: 19.0.0-native-fb-7e8a06cf-20240815\nLearn more: https://react.dev/warnings/version-mismatch")
);
if (
"function" !==
Expand Down Expand Up @@ -10979,11 +10979,11 @@ batchedUpdatesImpl = function (fn, a) {
var roots = new Map(),
internals$jscomp$inline_1215 = {
bundleType: 0,
version: "19.0.0-native-fb-5fb67fa2-20240801",
version: "19.0.0-native-fb-7e8a06cf-20240815",
rendererPackageName: "react-native-renderer",
currentDispatcherRef: ReactSharedInternals,
findFiberByHostInstance: getInstanceFromTag,
reconcilerVersion: "19.0.0-native-fb-5fb67fa2-20240801"
reconcilerVersion: "19.0.0-native-fb-7e8a06cf-20240815"
};
null !== extraDevToolsConfig &&
(internals$jscomp$inline_1215.rendererConfig = extraDevToolsConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<a990d92e3fe10d8fad28e9ffe5368da5>>
* @generated SignedSource<<54211e54371961fffc4b3136d1d4d4cd>>
*/

"use strict";
Expand Down Expand Up @@ -11630,11 +11630,11 @@ function updateContainer(element, container, parentComponent, callback) {
return lane;
}
var isomorphicReactPackageVersion = React.version;
if ("19.0.0-native-fb-5fb67fa2-20240801" !== isomorphicReactPackageVersion)
if ("19.0.0-native-fb-7e8a06cf-20240815" !== isomorphicReactPackageVersion)
throw Error(
'Incompatible React versions: The "react" and "react-native-renderer" packages must have the exact same version. Instead got:\n - react: ' +
(isomorphicReactPackageVersion +
"\n - react-native-renderer: 19.0.0-native-fb-5fb67fa2-20240801\nLearn more: https://react.dev/warnings/version-mismatch")
"\n - react-native-renderer: 19.0.0-native-fb-7e8a06cf-20240815\nLearn more: https://react.dev/warnings/version-mismatch")
);
if (
"function" !==
Expand Down Expand Up @@ -11683,11 +11683,11 @@ batchedUpdatesImpl = function (fn, a) {
var roots = new Map(),
internals$jscomp$inline_1297 = {
bundleType: 0,
version: "19.0.0-native-fb-5fb67fa2-20240801",
version: "19.0.0-native-fb-7e8a06cf-20240815",
rendererPackageName: "react-native-renderer",
currentDispatcherRef: ReactSharedInternals,
findFiberByHostInstance: getInstanceFromTag,
reconcilerVersion: "19.0.0-native-fb-5fb67fa2-20240801"
reconcilerVersion: "19.0.0-native-fb-7e8a06cf-20240815"
};
null !== extraDevToolsConfig &&
(internals$jscomp$inline_1297.rendererConfig = extraDevToolsConfig);
Expand Down

0 comments on commit 220e25c

Please sign in to comment.