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 5cb0c69
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 27 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
5 changes: 2 additions & 3 deletions packages/next/src/server/lib/patch-fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ export function patchFetch({
serverHooks: typeof import('../../client/components/hooks-server-context')
staticGenerationAsyncStorage: StaticGenerationAsyncStorage
}) {
if ((globalThis.fetch as any).patched) return
if ((fetch as any).__nextPatched) return

const { DynamicServerError } = serverHooks

const originFetch = fetch

// @ts-expect-error - we're patching fetch
Expand Down Expand Up @@ -291,5 +290,5 @@ export function patchFetch({
return doOriginalFetch()
}
)
;(globalThis.fetch as any).patched = true
;(fetch as any).__nextPatched = true
}
1 change: 0 additions & 1 deletion test/e2e/app-dir/app-static/app-static.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,6 @@ createNextDescribe(
expect($2('#data-body1').text()).toBe(dataBody1)
expect($2('#data-body2').text()).toBe(dataBody2)
expect($2('#data-body3').text()).toBe(dataBody3)
expect($2('#data-body4').text()).toBe(dataBody4)
return 'success'
}, 'success')
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { FormData, Blob } from 'next/dist/compiled/@edge-runtime/primitives'

const fetchRetry = async (url, init) => {
for (let i = 0; i < 5; i++) {
try {
Expand Down Expand Up @@ -52,23 +50,7 @@ export default async function Page() {
}
).then((res) => res.text())

const formData = new FormData()
formData.append('hello', 'value')
formData.append('another', new Blob(['some text'], { type: 'text/plain' }))
formData.append('another', 'text')

const dataWithBody3 = await fetchRetry(
'https://next-data-api-endpoint.vercel.app/api/random',
{
method: 'POST',
body: formData,
next: {
revalidate: 10,
},
}
).then((res) => res.text())

const dataWithBody4 = await fetchRetry(
'https://next-data-api-endpoint.vercel.app/api/random',
{
method: 'POST',
Expand All @@ -79,7 +61,7 @@ export default async function Page() {
}
).then((res) => res.text())

const dataWithBody5 = await fetchRetry(
const dataWithBody4 = await fetchRetry(
'https://next-data-api-endpoint.vercel.app/api/random',
{
method: 'POST',
Expand All @@ -93,9 +75,8 @@ export default async function Page() {
<p id="page-data">{data}</p>
<p id="data-body1">{dataWithBody1}</p>
<p id="data-body2">{dataWithBody2}</p>
<p id="data-body3">{dataWithBody3}</p>
<p id="data-body4">{dataWithBody3}</p>
<p id="data-body4">{dataWithBody4}</p>
<p id="data-body5">{dataWithBody5}</p>
</>
)
}

0 comments on commit 5cb0c69

Please sign in to comment.