-
Notifications
You must be signed in to change notification settings - Fork 26.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs: Next.js 14 #57342
docs: Next.js 14 #57342
Conversation
Still need to add a reference for #57287, will do that shortly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left committable suggestions for ease. Some are questions so feel free to resolve if not adding them 👍🏻
docs/02-app/01-building-your-application/03-rendering/02-client-components.mdx
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are 3 questions raised when I'm reading this. It would be super helpful if the doc also addressed those.
- Does
unstable_cache
also handle deduplication, which is not the case for the current version of this API? - Is it supposed to be used OUTSIDE of a component, instead of inside as suggested in the previous version of the doc?
- If the answer to (3) is yes, then how should one specify tags that depend on the function arguments? e.g.
const getCachedUser = unstable_cache(
async (id) => getUser(id),
['user'],
{ tags: [`user-${id}`] } // ???
);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both current and previous docs, unstable_cache
can be used both inside and outside of the component. However, when calling the function returned from unstable_cache
it has to be inside.
Based on my current understanding, this is because the object that is used to access the cache IncrementalCache
only exists inside a serverless function such as Server Components and generateMetadata() which is why it will throw an error if called outside of the component.
I assume the example below is used so that one can export the function and use it somewhere else. This is, through my experience, done by wrapping unstable_cache with a function that receives any external data which can be passed to the keyParts and inside the callback function.
Example:
const getCachedUser = (slug) => unstable_cache(
async (slug) => getUser(slug),
['my-app-user'],
{ tags: [`user-${slug}`] }
)(slug);
export default async function Component({ userID }) {
const user = await getCachedUser(userID);
...
}
This has worked for me, last time i checked in 13.4.9
Co-authored-by: Rich Haines <hello@richardhaines.dev>
All broken links are now fixed, thank you! |
docs/02-app/02-api-reference/04-functions/generate-viewport.mdx
Outdated
Show resolved
Hide resolved
...2-app/01-building-your-application/02-data-fetching/01-fetching-caching-and-revalidating.mdx
Outdated
Show resolved
Hide resolved
…etching-caching-and-revalidating.mdx Co-authored-by: Amy Burns <amy.burns@vercel.com>
Co-authored-by: Michael Novotny <manovotny@gmail.com>
unstable_noStore
referenceunstable_cache
referencenext/og
import changesnext export
command removalviewport
andgenerateViewport
reference