Unverified Commit 40cf3ce6 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Add error for renaming of unstable_revalidate (#38070)

* Add error for renaming of unstable_revalidate

* update test

* run test for dev too
parent e3fb62b6
...@@ -243,6 +243,13 @@ export async function apiResolver( ...@@ -243,6 +243,13 @@ export async function apiResolver(
} }
) => revalidate(urlPath, opts || {}, req, apiContext) ) => 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) const resolver = interopDefault(resolverModule)
let wasPiped = false let wasPiped = false
......
...@@ -256,6 +256,11 @@ export type NextApiResponse<T = any> = ServerResponse & { ...@@ -256,6 +256,11 @@ export type NextApiResponse<T = any> = ServerResponse & {
) => NextApiResponse<T> ) => NextApiResponse<T>
clearPreviewData: () => NextApiResponse<T> clearPreviewData: () => NextApiResponse<T>
/**
* @deprecated `unstable_revalidate` has been renamed to `revalidate`
*/
unstable_revalidate: () => void
revalidate: ( revalidate: (
urlPath: string, urlPath: string,
opts?: { opts?: {
......
...@@ -741,6 +741,20 @@ describe('Prerender', () => { ...@@ -741,6 +741,20 @@ describe('Prerender', () => {
expect(value).toMatch(/Hi \[third\] \[fourth\]/) 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) { if ((global as any).isNextStart) {
// TODO: dev currently renders this page as blocking, meaning it shows the // TODO: dev currently renders this page as blocking, meaning it shows the
// server error instead of continuously retrying. Do we want to change this? // server error instead of continuously retrying. Do we want to change this?
......
export default async function handler(req, res) { 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 // WARNING: don't use user input in production
// make sure to use trusted value for revalidating // make sure to use trusted value for revalidating
let revalidated = false let revalidated = false
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment