Skip to content

Commit

Permalink
Improve flagging of React.cache to remove indirection in bundled co…
Browse files Browse the repository at this point in the history
…de (#28263)

Uses a better technique for conditionally disabling cache on the client

DiffTrain build for commit a1ace9d.
  • Loading branch information
gnoff committed Feb 7, 2024
1 parent fcad637 commit 363b626
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25725,7 +25725,7 @@ if (__DEV__) {
return root;
}

var ReactVersion = "18.3.0-canary-91caa96e4-20240206";
var ReactVersion = "18.3.0-canary-a1ace9d3c-20240206";

// Might add PROFILE later.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9157,7 +9157,7 @@ var devToolsConfig$jscomp$inline_1012 = {
throw Error("TestRenderer does not support findFiberByHostInstance()");
},
bundleType: 0,
version: "18.3.0-canary-91caa96e4-20240206",
version: "18.3.0-canary-a1ace9d3c-20240206",
rendererPackageName: "react-test-renderer"
};
var internals$jscomp$inline_1190 = {
Expand Down Expand Up @@ -9188,7 +9188,7 @@ var internals$jscomp$inline_1190 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-canary-91caa96e4-20240206"
reconcilerVersion: "18.3.0-canary-a1ace9d3c-20240206"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1191 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9585,7 +9585,7 @@ var devToolsConfig$jscomp$inline_1054 = {
throw Error("TestRenderer does not support findFiberByHostInstance()");
},
bundleType: 0,
version: "18.3.0-canary-91caa96e4-20240206",
version: "18.3.0-canary-a1ace9d3c-20240206",
rendererPackageName: "react-test-renderer"
};
var internals$jscomp$inline_1231 = {
Expand Down Expand Up @@ -9616,7 +9616,7 @@ var internals$jscomp$inline_1231 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-canary-91caa96e4-20240206"
reconcilerVersion: "18.3.0-canary-a1ace9d3c-20240206"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1232 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<41ebcac0959dc7c1f568b21dae3e2874>>
* @generated SignedSource<<e586d9c47ab7cba6a52560196c89aa09>>
*/

"use strict";
Expand All @@ -24,7 +24,7 @@ if (__DEV__) {
) {
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
}
var ReactVersion = "18.3.0-canary-91caa96e4-20240206";
var ReactVersion = "18.3.0-canary-a1ace9d3c-20240206";

// ATTENTION
// When adding new symbols to this file,
Expand Down Expand Up @@ -2735,26 +2735,25 @@ if (__DEV__) {
return elementType;
}

function cache(fn) {
{
// On the client (i.e. not a Server Components environment) `cache` has
// no caching behavior. We just 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. But it
// does mean they need to be aware of the behavioral difference.
//
// The rest of the behavior is the same as the server implementation — it
// returns a new reference, extra properties like `displayName` are not
// preserved, the length of the new function is 0, etc. That way apps can't
// accidentally depend on those details.
return function () {
// $FlowFixMe[incompatible-call]: We don't want to use rest arguments since we transpile the code.
return fn.apply(null, arguments);
};
}
function noopCache(fn) {
// On the client (i.e. not a Server Components environment) `cache` has
// no caching behavior. We just 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. But it
// does mean they need to be aware of the behavioral difference.
//
// The rest of the behavior is the same as the server implementation — it
// returns a new reference, extra properties like `displayName` are not
// preserved, the length of the new function is 0, etc. That way apps can't
// accidentally depend on those details.
return function () {
// $FlowFixMe[incompatible-call]: We don't want to use rest arguments since we transpile the code.
return fn.apply(null, arguments);
};
}
var cache = noopCache;

function resolveDispatcher() {
var dispatcher = ReactCurrentDispatcher.current;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -548,4 +548,4 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactCurrentDispatcher.current.useTransition();
};
exports.version = "18.3.0-canary-91caa96e4-20240206";
exports.version = "18.3.0-canary-a1ace9d3c-20240206";
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactCurrentDispatcher.current.useTransition();
};
exports.version = "18.3.0-canary-91caa96e4-20240206";
exports.version = "18.3.0-canary-a1ace9d3c-20240206";
"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 @@
91caa96e4261704d42333f5e02ba32d870379fc4
a1ace9d3c2a0fc53703f11e30f32d0a009c5a8c9

0 comments on commit 363b626

Please sign in to comment.