Skip to content

Commit

Permalink
Move useMemoCache hook to react/compiler-runtime (#28954)
Browse files Browse the repository at this point in the history
Move useMemoCache hook to react/compiler-runtime

For Meta-internal purposes, we keep the export on `react` itself to
reduce churn.

DiffTrain build for commit 4508873.
  • Loading branch information
kassens committed Apr 30, 2024
1 parent 47c2161 commit 10db98e
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<c8ae5566bf20474b49e1679f0416b8da>>
* @generated SignedSource<<fb3dc85c52a7e9e7080d8725ffa8dc96>>
*/

"use strict";
Expand Down Expand Up @@ -2954,24 +2954,26 @@ function updateMemo(nextCreate, deps) {
hook.memoizedState = [prevState, deps];
return prevState;
}
function updateDeferredValueImpl(hook, prevValue, value) {
function mountDeferredValueImpl(hook, value, initialValue) {
if (void 0 === initialValue || 0 !== (renderLanes & 1073741824))
return (hook.memoizedState = value);
hook.memoizedState = initialValue;
hook = requestDeferredLane();
currentlyRenderingFiber$1.lanes |= hook;
workInProgressRootSkippedLanes |= hook;
return initialValue;
}
function updateDeferredValueImpl(hook, prevValue, value, initialValue) {
if (objectIs(value, prevValue)) return value;
if (null !== currentTreeHiddenStackCursor.current)
return (
(hook.memoizedState = value),
objectIs(value, prevValue) || (didReceiveUpdate = !0),
value
(hook = mountDeferredValueImpl(hook, value, initialValue)),
objectIs(hook, prevValue) || (didReceiveUpdate = !0),
hook
);
if (0 === (renderLanes & 42))
return (didReceiveUpdate = !0), (hook.memoizedState = value);
0 === workInProgressDeferredLane &&
(workInProgressDeferredLane =
0 !== (workInProgressRootRenderLanes & 536870912)
? 536870912
: claimNextTransitionLane());
hook = suspenseHandlerStackCursor.current;
null !== hook && (hook.flags |= 32);
hook = workInProgressDeferredLane;
hook = requestDeferredLane();
currentlyRenderingFiber$1.lanes |= hook;
workInProgressRootSkippedLanes |= hook;
return prevValue;
Expand Down Expand Up @@ -3237,9 +3239,9 @@ var HooksDispatcherOnMount = {
return [initialState.memoizedState, dispatch];
},
useDebugValue: mountDebugValue,
useDeferredValue: function (value) {
mountWorkInProgressHook().memoizedState = value;
return value;
useDeferredValue: function (value, initialValue) {
var hook = mountWorkInProgressHook();
return mountDeferredValueImpl(hook, value, initialValue);
},
useTransition: function () {
var stateHook = mountStateImpl(!1);
Expand Down Expand Up @@ -3334,9 +3336,14 @@ var HooksDispatcherOnUpdate = {
return updateReducer(basicStateReducer);
},
useDebugValue: mountDebugValue,
useDeferredValue: function (value) {
useDeferredValue: function (value, initialValue) {
var hook = updateWorkInProgressHook();
return updateDeferredValueImpl(hook, currentHook.memoizedState, value);
return updateDeferredValueImpl(
hook,
currentHook.memoizedState,
value,
initialValue
);
},
useTransition: function () {
var booleanOrThenable = updateReducer(basicStateReducer)[0],
Expand Down Expand Up @@ -3376,11 +3383,16 @@ var HooksDispatcherOnRerender = {
return rerenderReducer(basicStateReducer);
},
useDebugValue: mountDebugValue,
useDeferredValue: function (value) {
useDeferredValue: function (value, initialValue) {
var hook = updateWorkInProgressHook();
return null === currentHook
? ((hook.memoizedState = value), value)
: updateDeferredValueImpl(hook, currentHook.memoizedState, value);
? mountDeferredValueImpl(hook, value, initialValue)
: updateDeferredValueImpl(
hook,
currentHook.memoizedState,
value,
initialValue
);
},
useTransition: function () {
var booleanOrThenable = rerenderReducer(basicStateReducer)[0],
Expand Down Expand Up @@ -7907,6 +7919,16 @@ function requestUpdateLane(fiber) {
fiber = 0 !== currentUpdatePriority ? currentUpdatePriority : 32;
return fiber;
}
function requestDeferredLane() {
0 === workInProgressDeferredLane &&
(workInProgressDeferredLane =
0 !== (workInProgressRootRenderLanes & 536870912)
? 536870912
: claimNextTransitionLane());
var suspenseHandler = suspenseHandlerStackCursor.current;
null !== suspenseHandler && (suspenseHandler.flags |= 32);
return workInProgressDeferredLane;
}
function scheduleUpdateOnFiber(root, fiber, lane) {
if (
(root === workInProgressRoot && 2 === workInProgressSuspendedReason) ||
Expand Down Expand Up @@ -9765,12 +9787,12 @@ function wrapFiber(fiber) {
fiberToWrapper.set(fiber, wrapper));
return wrapper;
}
var devToolsConfig$jscomp$inline_1119 = {
var devToolsConfig$jscomp$inline_1100 = {
findFiberByHostInstance: function () {
throw Error("TestRenderer does not support findFiberByHostInstance()");
},
bundleType: 0,
version: "19.0.0-beta-70d95fed",
version: "19.0.0-beta-24a83b92",
rendererPackageName: "react-test-renderer"
};
(function (internals) {
Expand All @@ -9787,10 +9809,10 @@ var devToolsConfig$jscomp$inline_1119 = {
} catch (err) {}
return hook.checkDCE ? !0 : !1;
})({
bundleType: devToolsConfig$jscomp$inline_1119.bundleType,
version: devToolsConfig$jscomp$inline_1119.version,
rendererPackageName: devToolsConfig$jscomp$inline_1119.rendererPackageName,
rendererConfig: devToolsConfig$jscomp$inline_1119.rendererConfig,
bundleType: devToolsConfig$jscomp$inline_1100.bundleType,
version: devToolsConfig$jscomp$inline_1100.version,
rendererPackageName: devToolsConfig$jscomp$inline_1100.rendererPackageName,
rendererConfig: devToolsConfig$jscomp$inline_1100.rendererConfig,
overrideHookState: null,
overrideHookStateDeletePath: null,
overrideHookStateRenamePath: null,
Expand All @@ -9807,14 +9829,14 @@ var devToolsConfig$jscomp$inline_1119 = {
return null === fiber ? null : fiber.stateNode;
},
findFiberByHostInstance:
devToolsConfig$jscomp$inline_1119.findFiberByHostInstance ||
devToolsConfig$jscomp$inline_1100.findFiberByHostInstance ||
emptyFindFiberByHostInstance,
findHostInstancesForRefresh: null,
scheduleRefresh: null,
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "19.0.0-beta-70d95fed"
reconcilerVersion: "19.0.0-beta-24a83b92"
});
exports._Scheduler = Scheduler;
exports.act = act;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<a487e3f84fa0dfc3fc634dfba8721564>>
* @generated SignedSource<<0f88cc3fda756e3467304abd247a3db7>>
*/

'use strict';
Expand All @@ -27,7 +27,7 @@ if (
}
var dynamicFlagsUntyped = require('ReactNativeInternalFeatureFlags');

var ReactVersion = '19.0.0-beta-77a60a06';
var ReactVersion = '19.0.0-beta-6a68f48e';

// Re-export dynamic flags from the internal module.
var dynamicFlags = dynamicFlagsUntyped; // We destructure each value before re-exporting to avoid a dynamic look-up on
Expand Down Expand Up @@ -3386,6 +3386,7 @@ exports.StrictMode = REACT_STRICT_MODE_TYPE;
exports.Suspense = REACT_SUSPENSE_TYPE;
exports.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE = ReactSharedInternals;
exports.act = act;
exports.c = useMemoCache;
exports.cache = cache;
exports.cloneElement = cloneElement;
exports.createContext = createContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<ef84d5399c3fc891896520103223dc8f>>
* @generated SignedSource<<bde59d9748423e65ff411acf53cbb3fe>>
*/

"use strict";
Expand Down Expand Up @@ -356,6 +356,9 @@ function lazyInitializer(payload) {
if (1 === payload._status) return payload._result.default;
throw payload._result;
}
function useMemoCache(size) {
return ReactSharedInternals.H.useMemoCache(size);
}
var reportGlobalError =
"function" === typeof reportError
? reportError
Expand Down Expand Up @@ -430,6 +433,7 @@ exports.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE =
exports.act = function () {
throw Error("act(...) is not supported in production builds of React.");
};
exports.c = useMemoCache;
exports.cache = function (fn) {
return function () {
return fn.apply(null, arguments);
Expand Down Expand Up @@ -596,9 +600,7 @@ exports.unstable_getCacheForType = function (resourceType) {
exports.unstable_useCacheRefresh = function () {
return ReactSharedInternals.H.useCacheRefresh();
};
exports.unstable_useMemoCache = function (size) {
return ReactSharedInternals.H.useMemoCache(size);
};
exports.unstable_useMemoCache = useMemoCache;
exports.use = function (usable) {
return ReactSharedInternals.H.use(usable);
};
Expand Down Expand Up @@ -665,4 +667,4 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactSharedInternals.H.useTransition();
};
exports.version = "19.0.0-beta-f9776c99";
exports.version = "19.0.0-beta-79fa2413";
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<32d5e348978f815554e5015b9471046b>>
* @generated SignedSource<<ce6c9a1ae9253d45b2c46eb5a4f66b63>>
*/

"use strict";
Expand Down Expand Up @@ -360,6 +360,9 @@ function lazyInitializer(payload) {
if (1 === payload._status) return payload._result.default;
throw payload._result;
}
function useMemoCache(size) {
return ReactSharedInternals.H.useMemoCache(size);
}
var reportGlobalError =
"function" === typeof reportError
? reportError
Expand Down Expand Up @@ -434,6 +437,7 @@ exports.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE =
exports.act = function () {
throw Error("act(...) is not supported in production builds of React.");
};
exports.c = useMemoCache;
exports.cache = function (fn) {
return function () {
return fn.apply(null, arguments);
Expand Down Expand Up @@ -600,9 +604,7 @@ exports.unstable_getCacheForType = function (resourceType) {
exports.unstable_useCacheRefresh = function () {
return ReactSharedInternals.H.useCacheRefresh();
};
exports.unstable_useMemoCache = function (size) {
return ReactSharedInternals.H.useMemoCache(size);
};
exports.unstable_useMemoCache = useMemoCache;
exports.use = function (usable) {
return ReactSharedInternals.H.use(usable);
};
Expand Down Expand Up @@ -669,7 +671,7 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactSharedInternals.H.useTransition();
};
exports.version = "19.0.0-beta-0c71ce9a";
exports.version = "19.0.0-beta-101cb521";
"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 @@
94eed63c49d989861ae7cd62e111de6d717f0a10
4508873393058e86bed308b56e49ec883ece59d1

0 comments on commit 10db98e

Please sign in to comment.