Unverified Commit dca5e223 authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Remove legacy checks for unstable_getXProps (#55813)

These methods have been landed for multiple years now, it's fine to remove the legacy checks for `unstable_`.
parent 6177f9f9
...@@ -1580,38 +1580,6 @@ export async function isPageStatic({ ...@@ -1580,38 +1580,6 @@ export async function isPageStatic({
const hasStaticProps = !!componentsResult.getStaticProps const hasStaticProps = !!componentsResult.getStaticProps
const hasStaticPaths = !!componentsResult.getStaticPaths const hasStaticPaths = !!componentsResult.getStaticPaths
const hasServerProps = !!componentsResult.getServerSideProps const hasServerProps = !!componentsResult.getServerSideProps
const hasLegacyServerProps = !!(await componentsResult.ComponentMod
.unstable_getServerProps)
const hasLegacyStaticProps = !!(await componentsResult.ComponentMod
.unstable_getStaticProps)
const hasLegacyStaticPaths = !!(await componentsResult.ComponentMod
.unstable_getStaticPaths)
const hasLegacyStaticParams = !!(await componentsResult.ComponentMod
.unstable_getStaticParams)
if (hasLegacyStaticParams) {
throw new Error(
`unstable_getStaticParams was replaced with getStaticPaths. Please update your code.`
)
}
if (hasLegacyStaticPaths) {
throw new Error(
`unstable_getStaticPaths was replaced with getStaticPaths. Please update your code.`
)
}
if (hasLegacyStaticProps) {
throw new Error(
`unstable_getStaticProps was replaced with getStaticProps. Please update your code.`
)
}
if (hasLegacyServerProps) {
throw new Error(
`unstable_getServerProps was replaced with getServerSideProps. Please update your code.`
)
}
// A page cannot be prerendered _and_ define a data requirement. That's // A page cannot be prerendered _and_ define a data requirement. That's
// contradictory! // contradictory!
......
export async function unstable_getStaticProps() {
return {
props: {},
}
}
export default () => 'hi'
/* eslint-env jest */
import fs from 'fs-extra'
import { join } from 'path'
import { nextBuild } from 'next-test-utils'
const appDir = join(__dirname, '..')
const indexPage = join(appDir, 'pages/index.js')
let origIndexPage = ''
const runTests = () => {
it('should error when legacy unstable_getStaticProps', async () => {
const { stderr, code } = await nextBuild(appDir, [], { stderr: true })
expect(code).toBe(1)
expect(stderr).toContain(
`unstable_getStaticProps was replaced with getStaticProps. Please update your code.`
)
})
it('should error when legacy unstable_getServerProps', async () => {
await fs.writeFile(
indexPage,
origIndexPage.replace('getStaticProps', 'getServerProps')
)
const { stderr, code } = await nextBuild(appDir, [], { stderr: true })
expect(code).toBe(1)
expect(stderr).toContain(
`unstable_getServerProps was replaced with getServerSideProps. Please update your code.`
)
})
it('should error when legacy unstable_getStaticPaths', async () => {
await fs.writeFile(
indexPage,
origIndexPage.replace('getStaticProps', 'getStaticPaths')
)
const { stderr, code } = await nextBuild(appDir, [], { stderr: true })
expect(code).toBe(1)
expect(stderr).toContain(
`unstable_getStaticPaths was replaced with getStaticPaths. Please update your code.`
)
})
}
describe('Mixed getStaticProps and getServerSideProps error', () => {
beforeAll(async () => {
origIndexPage = await fs.readFile(indexPage, 'utf8')
})
afterEach(() => fs.writeFile(indexPage, origIndexPage))
describe('server mode', () => {
runTests(false)
})
})
import React from 'react'
export async function unstable_getStaticParams() {
return ['/blog/post-1']
}
export async function getStaticProps({ params }) {
return {
props: {
post: params.post,
time: (await import('perf_hooks')).performance.now(),
},
}
}
export default () => {
return <div />
}
/* eslint-env jest */
import { join } from 'path'
import { nextBuild } from 'next-test-utils'
const appDir = join(__dirname, '..')
describe('Legacy Prerender', () => {
describe('handles old getStaticParams', () => {
it('should fail the build in server mode', async () => {
const out = await nextBuild(appDir, [], { stderr: true })
expect(out.stderr).toMatch(`Build error occurred`)
expect(out.stderr).toMatch(
'unstable_getStaticParams was replaced with getStaticPaths. Please update your code.'
)
})
})
})
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