Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add error for renaming of unstable_revalidate #38070

Merged
merged 3 commits into from
Jun 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/next/server/api-utils/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,13 @@ export async function apiResolver(
}
) => revalidate(urlPath, opts || {}, req, apiContext)

// TODO: remove in next minor (current v12.2)
apiRes.unstable_revalidate = () => {
throw new Error(
`"unstable_revalidate" has been renamed to "revalidate" see more info here: https://nextjs.org/docs/basic-features/data-fetching/incremental-static-regeneration#on-demand-revalidation`
)
}

const resolver = interopDefault(resolverModule)
let wasPiped = false

Expand Down
5 changes: 5 additions & 0 deletions packages/next/shared/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,11 @@ export type NextApiResponse<T = any> = ServerResponse & {
) => NextApiResponse<T>
clearPreviewData: () => NextApiResponse<T>

/**
* @deprecated `unstable_revalidate` has been renamed to `revalidate`
*/
unstable_revalidate: () => void

revalidate: (
urlPath: string,
opts?: {
Expand Down
14 changes: 14 additions & 0 deletions test/e2e/prerender.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,20 @@ describe('Prerender', () => {
expect(value).toMatch(/Hi \[third\] \[fourth\]/)
})

if (!(global as any).isNextDeploy) {
it('should show error about renaming unstable_revalidate', async () => {
const res = await fetchViaHTTP(next.url, '/api/manual-revalidate', {
pathname: '/blog/first',
deprecated: '1',
})
expect(res.status).toBe(500)

expect(next.cliOutput).toContain(
'"unstable_revalidate" has been renamed to "revalidate"'
)
})
}

if ((global as any).isNextStart) {
// TODO: dev currently renders this page as blocking, meaning it shows the
// server error instead of continuously retrying. Do we want to change this?
Expand Down
3 changes: 3 additions & 0 deletions test/e2e/prerender/pages/api/manual-revalidate.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export default async function handler(req, res) {
if (req.query.deprecated) {
await res.unstable_revalidate(req.query.pathname)
}
// WARNING: don't use user input in production
// make sure to use trusted value for revalidating
let revalidated = false
Expand Down