-
Notifications
You must be signed in to change notification settings - Fork 27k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix fetch caching inside of
"use cache"
Follow-up to #71754: > This ensures if you have a `fetch` with `cache: 'no-store'` inside of > `use cache`/`unstable_cache` we don't update the revalidate period to > `0` which effectively makes the `use cache` a no-op. This doesn't > change the behavior if `revalidate: 0` is defined on a `fetch` inside > of `use cache` as that is more explicitly changing the revalidate > period similar to `cacheLife()`. This PR follows this logic and ensures that we also cache fetches inside of `"use cache"` if `cache: 'no-store'` is not specified. It also adds a test to ensure that `revalidate: 0` inside of `"use cache"` is still considered.
- Loading branch information
1 parent
eabfdea
commit 6eaa67d
Showing
4 changed files
with
60 additions
and
2 deletions.
There are no files selected for viewing
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,18 @@ | ||
import React from 'react' | ||
|
||
async function getData() { | ||
'use cache' | ||
|
||
return fetch('https://next-data-api-endpoint.vercel.app/api/random').then( | ||
(res) => res.text() | ||
) | ||
} | ||
|
||
export default async function Page() { | ||
return ( | ||
<> | ||
<p>index page</p> | ||
<p id="random">{await getData()}</p> | ||
</> | ||
) | ||
} |
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,18 @@ | ||
import React from 'react' | ||
|
||
async function getData() { | ||
'use cache' | ||
|
||
return fetch('https://next-data-api-endpoint.vercel.app/api/random', { | ||
next: { revalidate: 0 }, | ||
}).then((res) => res.text()) | ||
} | ||
|
||
export default async function Page() { | ||
return ( | ||
<> | ||
<p>index page</p> | ||
<p id="random">{await getData()}</p> | ||
</> | ||
) | ||
} |
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