Skip to content

Commit 8d091c6

Browse files
committed
Remove client caching from cache() API (#27977)
We haven't yet decided how we want `cache` to work on the client. The lifetime of the cache is more complex than on the server, where it only has to live as long as a single request. Since it's more important to ship this on the server, we're removing the existing behavior from the client for now. On the client (i.e. not a Server Components environment) `cache` will have not have any caching behavior. `cache(fn)` will return the function as-is. We intend to implement client caching in a future major release. In the meantime, it's only exposed as an API so that Shared Components can use per-request caching on the server without breaking on the client. DiffTrain build for commit 5c60736.
1 parent 845c10a commit 8d091c6

File tree

7 files changed

+28
-198
lines changed

7 files changed

+28
-198
lines changed

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react-test-renderer/cjs/ReactTestRenderer-dev.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -25540,7 +25540,7 @@ if (__DEV__) {
2554025540
return root;
2554125541
}
2554225542

25543-
var ReactVersion = "18.3.0-canary-f16344ea6-20240116";
25543+
var ReactVersion = "18.3.0-canary-5c607369c-20240116";
2554425544

2554525545
// Might add PROFILE later.
2554625546

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react-test-renderer/cjs/ReactTestRenderer-prod.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -9122,7 +9122,7 @@ var devToolsConfig$jscomp$inline_1037 = {
91229122
throw Error("TestRenderer does not support findFiberByHostInstance()");
91239123
},
91249124
bundleType: 0,
9125-
version: "18.3.0-canary-f16344ea6-20240116",
9125+
version: "18.3.0-canary-5c607369c-20240116",
91269126
rendererPackageName: "react-test-renderer"
91279127
};
91289128
var internals$jscomp$inline_1230 = {
@@ -9153,7 +9153,7 @@ var internals$jscomp$inline_1230 = {
91539153
scheduleRoot: null,
91549154
setRefreshHandler: null,
91559155
getCurrentFiber: null,
9156-
reconcilerVersion: "18.3.0-canary-f16344ea6-20240116"
9156+
reconcilerVersion: "18.3.0-canary-5c607369c-20240116"
91579157
};
91589158
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
91599159
var hook$jscomp$inline_1231 = __REACT_DEVTOOLS_GLOBAL_HOOK__;

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react-test-renderer/cjs/ReactTestRenderer-profiling.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -9550,7 +9550,7 @@ var devToolsConfig$jscomp$inline_1079 = {
95509550
throw Error("TestRenderer does not support findFiberByHostInstance()");
95519551
},
95529552
bundleType: 0,
9553-
version: "18.3.0-canary-f16344ea6-20240116",
9553+
version: "18.3.0-canary-5c607369c-20240116",
95549554
rendererPackageName: "react-test-renderer"
95559555
};
95569556
var internals$jscomp$inline_1271 = {
@@ -9581,7 +9581,7 @@ var internals$jscomp$inline_1271 = {
95819581
scheduleRoot: null,
95829582
setRefreshHandler: null,
95839583
getCurrentFiber: null,
9584-
reconcilerVersion: "18.3.0-canary-f16344ea6-20240116"
9584+
reconcilerVersion: "18.3.0-canary-5c607369c-20240116"
95859585
};
95869586
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
95879587
var hook$jscomp$inline_1272 = __REACT_DEVTOOLS_GLOBAL_HOOK__;

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-dev.js

+16-104
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<8f35d93e989a78a1f8613b9b55b0a715>>
10+
* @generated SignedSource<<807dd24b40aeb78f3b98550677a2f14f>>
1111
*/
1212

1313
"use strict";
@@ -24,7 +24,7 @@ if (__DEV__) {
2424
) {
2525
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
2626
}
27-
var ReactVersion = "18.3.0-canary-f16344ea6-20240116";
27+
var ReactVersion = "18.3.0-canary-5c607369c-20240116";
2828

2929
// ATTENTION
3030
// When adding new symbols to this file,
@@ -2452,110 +2452,22 @@ if (__DEV__) {
24522452
return elementType;
24532453
}
24542454

2455-
var UNTERMINATED = 0;
2456-
var TERMINATED = 1;
2457-
var ERRORED = 2;
2458-
2459-
function createCacheRoot() {
2460-
return new WeakMap();
2461-
}
2462-
2463-
function createCacheNode() {
2464-
return {
2465-
s: UNTERMINATED,
2466-
// status, represents whether the cached computation returned a value or threw an error
2467-
v: undefined,
2468-
// value, either the cached result or an error, depending on s
2469-
o: null,
2470-
// object cache, a WeakMap where non-primitive arguments are stored
2471-
p: null // primitive cache, a regular Map where primitive arguments are stored.
2472-
};
2473-
}
2474-
24752455
function cache(fn) {
2456+
// On the client (i.e. not a Server Components environment) `cache` has
2457+
// no caching behavior. We just return the function as-is.
2458+
//
2459+
// We intend to implement client caching in a future major release. In the
2460+
// meantime, it's only exposed as an API so that Shared Components can use
2461+
// per-request caching on the server without breaking on the client. But it
2462+
// does mean they need to be aware of the behavioral difference.
2463+
//
2464+
// The rest of the behavior is the same as the server implementation — it
2465+
// returns a new reference, extra properties like `displayName` are not
2466+
// preserved, the length of the new function is 0, etc. That way apps can't
2467+
// accidentally depend on those details.
24762468
return function () {
2477-
var dispatcher = ReactCurrentCache.current;
2478-
2479-
if (!dispatcher) {
2480-
// If there is no dispatcher, then we treat this as not being cached.
2481-
// $FlowFixMe[incompatible-call]: We don't want to use rest arguments since we transpile the code.
2482-
return fn.apply(null, arguments);
2483-
}
2484-
2485-
var fnMap = dispatcher.getCacheForType(createCacheRoot);
2486-
var fnNode = fnMap.get(fn);
2487-
var cacheNode;
2488-
2489-
if (fnNode === undefined) {
2490-
cacheNode = createCacheNode();
2491-
fnMap.set(fn, cacheNode);
2492-
} else {
2493-
cacheNode = fnNode;
2494-
}
2495-
2496-
for (var i = 0, l = arguments.length; i < l; i++) {
2497-
var arg = arguments[i];
2498-
2499-
if (
2500-
typeof arg === "function" ||
2501-
(typeof arg === "object" && arg !== null)
2502-
) {
2503-
// Objects go into a WeakMap
2504-
var objectCache = cacheNode.o;
2505-
2506-
if (objectCache === null) {
2507-
cacheNode.o = objectCache = new WeakMap();
2508-
}
2509-
2510-
var objectNode = objectCache.get(arg);
2511-
2512-
if (objectNode === undefined) {
2513-
cacheNode = createCacheNode();
2514-
objectCache.set(arg, cacheNode);
2515-
} else {
2516-
cacheNode = objectNode;
2517-
}
2518-
} else {
2519-
// Primitives go into a regular Map
2520-
var primitiveCache = cacheNode.p;
2521-
2522-
if (primitiveCache === null) {
2523-
cacheNode.p = primitiveCache = new Map();
2524-
}
2525-
2526-
var primitiveNode = primitiveCache.get(arg);
2527-
2528-
if (primitiveNode === undefined) {
2529-
cacheNode = createCacheNode();
2530-
primitiveCache.set(arg, cacheNode);
2531-
} else {
2532-
cacheNode = primitiveNode;
2533-
}
2534-
}
2535-
}
2536-
2537-
if (cacheNode.s === TERMINATED) {
2538-
return cacheNode.v;
2539-
}
2540-
2541-
if (cacheNode.s === ERRORED) {
2542-
throw cacheNode.v;
2543-
}
2544-
2545-
try {
2546-
// $FlowFixMe[incompatible-call]: We don't want to use rest arguments since we transpile the code.
2547-
var result = fn.apply(null, arguments);
2548-
var terminatedNode = cacheNode;
2549-
terminatedNode.s = TERMINATED;
2550-
terminatedNode.v = result;
2551-
return result;
2552-
} catch (error) {
2553-
// We store the first error that's thrown and rethrow it.
2554-
var erroredNode = cacheNode;
2555-
erroredNode.s = ERRORED;
2556-
erroredNode.v = error;
2557-
throw error;
2558-
}
2469+
// $FlowFixMe[incompatible-call]: We don't want to use rest arguments since we transpile the code.
2470+
return fn.apply(null, arguments);
25592471
};
25602472
}
25612473

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-prod.js

+3-44
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<e61b0483b88bb8d41bee65d1d3f6e785>>
10+
* @generated SignedSource<<c99939d6e36ef0328839a3f03a56e41f>>
1111
*/
1212

1313
"use strict";
@@ -278,12 +278,6 @@ function lazyInitializer(payload) {
278278
if (1 === payload._status) return payload._result.default;
279279
throw payload._result;
280280
}
281-
function createCacheRoot() {
282-
return new WeakMap();
283-
}
284-
function createCacheNode() {
285-
return { s: 0, v: void 0, o: null, p: null };
286-
}
287281
var ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner,
288282
RESERVED_PROPS = { key: !0, ref: !0, __self: !0, __source: !0 };
289283
function jsx$1(type, config, maybeKey) {
@@ -353,42 +347,7 @@ exports.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED =
353347
ReactSharedInternals;
354348
exports.cache = function (fn) {
355349
return function () {
356-
var dispatcher = ReactCurrentCache.current;
357-
if (!dispatcher) return fn.apply(null, arguments);
358-
var fnMap = dispatcher.getCacheForType(createCacheRoot);
359-
dispatcher = fnMap.get(fn);
360-
void 0 === dispatcher &&
361-
((dispatcher = createCacheNode()), fnMap.set(fn, dispatcher));
362-
fnMap = 0;
363-
for (var l = arguments.length; fnMap < l; fnMap++) {
364-
var arg = arguments[fnMap];
365-
if (
366-
"function" === typeof arg ||
367-
("object" === typeof arg && null !== arg)
368-
) {
369-
var objectCache = dispatcher.o;
370-
null === objectCache && (dispatcher.o = objectCache = new WeakMap());
371-
dispatcher = objectCache.get(arg);
372-
void 0 === dispatcher &&
373-
((dispatcher = createCacheNode()), objectCache.set(arg, dispatcher));
374-
} else
375-
(objectCache = dispatcher.p),
376-
null === objectCache && (dispatcher.p = objectCache = new Map()),
377-
(dispatcher = objectCache.get(arg)),
378-
void 0 === dispatcher &&
379-
((dispatcher = createCacheNode()),
380-
objectCache.set(arg, dispatcher));
381-
}
382-
if (1 === dispatcher.s) return dispatcher.v;
383-
if (2 === dispatcher.s) throw dispatcher.v;
384-
try {
385-
var result = fn.apply(null, arguments);
386-
fnMap = dispatcher;
387-
fnMap.s = 1;
388-
return (fnMap.v = result);
389-
} catch (error) {
390-
throw ((result = dispatcher), (result.s = 2), (result.v = error), error);
391-
}
350+
return fn.apply(null, arguments);
392351
};
393352
};
394353
exports.cloneElement = function (element, config, children) {
@@ -580,4 +539,4 @@ exports.useSyncExternalStore = function (
580539
exports.useTransition = function () {
581540
return ReactCurrentDispatcher.current.useTransition();
582541
};
583-
exports.version = "18.3.0-canary-f16344ea6-20240116";
542+
exports.version = "18.3.0-canary-5c607369c-20240116";

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-profiling.js

+3-44
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<e9bba84e09b058c7ba4cbba532a17a04>>
10+
* @generated SignedSource<<f970a167227dc5d72ad0fc9ab65f8518>>
1111
*/
1212

1313
"use strict";
@@ -249,12 +249,6 @@ function lazyInitializer(payload) {
249249
if (1 === payload._status) return payload._result.default;
250250
throw payload._result;
251251
}
252-
function createCacheRoot() {
253-
return new WeakMap();
254-
}
255-
function createCacheNode() {
256-
return { s: 0, v: void 0, o: null, p: null };
257-
}
258252
var ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner,
259253
RESERVED_PROPS = { key: !0, ref: !0, __self: !0, __source: !0 };
260254
function jsx$1(type, config, maybeKey) {
@@ -324,42 +318,7 @@ exports.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED =
324318
ReactSharedInternals;
325319
exports.cache = function (fn) {
326320
return function () {
327-
var dispatcher = ReactCurrentCache.current;
328-
if (!dispatcher) return fn.apply(null, arguments);
329-
var fnMap = dispatcher.getCacheForType(createCacheRoot);
330-
dispatcher = fnMap.get(fn);
331-
void 0 === dispatcher &&
332-
((dispatcher = createCacheNode()), fnMap.set(fn, dispatcher));
333-
fnMap = 0;
334-
for (var l = arguments.length; fnMap < l; fnMap++) {
335-
var arg = arguments[fnMap];
336-
if (
337-
"function" === typeof arg ||
338-
("object" === typeof arg && null !== arg)
339-
) {
340-
var objectCache = dispatcher.o;
341-
null === objectCache && (dispatcher.o = objectCache = new WeakMap());
342-
dispatcher = objectCache.get(arg);
343-
void 0 === dispatcher &&
344-
((dispatcher = createCacheNode()), objectCache.set(arg, dispatcher));
345-
} else
346-
(objectCache = dispatcher.p),
347-
null === objectCache && (dispatcher.p = objectCache = new Map()),
348-
(dispatcher = objectCache.get(arg)),
349-
void 0 === dispatcher &&
350-
((dispatcher = createCacheNode()),
351-
objectCache.set(arg, dispatcher));
352-
}
353-
if (1 === dispatcher.s) return dispatcher.v;
354-
if (2 === dispatcher.s) throw dispatcher.v;
355-
try {
356-
var result = fn.apply(null, arguments);
357-
fnMap = dispatcher;
358-
fnMap.s = 1;
359-
return (fnMap.v = result);
360-
} catch (error) {
361-
throw ((result = dispatcher), (result.s = 2), (result.v = error), error);
362-
}
321+
return fn.apply(null, arguments);
363322
};
364323
};
365324
exports.cloneElement = function (element, config, children) {
@@ -576,7 +535,7 @@ exports.useSyncExternalStore = function (
576535
exports.useTransition = function () {
577536
return ReactCurrentDispatcher.current.useTransition();
578537
};
579-
exports.version = "18.3.0-canary-f16344ea6-20240116";
538+
exports.version = "18.3.0-canary-5c607369c-20240116";
580539
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
581540
"function" ===
582541
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
f16344ea6db5bcc108de80dbc39a41ec28e8210d
1+
5c607369ceebe56d85175df84b7b6ad58dd25e1f

0 commit comments

Comments
 (0)