Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
dca6516c
Unverified
Commit
dca6516c
authored
Oct 23, 2024
by
JJ Kasper
Committed by
GitHub
Oct 23, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix fetch with no-store inside of use cache (#71754)
parent
82196b8e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
10 deletions
+41
-10
patch-fetch.ts
packages/next/src/server/lib/patch-fetch.ts
+14
-10
page.tsx
test/e2e/app-dir/use-cache/app/cache-fetch-no-store/page.tsx
+18
-0
use-cache.test.ts
test/e2e/app-dir/use-cache/use-cache.test.ts
+9
-0
No files found.
packages/next/src/server/lib/patch-fetch.ts
View file @
dca6516c
...
@@ -304,16 +304,20 @@ export function createPatchedFetcher(
...
@@ -304,16 +304,20 @@ export function createPatchedFetcher(
if
(
currentFetchCacheConfig
===
'force-cache'
)
{
if
(
currentFetchCacheConfig
===
'force-cache'
)
{
currentFetchRevalidate
=
false
currentFetchRevalidate
=
false
}
else
if
(
}
else
if
(
currentFetchCacheConfig
===
'no-cache'
||
// if we are inside of "use cache"/"unstable_cache"
currentFetchCacheConfig
===
'no-store'
||
// we shouldn't set the revalidate to 0 as it's overridden
pageFetchCacheMode
===
'force-no-store'
||
// by the cache context
pageFetchCacheMode
===
'only-no-store'
||
workUnitStore
?.
type
!==
'cache'
&&
// If no explicit fetch cache mode is set, but dynamic = `force-dynamic` is set,
(
currentFetchCacheConfig
===
'no-cache'
||
// we shouldn't consider caching the fetch. This is because the `dynamic` cache
currentFetchCacheConfig
===
'no-store'
||
// is considered a "top-level" cache mode, whereas something like `fetchCache` is more
pageFetchCacheMode
===
'force-no-store'
||
// fine-grained. Top-level modes are responsible for setting reasonable defaults for the
pageFetchCacheMode
===
'only-no-store'
||
// other configurations.
// If no explicit fetch cache mode is set, but dynamic = `force-dynamic` is set,
(
!
pageFetchCacheMode
&&
workStore
.
forceDynamic
)
// we shouldn't consider caching the fetch. This is because the `dynamic` cache
// is considered a "top-level" cache mode, whereas something like `fetchCache` is more
// fine-grained. Top-level modes are responsible for setting reasonable defaults for the
// other configurations.
(
!
pageFetchCacheMode
&&
workStore
.
forceDynamic
))
)
{
)
{
currentFetchRevalidate
=
0
currentFetchRevalidate
=
0
}
}
...
...
test/e2e/app-dir/use-cache/app/cache-fetch-no-store/page.tsx
0 → 100644
View file @
dca6516c
import
React
from
'react'
async
function
getData
()
{
'use cache'
return
fetch
(
'https://next-data-api-endpoint.vercel.app/api/random'
,
{
cache
:
'no-store'
,
}).
then
((
res
)
=>
res
.
text
())
}
export
default
async
function
Page
()
{
return
(
<>
<
p
>
index page
</
p
>
<
p
id=
"random"
>
{
await
getData
()
}
</
p
>
</>
)
}
test/e2e/app-dir/use-cache/use-cache.test.ts
View file @
dca6516c
...
@@ -266,4 +266,13 @@ describe('use-cache', () => {
...
@@ -266,4 +266,13 @@ describe('use-cache', () => {
// const time4 = await browser.waitForElementByCss('#t').text()
// const time4 = await browser.waitForElementByCss('#t').text()
// expect(time4).toBe(time3);
// expect(time4).toBe(time3);
})
})
it
(
'should override fetch with no-store in use cache properly'
,
async
()
=>
{
const
browser
=
await
next
.
browser
(
'/cache-fetch-no-store'
)
const
initialValue
=
await
browser
.
elementByCss
(
'#random'
).
text
()
await
browser
.
refresh
()
expect
(
await
browser
.
elementByCss
(
'#random'
).
text
()).
toBe
(
initialValue
)
})
})
})
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment