mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
This modifies the patched fetch implementation to better handle when called within an `unstable_cache` callback. In these callbacks, it should not throw an error related to dynamic access. This replaces the verbose `trackDynamicFetch` instead with `markCurrentScopeAsDynamic` which already has support for checking if inside an unstable cache context. It also has been adjusted to be a no-op when `export const dynamic = "force-static"`, further simplifying the code within the patch fetch implementation.
20 lines
395 B
JavaScript
20 lines
395 B
JavaScript
import { unstable_rethrow } from 'next/navigation'
|
|
|
|
const MAX_ATTEMPTS = 5
|
|
|
|
export const fetchRetry = async (url, init) => {
|
|
for (let i = 0; i < MAX_ATTEMPTS; i++) {
|
|
try {
|
|
return await fetch(url, init)
|
|
} catch (err) {
|
|
unstable_rethrow(err)
|
|
|
|
if (i === MAX_ATTEMPTS - 1) {
|
|
throw err
|
|
}
|
|
|
|
console.log(`Failed to fetch`, err, `retrying...`)
|
|
}
|
|
}
|
|
}
|