Skip to content

Commit

Permalink
Update fetch cache internal handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk committed Feb 28, 2023
1 parent 6b27604 commit 10edc8b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build_test_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ jobs:
node: [16]
group: [1, 2, 3, 4, 5, 6, 7, 8]
# run LTS matrix always and maintenance tests during a release
if: ${{ needs.build.outputs.isRelease == 'true' }}
# if: ${{ needs.build.outputs.isRelease == 'true' }}
steps:
- run: echo "${{needs.build.outputs.docsChange}}"

Expand Down Expand Up @@ -822,7 +822,7 @@ jobs:
testDevLTS,
testProdLTS,
testDevE2ELTS,
testprode2elts,
testProdE2ELTS,
]
steps:
- run: exit 0
Expand Down
11 changes: 6 additions & 5 deletions packages/next/src/server/lib/incremental-cache/fetch-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ export default class FetchCache implements CacheHandler {
{
method: 'GET',
headers: this.headers,
// @ts-expect-error
next: { internal: true },
}
},
// @ts-expect-error custom param
true
)

if (res.status === 404) {
Expand Down Expand Up @@ -166,9 +167,9 @@ export default class FetchCache implements CacheHandler {
method: 'POST',
headers: this.headers,
body: body,
// @ts-expect-error
next: { internal: true },
}
},
// @ts-expect-error custom param
true
)

if (!res.ok) {
Expand Down
9 changes: 7 additions & 2 deletions packages/next/src/server/lib/patch-fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ export function patchFetch({
{
kind: SpanKind.CLIENT,
},
async (input: RequestInfo | URL, init: RequestInit | undefined) => {
async (
input: RequestInfo | URL,
init: RequestInit | undefined,
// internal param to bypass cache handling
skipCache?: boolean
) => {
const staticGenerationStore = staticGenerationAsyncStorage.getStore()
const isRequestInput = input && typeof input === 'object'
const getRequestMeta = (field: string) => {
Expand All @@ -38,7 +43,7 @@ export function patchFetch({
// If the staticGenerationStore is not available, we can't do any
// special treatment of fetch, therefore fallback to the original
// fetch implementation.
if (!staticGenerationStore || (init?.next as any)?.internal) {
if (skipCache || !staticGenerationStore) {
return originFetch(input, init)
}

Expand Down

0 comments on commit 10edc8b

Please sign in to comment.