Skip to content

Commit a6a77a2

Browse files
committed
Improve flagging of React.cache to remove indirection in bundled code (#28263)
Uses a better technique for conditionally disabling cache on the client DiffTrain build for [a1ace9d](a1ace9d)
1 parent 126187e commit a6a77a2

File tree

3 files changed

+39
-41
lines changed

3 files changed

+39
-41
lines changed

compiled/facebook-www/REVISION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
91caa96e4261704d42333f5e02ba32d870379fc4
1+
a1ace9d3c2a0fc53703f11e30f32d0a009c5a8c9

compiled/facebook-www/React-dev.classic.js

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ if (__DEV__) {
2424
) {
2525
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
2626
}
27-
var ReactVersion = "18.3.0-www-classic-87aadbfe";
27+
var ReactVersion = "18.3.0-www-classic-8ed7454f";
2828

2929
// ATTENTION
3030
// When adding new symbols to this file,
@@ -3061,26 +3061,25 @@ if (__DEV__) {
30613061
return elementType;
30623062
}
30633063

3064-
function cache(fn) {
3065-
{
3066-
// On the client (i.e. not a Server Components environment) `cache` has
3067-
// no caching behavior. We just return the function as-is.
3068-
//
3069-
// We intend to implement client caching in a future major release. In the
3070-
// meantime, it's only exposed as an API so that Shared Components can use
3071-
// per-request caching on the server without breaking on the client. But it
3072-
// does mean they need to be aware of the behavioral difference.
3073-
//
3074-
// The rest of the behavior is the same as the server implementation — it
3075-
// returns a new reference, extra properties like `displayName` are not
3076-
// preserved, the length of the new function is 0, etc. That way apps can't
3077-
// accidentally depend on those details.
3078-
return function () {
3079-
// $FlowFixMe[incompatible-call]: We don't want to use rest arguments since we transpile the code.
3080-
return fn.apply(null, arguments);
3081-
};
3082-
}
3064+
function noopCache(fn) {
3065+
// On the client (i.e. not a Server Components environment) `cache` has
3066+
// no caching behavior. We just return the function as-is.
3067+
//
3068+
// We intend to implement client caching in a future major release. In the
3069+
// meantime, it's only exposed as an API so that Shared Components can use
3070+
// per-request caching on the server without breaking on the client. But it
3071+
// does mean they need to be aware of the behavioral difference.
3072+
//
3073+
// The rest of the behavior is the same as the server implementation — it
3074+
// returns a new reference, extra properties like `displayName` are not
3075+
// preserved, the length of the new function is 0, etc. That way apps can't
3076+
// accidentally depend on those details.
3077+
return function () {
3078+
// $FlowFixMe[incompatible-call]: We don't want to use rest arguments since we transpile the code.
3079+
return fn.apply(null, arguments);
3080+
};
30833081
}
3082+
var cache = noopCache;
30843083

30853084
function resolveDispatcher() {
30863085
var dispatcher = ReactCurrentDispatcher$1.current;

compiled/facebook-www/React-dev.modern.js

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ if (__DEV__) {
2424
) {
2525
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
2626
}
27-
var ReactVersion = "18.3.0-www-modern-fe0a8b28";
27+
var ReactVersion = "18.3.0-www-modern-be673a16";
2828

2929
// ATTENTION
3030
// When adding new symbols to this file,
@@ -3026,26 +3026,25 @@ if (__DEV__) {
30263026
return elementType;
30273027
}
30283028

3029-
function cache(fn) {
3030-
{
3031-
// On the client (i.e. not a Server Components environment) `cache` has
3032-
// no caching behavior. We just return the function as-is.
3033-
//
3034-
// We intend to implement client caching in a future major release. In the
3035-
// meantime, it's only exposed as an API so that Shared Components can use
3036-
// per-request caching on the server without breaking on the client. But it
3037-
// does mean they need to be aware of the behavioral difference.
3038-
//
3039-
// The rest of the behavior is the same as the server implementation — it
3040-
// returns a new reference, extra properties like `displayName` are not
3041-
// preserved, the length of the new function is 0, etc. That way apps can't
3042-
// accidentally depend on those details.
3043-
return function () {
3044-
// $FlowFixMe[incompatible-call]: We don't want to use rest arguments since we transpile the code.
3045-
return fn.apply(null, arguments);
3046-
};
3047-
}
3029+
function noopCache(fn) {
3030+
// On the client (i.e. not a Server Components environment) `cache` has
3031+
// no caching behavior. We just return the function as-is.
3032+
//
3033+
// We intend to implement client caching in a future major release. In the
3034+
// meantime, it's only exposed as an API so that Shared Components can use
3035+
// per-request caching on the server without breaking on the client. But it
3036+
// does mean they need to be aware of the behavioral difference.
3037+
//
3038+
// The rest of the behavior is the same as the server implementation — it
3039+
// returns a new reference, extra properties like `displayName` are not
3040+
// preserved, the length of the new function is 0, etc. That way apps can't
3041+
// accidentally depend on those details.
3042+
return function () {
3043+
// $FlowFixMe[incompatible-call]: We don't want to use rest arguments since we transpile the code.
3044+
return fn.apply(null, arguments);
3045+
};
30483046
}
3047+
var cache = noopCache;
30493048

30503049
function resolveDispatcher() {
30513050
var dispatcher = ReactCurrentDispatcher$1.current;

0 commit comments

Comments
 (0)