forked from facebook/react
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove client caching from cache() API (facebook#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.
- Loading branch information
1 parent
65c10b7
commit 5ab7789
Showing
8 changed files
with
1,810 additions
and
1,712 deletions.
There are no files selected for viewing
1,841 changes: 153 additions & 1,688 deletions
1,841
packages/react-reconciler/src/__tests__/ReactCache-test.js
Large diffs are not rendered by default.
Oops, something went wrong.
1,597 changes: 1,597 additions & 0 deletions
1,597
packages/react-reconciler/src/__tests__/ReactCacheElement-test.js
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
export function cache<A: Iterable<mixed>, T>(fn: (...A) => T): (...A) => T { | ||
// 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); | ||
}; | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters