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 [a1ace9d](a1ace9d)
  • Loading branch information
gnoff committed Feb 7, 2024
1 parent 126187e commit a6a77a2
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 41 deletions.
2 changes: 1 addition & 1 deletion compiled/facebook-www/REVISION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
91caa96e4261704d42333f5e02ba32d870379fc4
a1ace9d3c2a0fc53703f11e30f32d0a009c5a8c9
39 changes: 19 additions & 20 deletions compiled/facebook-www/React-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ if (__DEV__) {
) {
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
}
var ReactVersion = "18.3.0-www-classic-87aadbfe";
var ReactVersion = "18.3.0-www-classic-8ed7454f";

// ATTENTION
// When adding new symbols to this file,
Expand Down Expand Up @@ -3061,26 +3061,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$1.current;
Expand Down
39 changes: 19 additions & 20 deletions compiled/facebook-www/React-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ if (__DEV__) {
) {
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
}
var ReactVersion = "18.3.0-www-modern-fe0a8b28";
var ReactVersion = "18.3.0-www-modern-be673a16";

// ATTENTION
// When adding new symbols to this file,
Expand Down Expand Up @@ -3026,26 +3026,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$1.current;
Expand Down

0 comments on commit a6a77a2

Please sign in to comment.