Make cache()'s server request scope more obvious#8310
Open
thomasboyt wants to merge 1 commit intoreactjs:mainfrom
Open
Make cache()'s server request scope more obvious#8310thomasboyt wants to merge 1 commit intoreactjs:mainfrom
thomasboyt wants to merge 1 commit intoreactjs:mainfrom
Conversation
Size changesDetails📦 Next.js Bundle Analysis for react-devThis analysis was generated by the Next.js Bundle Analysis action. 🤖 This PR introduced no changes to the JavaScript bundle! 🙌 |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I'm adopting Next's App Router in a new project, and was surprised by how non-obvious the documentation for
cache()is about how it works.As far as I'm aware - please correct me if I'm wrong on this, because it's rather important! -
cache()is a server-request-scoped cache. A cache is unique to a single server request and will not share values with other server requests being handled at the same time.This is important to its use in a framework like Next.js, where you might have a function like:
Even though
getCurrentUser()has no arguments passed in, it still should return the correct user for each request's current context, and not incorrectly share a user object between different server requests.As far as I'm concerned, this is the single most important aspect of
cache(), and I don't understand why this is buried under the caveats section. It's not a caveat; it is intentional, desired behavior! It is the key to how you use it!So in this PR I want to lift this detail up to the first sentence. I would also like to add a second sentence like:
Because currently, the motivation is buried down in "Usage." However, I think there's a preference to only have a single sentence in the "intro" of each docs page, so I held off - maybe it could be a separate paragraph above the TOC?