-
Notifications
You must be signed in to change notification settings - Fork 27.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix static to dynamic on revalidate (#46668)
Since it's perfectly valid to do an authorized request during revalidate we shouldn't consider this a reason to throw the static to dynamic error during runtime. If an authorized request is done during build and caching isn't enabled for a path it will still bail from being turned into a Prerender. x-ref: [slack thread](https://vercel.slack.com/archives/C03KAR5DCKC/p1677734108126679) ## Bug - [x] Related issues linked using `fixes #number` - [x] Integration tests added - [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)
- Loading branch information
Showing
7 changed files
with
94 additions
and
4 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
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
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
42 changes: 42 additions & 0 deletions
42
test/e2e/app-dir/app-static/app/gen-params-dynamic-revalidate/[slug]/page.js
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,42 @@ | ||
export const revalidate = 3 | ||
|
||
export async function generateStaticParams() { | ||
return [{ slug: 'one' }] | ||
} | ||
|
||
const fetchRetry = async (url, init) => { | ||
for (let i = 0; i < 5; i++) { | ||
try { | ||
return await fetch(url, init) | ||
} catch (err) { | ||
if (i === 4) { | ||
throw err | ||
} | ||
console.log(`Failed to fetch`, err, `retrying...`) | ||
} | ||
} | ||
} | ||
|
||
export default async function page({ params }) { | ||
const { slug } = params | ||
let data | ||
|
||
if (process.env.NEXT_PHASE !== 'phase-production-build') { | ||
data = await fetchRetry( | ||
'https://next-data-api-endpoint.vercel.app/api/random', | ||
{ | ||
headers: { | ||
Authorization: 'Bearer my-token', | ||
}, | ||
} | ||
).then((res) => res.text()) | ||
} | ||
|
||
return ( | ||
<> | ||
<p id="page">/gen-params-dynamic/[slug]</p> | ||
<p id="slug">{slug}</p> | ||
<p id="data">{data}</p> | ||
</> | ||
) | ||
} |