-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Docs for cacheSignal
#8023
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 for cacheSignal
#8023
Conversation
039174b
to
cea9190
Compare
cea9190
to
c832b32
Compare
Size changes📦 Next.js Bundle Analysis for react-devThis analysis was generated by the Next.js Bundle Analysis action. 🤖 One Page Changed SizeThe following page changed size from the code in this PR compared to its base branch:
DetailsOnly the gzipped size is provided here based on an expert tip. First Load is the size of the global bundle plus the bundle for the individual page. If a user were to show up to your website and land on a given page, the first load size represents the amount of javascript that user would need to download. If Any third party scripts you have added directly to your app using the Next to the size is how much the size has increased or decreased compared with the base branch of this PR. If this percentage has increased by 10% or more, there will be a red status indicator applied, indicating that special attention should be given to this. |
Co-authored-by: Sebastian Markbåge <sebastian@calyptus.eu>
Co-authored-by: Sebastian Markbåge <sebastian@calyptus.eu>
|
||
<Intro> | ||
|
||
`cacheSignal()` returns an [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) which aborts when the cache lifetime is done based on the same execution scope as a [`cache()`](/reference/react/cache)ed function |
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.
This needs to be explained simple enough to fit on one line in desktop. Something like:
`cacheSignal` allows you to know when a `cache()` is cleared.
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.
`cacheSignal()` returns an [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) which aborts when the cache lifetime is done based on the same execution scope as a [`cache()`](/reference/react/cache)ed function | |
`cacheSignal` allows you to know when the `cache()` life time is over. |
```js {3,7} | ||
import {cacheSignal} from 'react'; | ||
async function Component() { | ||
await fetch(url, { signal: cacheSignal() }); |
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.
This example doesn't make sense because you have no idea that the fetch here is using cache()
.
Can you use something like a DB example, like here?
https://react-do5kq6ru7-fbopensource.vercel.app/reference/react/cache#preload-data
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.
You don't need to know if the call is cached or not. Just that it may be cached by cache()
.
Preview: https://react-do5kq6ru7-fbopensource.vercel.app/reference/react/cacheSignal
Mostly taken from facebook/react#33557