Unverified Commit c9d9f113 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Remove `unstable_` prefix from new methods (#10723)

* Rename getServerProps to getServerSideProps

* Remove unstable_ prefix from new methods

* Add error when legacy methods are detected

* Add legacy methods for babel transform

* Add unstable_getServerSideProps also

* Apply suggestions from code review
Co-Authored-By: 's avatarJoe Haddad <joe.haddad@zeit.co>

* Update types import
Co-authored-by: 's avatarJoe Haddad <timer150@gmail.com>
parent 2789e7e0
# Invalid unstable_getStaticPaths Return Value
# Invalid getStaticPaths Return Value
#### Why This Error Occurred
In one of the page's `unstable_getStaticPaths` the return value had the incorrect shape.
In one of the page's `getStaticPaths` the return value had the incorrect shape.
#### Possible Ways to Fix It
Make sure to return the following shape from `unstable_getStaticPaths`:
Make sure to return the following shape from `getStaticPaths`:
```js
export async function unstable_getStaticPaths() {
export async function getStaticPaths() {
return {
paths: Array<string | { params: { [key: string]: string } }>,
fallback: boolean
......@@ -23,7 +23,7 @@ There are two required properties:
- You may return a [String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) or an [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) that explicitly defines all URL `params`.
```js
// pages/blog/[slug].js
export async function unstable_getStaticPaths() {
export async function getStaticPaths() {
return {
paths: [
// String variant:
......
# Invalid unstable_getStaticProps Return Value
# Invalid getStaticProps Return Value
#### Why This Error Occurred
In one of the page's `unstable_getStaticProps` the return value had the incorrect shape.
In one of the page's `getStaticProps` the return value had the incorrect shape.
#### Possible Ways to Fix It
Make sure to return the following shape from `unstable_getStaticProps`:
Make sure to return the following shape from `getStaticProps`:
```js
export async function unstable_getStaticProps() {
export async function getStaticProps() {
return {
props: { [key: string]: any }
}
......
......@@ -4,7 +4,7 @@ import Stories from '../components/stories'
import getStories from '../lib/get-stories'
// eslint-disable-next-line camelcase
export async function unstable_getStaticProps() {
export async function getStaticProps() {
const page = 1
const stories = await getStories('askstories', { page })
return { props: { page, stories } }
......
......@@ -4,7 +4,7 @@ import Stories from '../components/stories'
import getStories from '../lib/get-stories'
// eslint-disable-next-line camelcase
export async function unstable_getStaticProps() {
export async function getStaticProps() {
const page = 1
const stories = await getStories('topstories', { page })
return { props: { page, stories } }
......
......@@ -4,7 +4,7 @@ import Item from '../../components/item'
import getItem from '../../lib/get-item'
import getComments from '../../lib/get-comments'
export async function unstable_getStaticProps({ params }) {
export async function getStaticProps({ params }) {
const story = await getItem(params.id)
return { props: { story } }
}
......
......@@ -4,7 +4,7 @@ import Stories from '../components/stories'
import getStories from '../lib/get-stories'
// eslint-disable-next-line camelcase
export async function unstable_getStaticProps() {
export async function getStaticProps() {
const page = 1
const stories = await getStories('jobstories', { page })
return { props: { page, stories } }
......
......@@ -4,7 +4,7 @@ import Stories from '../components/stories'
import getStories from '../lib/get-stories'
// eslint-disable-next-line camelcase
export async function unstable_getStaticProps() {
export async function getStaticProps() {
const page = 1
const stories = await getStories('newstories', { page })
return { props: { page, stories } }
......
......@@ -4,7 +4,7 @@ import Stories from '../../components/stories'
import getStories from '../../lib/get-stories'
// eslint-disable-next-line camelcase
export async function unstable_getStaticProps({ params }) {
export async function getStaticProps({ params }) {
const page = Number(params.id)
const stories = await getStories('topstories', { page })
return { props: { page, stories } }
......
......@@ -4,7 +4,7 @@ import Stories from '../components/stories'
import getStories from '../lib/get-stories'
// eslint-disable-next-line camelcase
export async function unstable_getStaticProps() {
export async function getStaticProps() {
const page = 1
const stories = await getStories('showstories', { page })
return { props: { page, stories } }
......
......@@ -8,14 +8,21 @@ import {
const pageComponentVar = '__NEXT_COMP'
export const EXPORT_NAME_GET_STATIC_PROPS = 'unstable_getStaticProps'
export const EXPORT_NAME_GET_STATIC_PATHS = 'unstable_getStaticPaths'
export const EXPORT_NAME_GET_SERVER_PROPS = 'unstable_getServerSideProps'
export const EXPORT_NAME_GET_STATIC_PROPS = 'getStaticProps'
export const EXPORT_NAME_GET_STATIC_PATHS = 'getStaticPaths'
export const EXPORT_NAME_GET_SERVER_PROPS = 'getServerSideProps'
const ssgExports = new Set([
EXPORT_NAME_GET_STATIC_PROPS,
EXPORT_NAME_GET_STATIC_PATHS,
EXPORT_NAME_GET_SERVER_PROPS,
// legacy methods added so build doesn't fail from importing
// server-side only methods
`unstable_getStaticProps`,
`unstable_getStaticPaths`,
`unstable_getServerProps`,
`unstable_getServerSideProps`,
])
type PluginState = {
......
......@@ -779,7 +779,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
// For a dynamic SSG page, we did not copy its data exports and only
// copy the fallback HTML file (if present).
// We must also copy specific versions of this page as defined by
// `unstable_getStaticPaths` (additionalSsgPaths).
// `getStaticPaths` (additionalSsgPaths).
const extraRoutes = additionalSsgPaths.get(page) || []
for (const route of extraRoutes) {
await moveExportedPage(route, route, true, 'html')
......
......@@ -15,7 +15,7 @@ import { recursiveReadDir } from '../lib/recursive-readdir'
import { getRouteMatcher, getRouteRegex } from '../next-server/lib/router/utils'
import { isDynamicRoute } from '../next-server/lib/router/utils/is-dynamic'
import { findPageFile } from '../server/lib/find-page-file'
import { Unstable_getStaticPaths } from '../next-server/server/load-components'
import { GetStaticPaths } from 'next/types'
const fileGzipStats: { [k: string]: Promise<number> } = {}
const fsStatGzip = (file: string) => {
......@@ -500,7 +500,7 @@ export async function getPageSizeInKb(
export async function buildStaticPaths(
page: string,
unstable_getStaticPaths: Unstable_getStaticPaths
getStaticPaths: GetStaticPaths
): Promise<{ paths: string[]; fallback: boolean }> {
const prerenderPaths = new Set<string>()
const _routeRegex = getRouteRegex(page)
......@@ -509,7 +509,7 @@ export async function buildStaticPaths(
// Get the default list of allowed params.
const _validParamKeys = Object.keys(_routeMatcher(page))
const staticPathsResult = await unstable_getStaticPaths()
const staticPathsResult = await getStaticPaths()
const expectedReturnVal =
`Expected: { paths: [], fallback: boolean }\n` +
......@@ -521,7 +521,7 @@ export async function buildStaticPaths(
Array.isArray(staticPathsResult)
) {
throw new Error(
`Invalid value returned from unstable_getStaticPaths in ${page}. Received ${typeof staticPathsResult} ${expectedReturnVal}`
`Invalid value returned from getStaticPaths in ${page}. Received ${typeof staticPathsResult} ${expectedReturnVal}`
)
}
......@@ -531,7 +531,7 @@ export async function buildStaticPaths(
if (invalidStaticPathKeys.length > 0) {
throw new Error(
`Extra keys returned from unstable_getStaticPaths in ${page} (${invalidStaticPathKeys.join(
`Extra keys returned from getStaticPaths in ${page} (${invalidStaticPathKeys.join(
', '
)}) ${expectedReturnVal}`
)
......@@ -539,7 +539,7 @@ export async function buildStaticPaths(
if (typeof staticPathsResult.fallback !== 'boolean') {
throw new Error(
`The \`fallback\` key must be returned from unstable_getStaticPaths in ${page}.\n` +
`The \`fallback\` key must be returned from getStaticPaths in ${page}.\n` +
expectedReturnVal
)
}
......@@ -548,7 +548,7 @@ export async function buildStaticPaths(
if (!Array.isArray(toPrerender)) {
throw new Error(
`Invalid \`paths\` value returned from unstable_getStaticProps in ${page}.\n` +
`Invalid \`paths\` value returned from getStaticProps in ${page}.\n` +
`\`paths\` must be an array of strings or objects of shape { params: [key: string]: string }`
)
}
......@@ -572,7 +572,7 @@ export async function buildStaticPaths(
const invalidKeys = Object.keys(entry).filter(key => key !== 'params')
if (invalidKeys.length) {
throw new Error(
`Additional keys were returned from \`unstable_getStaticPaths\` in page "${page}". ` +
`Additional keys were returned from \`getStaticPaths\` in page "${page}". ` +
`URL Parameters intended for this dynamic route must be nested under the \`params\` key, i.e.:` +
`\n\n\treturn { params: { ${_validParamKeys
.map(k => `${k}: ...`)
......@@ -593,7 +593,7 @@ export async function buildStaticPaths(
throw new Error(
`A required parameter (${validParamKey}) was not provided as ${
repeat ? 'an array' : 'a string'
} in unstable_getStaticPaths for ${page}`
} in getStaticPaths for ${page}`
)
}
......@@ -634,14 +634,35 @@ export async function isPageStatic(
}
const hasGetInitialProps = !!(Comp as any).getInitialProps
const hasStaticProps = !!mod.unstable_getStaticProps
const hasStaticPaths = !!mod.unstable_getStaticPaths
const hasServerProps = !!mod.unstable_getServerSideProps
const hasStaticProps = !!mod.getStaticProps
const hasStaticPaths = !!mod.getStaticPaths
const hasServerProps = !!mod.getServerSideProps
const hasLegacyServerProps = !!mod.unstable_getServerProps
const hasLegacyStaticProps = !!mod.unstable_getStaticProps
const hasLegacyStaticPaths = !!mod.unstable_getStaticPaths
const hasLegacyStaticParams = !!mod.unstable_getStaticParams
if (hasLegacyStaticParams) {
throw new Error(
`unstable_getStaticParams was replaced with unstable_getStaticPaths. Please update your code.`
`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.`
)
}
......@@ -663,14 +684,14 @@ export async function isPageStatic(
// A page cannot have static parameters if it is not a dynamic page.
if (hasStaticProps && hasStaticPaths && !pageIsDynamic) {
throw new Error(
`unstable_getStaticPaths can only be used with dynamic pages, not '${page}'.` +
`getStaticPaths can only be used with dynamic pages, not '${page}'.` +
`\nLearn more: https://nextjs.org/docs#dynamic-routing`
)
}
if (hasStaticProps && pageIsDynamic && !hasStaticPaths) {
throw new Error(
`unstable_getStaticPaths is required for dynamic SSG pages and is missing for '${page}'.` +
`getStaticPaths is required for dynamic SSG pages and is missing for '${page}'.` +
`\nRead more: https://err.sh/next.js/invalid-getstaticpaths-value`
)
}
......@@ -681,7 +702,7 @@ export async function isPageStatic(
;({
paths: prerenderRoutes,
fallback: prerenderFallback,
} = await buildStaticPaths(page, mod.unstable_getStaticPaths))
} = await buildStaticPaths(page, mod.getStaticPaths))
}
const config = mod.config || {}
......
......@@ -217,10 +217,15 @@ const nextServerlessLoader: loader.Loader = function() {
const Component = ComponentInfo.default
export default Component
export const unstable_getStaticProps = ComponentInfo['unstable_getStaticProp' + 's']
export const unstable_getStaticParams = ComponentInfo['unstable_getStaticParam' + 's']
export const getStaticProps = ComponentInfo['getStaticProp' + 's']
export const getStaticPaths = ComponentInfo['getStaticPath' + 's']
export const getServerSideProps = ComponentInfo['getServerSideProp' + 's']
// kept for detecting legacy exports
export const unstable_getStaticProps = ComponentInfo['unstable_getStaticProp' + 's']
export const unstable_getStaticPaths = ComponentInfo['unstable_getStaticPath' + 's']
export const unstable_getServerSideProps = ComponentInfo['unstable_getServerSideProp' + 's']
export const unstable_getServerProps = ComponentInfo['unstable_getServerProp' + 's']
${dynamicRouteMatcher}
${handleRewrites}
......@@ -241,9 +246,9 @@ const nextServerlessLoader: loader.Loader = function() {
App,
Document,
buildManifest,
unstable_getStaticProps,
unstable_getServerSideProps,
unstable_getStaticPaths,
getStaticProps,
getServerSideProps,
getStaticPaths,
reactLoadableManifest,
canonicalBase: "${canonicalBase}",
buildId: "${buildId}",
......@@ -275,7 +280,7 @@ const nextServerlessLoader: loader.Loader = function() {
${page === '/_error' ? `res.statusCode = 404` : ''}
${
pageIsDynamicRoute
? `const params = fromExport && !unstable_getStaticProps && !unstable_getServerSideProps ? {} : dynamicRouteMatcher(parsedUrl.pathname) || {};`
? `const params = fromExport && !getStaticProps && !getServerSideProps ? {} : dynamicRouteMatcher(parsedUrl.pathname) || {};`
: `const params = {};`
}
${
......@@ -320,7 +325,7 @@ const nextServerlessLoader: loader.Loader = function() {
const previewData = tryGetPreviewData(req, res, options.previewProps)
const isPreviewMode = previewData !== false
let result = await renderToHTML(req, res, "${page}", Object.assign({}, unstable_getStaticProps ? {} : parsedUrl.query, nowParams ? nowParams : params, _params, isFallback ? { __nextFallback: 'true' } : {}), renderOpts)
let result = await renderToHTML(req, res, "${page}", Object.assign({}, getStaticProps ? {} : parsedUrl.query, nowParams ? nowParams : params, _params, isFallback ? { __nextFallback: 'true' } : {}), renderOpts)
if (_nextData && !fromExport) {
const payload = JSON.stringify(renderOpts.pageData)
......@@ -331,7 +336,7 @@ const nextServerlessLoader: loader.Loader = function() {
'Cache-Control',
isPreviewMode
? \`private, no-cache, no-store, max-age=0, must-revalidate\`
: unstable_getServerSideProps
: getServerSideProps
? \`no-cache, no-store, must-revalidate\`
: \`s-maxage=\${renderOpts.revalidate}, stale-while-revalidate\`
)
......@@ -350,9 +355,9 @@ const nextServerlessLoader: loader.Loader = function() {
if (err.code === 'ENOENT') {
res.statusCode = 404
const result = await renderToHTML(req, res, "/_error", parsedUrl.query, Object.assign({}, options, {
unstable_getStaticProps: undefined,
unstable_getStaticPaths: undefined,
unstable_getServerSideProps: undefined,
getStaticProps: undefined,
getStaticPaths: undefined,
getServerSideProps: undefined,
Component: Error
}))
return result
......@@ -360,9 +365,9 @@ const nextServerlessLoader: loader.Loader = function() {
console.error(err)
res.statusCode = 500
const result = await renderToHTML(req, res, "/_error", parsedUrl.query, Object.assign({}, options, {
unstable_getStaticProps: undefined,
unstable_getStaticPaths: undefined,
unstable_getServerSideProps: undefined,
getStaticProps: undefined,
getStaticPaths: undefined,
getServerSideProps: undefined,
Component: Error,
err
}))
......
......@@ -119,9 +119,9 @@ export default async function({
let renderMethod = renderToHTML
// eslint-disable-next-line camelcase
const renderedDuringBuild = unstable_getStaticProps => {
const renderedDuringBuild = getStaticProps => {
// eslint-disable-next-line camelcase
return !buildExport && unstable_getStaticProps && !isDynamicRoute(path)
return !buildExport && getStaticProps && !isDynamicRoute(path)
}
if (serverless) {
......@@ -147,9 +147,9 @@ export default async function({
} else {
// for non-dynamic SSG pages we should have already
// prerendered the file
if (renderedDuringBuild(mod.unstable_getStaticProps)) return results
if (renderedDuringBuild(mod.getStaticProps)) return results
if (mod.unstable_getStaticProps && !htmlFilepath.endsWith('.html')) {
if (mod.getStaticProps && !htmlFilepath.endsWith('.html')) {
// make sure it ends with .html if the name contains a dot
htmlFilename += '.html'
htmlFilepath += '.html'
......@@ -174,15 +174,12 @@ export default async function({
// for non-dynamic SSG pages we should have already
// prerendered the file
if (renderedDuringBuild(components.unstable_getStaticProps)) {
if (renderedDuringBuild(components.getStaticProps)) {
return results
}
// TODO: de-dupe the logic here between serverless and server mode
if (
components.unstable_getStaticProps &&
!htmlFilepath.endsWith('.html')
) {
if (components.getStaticProps && !htmlFilepath.endsWith('.html')) {
// make sure it ends with .html if the name contains a dot
htmlFilepath += '.html'
htmlFilename += '.html'
......
......@@ -24,10 +24,10 @@ export const DOT_NEXT_ALIAS = 'private-dot-next'
export const PUBLIC_DIR_MIDDLEWARE_CONFLICT = `You can not have a '_next' folder inside of your public folder. This conflicts with the internal '/_next' route. https://err.sh/zeit/next.js/public-next-folder-conflict`
export const SSG_GET_INITIAL_PROPS_CONFLICT = `You can not use getInitialProps with unstable_getStaticProps. To use SSG, please remove your getInitialProps`
export const SSG_GET_INITIAL_PROPS_CONFLICT = `You can not use getInitialProps with getStaticProps. To use SSG, please remove your getInitialProps`
export const SERVER_PROPS_GET_INIT_PROPS_CONFLICT = `You can not use getInitialProps with unstable_getServerSideProps. Please remove one or the other`
export const SERVER_PROPS_GET_INIT_PROPS_CONFLICT = `You can not use getInitialProps with getServerSideProps. Please remove getInitialProps.`
export const SERVER_PROPS_SSG_CONFLICT = `You can not use unstable_getStaticProps with unstable_getServerSideProps. To use SSG, please remove your unstable_getServerSideProps`
export const SERVER_PROPS_SSG_CONFLICT = `You can not use getStaticProps with getServerSideProps. To use SSG, please remove getServerSideProps`
export const PAGES_404_GET_INITIAL_PROPS_ERROR = `\`pages/404\` can not have getInitialProps/getServerSideProps, https://err.sh/zeit/next.js/404-get-initial-props`
import { IncomingMessage, ServerResponse } from 'http'
import { ParsedUrlQuery } from 'querystring'
import {
BUILD_MANIFEST,
CLIENT_STATIC_FILES_PATH,
......@@ -12,7 +10,13 @@ import { join } from 'path'
import { requirePage } from './require'
import { BuildManifest } from './get-page-files'
import { AppType, DocumentType } from '../lib/utils'
import { PageConfig, NextPageContext } from 'next/types'
import {
PageConfig,
NextPageContext,
GetStaticPaths,
GetServerSideProps,
GetStaticProps,
} from 'next/types'
export function interopDefault(mod: any) {
return mod.default || mod
......@@ -41,27 +45,6 @@ export type ManifestItem = {
type ReactLoadableManifest = { [moduleId: string]: ManifestItem[] }
type Unstable_getStaticProps = (ctx: {
params: ParsedUrlQuery | undefined
preview?: boolean
previewData?: any
}) => Promise<{
props: { [key: string]: any }
revalidate?: number | boolean
}>
export type Unstable_getStaticPaths = () => Promise<{
paths: Array<string | { params: ParsedUrlQuery }>
fallback: boolean
}>
type Unstable_getServerSideProps = (context: {
params: ParsedUrlQuery | undefined
req: IncomingMessage
res: ServerResponse
query: ParsedUrlQuery
}) => Promise<{ [key: string]: any }>
export type LoadComponentsReturnType = {
Component: React.ComponentType
pageConfig?: PageConfig
......@@ -70,9 +53,9 @@ export type LoadComponentsReturnType = {
Document: DocumentType
DocumentMiddleware?: (ctx: NextPageContext) => void
App: AppType
unstable_getStaticProps?: Unstable_getStaticProps
unstable_getStaticPaths?: Unstable_getStaticPaths
unstable_getServerSideProps?: Unstable_getServerSideProps
getStaticProps?: GetStaticProps
getStaticPaths?: GetStaticPaths
getServerSideProps?: GetServerSideProps
}
export async function loadComponents(
......@@ -83,24 +66,16 @@ export async function loadComponents(
): Promise<LoadComponentsReturnType> {
if (serverless) {
const Component = await requirePage(pathname, distDir, serverless)
const {
unstable_getStaticProps,
unstable_getStaticPaths,
unstable_getServerSideProps,
} = Component
const { getStaticProps, getStaticPaths, getServerSideProps } = Component
addComponentPropsId(
Component,
unstable_getStaticProps,
unstable_getServerSideProps
)
addComponentPropsId(Component, getStaticProps, getServerSideProps)
return {
Component,
pageConfig: Component.config || {},
unstable_getStaticProps,
unstable_getStaticPaths,
unstable_getServerSideProps,
getStaticProps,
getStaticPaths,
getServerSideProps,
} as LoadComponentsReturnType
}
const documentPath = join(
......@@ -141,17 +116,9 @@ export async function loadComponents(
interopDefault(AppMod),
])
const {
unstable_getServerSideProps,
unstable_getStaticProps,
unstable_getStaticPaths,
} = ComponentMod
const { getServerSideProps, getStaticProps, getStaticPaths } = ComponentMod
addComponentPropsId(
Component,
unstable_getStaticProps,
unstable_getServerSideProps
)
addComponentPropsId(Component, getStaticProps, getServerSideProps)
return {
App,
......@@ -161,8 +128,8 @@ export async function loadComponents(
DocumentMiddleware,
reactLoadableManifest,
pageConfig: ComponentMod.config || {},
unstable_getServerSideProps,
unstable_getStaticProps,
unstable_getStaticPaths,
getServerSideProps,
getStaticProps,
getStaticPaths,
}
}
......@@ -810,7 +810,7 @@ export default class Server {
return {
components,
query: {
...(components.unstable_getStaticProps
...(components.getStaticProps
? { _nextDataReq: query._nextDataReq }
: query),
...(params || {}),
......@@ -888,9 +888,9 @@ export default class Server {
const isLikeServerless =
typeof components.Component === 'object' &&
typeof (components.Component as any).renderReqToHTML === 'function'
const isSSG = !!components.unstable_getStaticProps
const isServerProps = !!components.unstable_getServerSideProps
const hasStaticPaths = !!components.unstable_getStaticPaths
const isSSG = !!components.getStaticProps
const isServerProps = !!components.getServerSideProps
const hasStaticPaths = !!components.getStaticPaths
// Toggle whether or not this is a Data request
const isDataReq = query._nextDataReq
......
......@@ -273,9 +273,9 @@ export async function renderToHTML(
buildManifest,
reactLoadableManifest,
ErrorDebug,
unstable_getStaticProps,
unstable_getStaticPaths,
unstable_getServerSideProps,
getStaticProps,
getStaticPaths,
getServerSideProps,
isDataReq,
params,
previewProps,
......@@ -311,7 +311,7 @@ export async function renderToHTML(
const isFallback = !!query.__nextFallback
delete query.__nextFallback
const isSpr = !!unstable_getStaticProps
const isSpr = !!getStaticProps
const defaultAppGetInitialProps =
App.getInitialProps === (App as any).origGetInitialProps
......@@ -323,7 +323,7 @@ export async function renderToHTML(
!hasPageGetInitialProps &&
defaultAppGetInitialProps &&
!isSpr &&
!unstable_getServerSideProps
!getServerSideProps
if (
process.env.NODE_ENV !== 'production' &&
......@@ -349,23 +349,23 @@ export async function renderToHTML(
throw new Error(SSG_GET_INITIAL_PROPS_CONFLICT + ` ${pathname}`)
}
if (hasPageGetInitialProps && unstable_getServerSideProps) {
if (hasPageGetInitialProps && getServerSideProps) {
throw new Error(SERVER_PROPS_GET_INIT_PROPS_CONFLICT + ` ${pathname}`)
}
if (unstable_getServerSideProps && isSpr) {
if (getServerSideProps && isSpr) {
throw new Error(SERVER_PROPS_SSG_CONFLICT + ` ${pathname}`)
}
if (!!unstable_getStaticPaths && !isSpr) {
if (!!getStaticPaths && !isSpr) {
throw new Error(
`unstable_getStaticPaths was added without a unstable_getStaticProps in ${pathname}. Without unstable_getStaticProps, unstable_getStaticPaths does nothing`
`getStaticPaths was added without a getStaticProps in ${pathname}. Without getStaticProps, getStaticPaths does nothing`
)
}
if (isSpr && pageIsDynamic && !unstable_getStaticPaths) {
if (isSpr && pageIsDynamic && !getStaticPaths) {
throw new Error(
`unstable_getStaticPaths is required for dynamic SSG pages and is missing for '${pathname}'.` +
`getStaticPaths is required for dynamic SSG pages and is missing for '${pathname}'.` +
`\nRead more: https://err.sh/next.js/invalid-getstaticpaths-value`
)
}
......@@ -467,7 +467,7 @@ export async function renderToHTML(
// instantly. There's no need to pass this data down from a previous
// invoke, where we'd have to consider server & serverless.
const previewData = tryGetPreviewData(req, res, previewProps)
const data = await unstable_getStaticProps!({
const data = await getStaticProps!({
...(pageIsDynamic
? {
params: query as ParsedUrlQuery,
......@@ -529,8 +529,8 @@ export async function renderToHTML(
console.error(err)
}
if (unstable_getServerSideProps && !isFallback) {
const data = await unstable_getServerSideProps({
if (getServerSideProps && !isFallback) {
const data = await getServerSideProps({
params,
query,
req,
......@@ -549,7 +549,7 @@ export async function renderToHTML(
if (
!isSpr && // we only show this warning for legacy pages
!unstable_getServerSideProps &&
!getServerSideProps &&
process.env.NODE_ENV !== 'production' &&
Object.keys(props?.pageProps || {}).includes('url')
) {
......
......@@ -28,13 +28,13 @@ export async function loadStaticPaths(
serverless
)
if (!components.unstable_getStaticPaths) {
if (!components.getStaticPaths) {
// we shouldn't get to this point since the worker should
// only be called for SSG pages with getStaticPaths
throw new Error(
`Invariant: failed to load page with unstable_getStaticPaths for ${pathname}`
`Invariant: failed to load page with getStaticPaths for ${pathname}`
)
}
return buildStaticPaths(pathname, components.unstable_getStaticPaths)
return buildStaticPaths(pathname, components.getStaticPaths)
}
......@@ -3,6 +3,8 @@
/// <reference types="react-dom" />
import React from 'react'
import { ParsedUrlQuery } from 'querystring'
import { IncomingMessage, ServerResponse } from 'http'
import {
NextPageContext,
......@@ -62,4 +64,25 @@ export {
NextApiHandler,
}
export type GetStaticProps = (ctx: {
params: ParsedUrlQuery | undefined
preview?: boolean
previewData?: any
}) => Promise<{
props: { [key: string]: any }
revalidate?: number | boolean
}>
export type GetStaticPaths = () => Promise<{
paths: Array<string | { params: ParsedUrlQuery }>
fallback: boolean
}>
export type GetServerSideProps = (context: {
params: ParsedUrlQuery | undefined
req: IncomingMessage
res: ServerResponse
query: ParsedUrlQuery
}) => Promise<{ [key: string]: any }>
export default next
export async function unstable_getStaticPaths() {
export async function getStaticPaths() {
return { paths: ['/hello', '/world'], fallback: true }
}
......
......@@ -14,7 +14,7 @@ jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 1
const appDir = join(__dirname, '../')
const nextConfig = join(appDir, 'next.config.js')
const errorRegex = /unstable_getStaticPaths was added without a unstable_getStaticProps in/
const errorRegex = /getStaticPaths was added without a getStaticProps in/
describe('Catches Missing getStaticProps', () => {
afterAll(() => fs.remove(nextConfig))
......
......@@ -2,11 +2,11 @@ function All({ params }) {
return <div id="all-ssg-content">{JSON.stringify(params)}</div>
}
export function unstable_getStaticProps({ params }) {
export function getStaticProps({ params }) {
return { props: { params } }
}
export function unstable_getStaticPaths() {
export function getStaticPaths() {
return {
paths: [],
fallback: true,
......
......@@ -8,11 +8,11 @@ function All({ params }) {
)
}
export function unstable_getStaticProps({ params }) {
export function getStaticProps({ params }) {
return { props: { params } }
}
export function unstable_getStaticPaths() {
export function getStaticPaths() {
return {
paths: [],
fallback: true,
......
......@@ -2,11 +2,11 @@ function All({ params }) {
return <div id="all-ssg-content">{JSON.stringify(params)}</div>
}
export function unstable_getStaticProps({ params }) {
export function getStaticProps({ params }) {
return { props: { params } }
}
export function unstable_getStaticPaths() {
export function getStaticPaths() {
return {
paths: [
`/p1/p2/predefined-ssg/one-level`,
......
......@@ -3,7 +3,7 @@ import fs from 'fs'
import findUp from 'find-up'
// eslint-disable-next-line camelcase
export async function unstable_getServerSideProps() {
export async function getServerSideProps() {
const text = fs
.readFileSync(
findUp.sync('world.txt', {
......
......@@ -2,7 +2,7 @@ import React from 'react'
import Link from 'next/link'
// eslint-disable-next-line camelcase
export async function unstable_getServerSideProps({ query }) {
export async function getServerSideProps({ query }) {
return {
props: {
post: query.post,
......
......@@ -3,7 +3,7 @@ import Link from 'next/link'
import { useRouter } from 'next/router'
// eslint-disable-next-line camelcase
export async function unstable_getServerSideProps({ params }) {
export async function getServerSideProps({ params }) {
if (params.post === 'post-10') {
await new Promise(resolve => {
setTimeout(() => resolve(), 1000)
......
......@@ -2,7 +2,7 @@ import React from 'react'
import Link from 'next/link'
// eslint-disable-next-line camelcase
export async function unstable_getServerSideProps() {
export async function getServerSideProps() {
return {
props: {
slugs: ['post-1', 'post-2'],
......
......@@ -3,7 +3,7 @@ import Link from 'next/link'
import { useRouter } from 'next/router'
// eslint-disable-next-line camelcase
export async function unstable_getServerSideProps({ params }) {
export async function getServerSideProps({ params }) {
return {
props: {
world: 'world',
......
import Link from 'next/link'
// eslint-disable-next-line camelcase
export async function unstable_getServerSideProps() {
export async function getServerSideProps() {
return {
props: {
world: 'world',
......
import Link from 'next/link'
// eslint-disable-next-line camelcase
export async function unstable_getServerSideProps() {
export async function getServerSideProps() {
return {
props: {
world: 'world',
......
......@@ -3,7 +3,7 @@ import Link from 'next/link'
import { useRouter } from 'next/router'
// eslint-disable-next-line camelcase
export async function unstable_getServerSideProps({ params, query }) {
export async function getServerSideProps({ params, query }) {
return {
world: 'world',
query: query || {},
......
......@@ -3,7 +3,7 @@ import Link from 'next/link'
import { useRouter } from 'next/router'
// eslint-disable-next-line camelcase
export async function unstable_getServerSideProps({ params, query }) {
export async function getServerSideProps({ params, query }) {
return {
props: {
world: 'world',
......
......@@ -2,7 +2,7 @@ import React from 'react'
import Link from 'next/link'
// eslint-disable-next-line camelcase
export async function unstable_getServerSideProps({ query }) {
export async function getServerSideProps({ query }) {
return {
props: {
user: query.user,
......
......@@ -337,7 +337,7 @@ const runTests = (dev = false) => {
await fs.writeFile(
urlPropPage,
`
export async function unstable_getServerSideProps() {
export async function getServerSideProps() {
return {
props: {
url: 'something'
......@@ -396,7 +396,7 @@ const runTests = (dev = false) => {
}
}
describe('unstable_getServerSideProps', () => {
describe('getServerSideProps', () => {
describe('dev mode', () => {
beforeAll(async () => {
stderr = ''
......
export async function unstable_getStaticProps() {
return {
props: {},
}
}
export default () => 'hi'
/* eslint-env jest */
/* global jasmine */
import fs from 'fs-extra'
import { join } from 'path'
import { nextBuild } from 'next-test-utils'
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 1
const appDir = join(__dirname, '..')
const indexPage = join(appDir, 'pages/index.js')
let origIndexPage = ''
const runTests = (serverless = false) => {
if (serverless) {
const nextConfig = join(appDir, 'next.config.js')
beforeEach(() =>
fs.writeFile(
nextConfig,
`
module.exports = {
target: 'experimental-serverless-trace'
}
`
)
)
afterAll(() => fs.remove(nextConfig))
}
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_getServerProps', 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)
})
describe('serverless mode', () => {
runTests(true)
})
})
export const unstable_getStaticProps = async () => {
export const getStaticProps = async () => {
return {
props: { world: 'world' },
}
}
export const unstable_getServerSideProps = async () => {
export const getServerSideProps = async () => {
return {
props: { world: 'world' },
}
......
export const unstable_getStaticPaths = async () => {
export const getStaticPaths = async () => {
return {
props: { world: 'world' }, fallback: true
}
}
export const unstable_getServerSideProps = async () => {
export const getServerSideProps = async () => {
return {
props: { world: 'world' }
}
......
import React from 'react'
// eslint-disable-next-line camelcase
export async function unstable_getStaticPaths() {
export async function getStaticPaths() {
return { paths: [{ params: { slug: 'hello' } }], fallback: true }
}
// eslint-disable-next-line camelcase
export async function unstable_getStaticProps({ params }) {
export async function getStaticProps({ params }) {
return {
props: {
post: params.post,
......
......@@ -11,7 +11,7 @@ describe('Invalid Prerender Catchall Params', () => {
const out = await nextBuild(appDir, [], { stderr: true })
expect(out.stderr).toMatch(`Build error occurred`)
expect(out.stderr).toMatch(
'A required parameter (slug) was not provided as an array in unstable_getStaticPaths for /[...slug]'
'A required parameter (slug) was not provided as an array in getStaticPaths for /[...slug]'
)
})
})
import React from 'react'
// eslint-disable-next-line camelcase
export async function unstable_getStaticPaths() {
export async function getStaticPaths() {
return { paths: [{ foo: 'bad', baz: 'herro' }], fallback: true }
}
// eslint-disable-next-line camelcase
export async function unstable_getStaticProps({ params }) {
export async function getStaticProps({ params }) {
return {
props: {
post: params.post,
......
......@@ -6,7 +6,7 @@ export async function unstable_getStaticParams() {
}
// eslint-disable-next-line camelcase
export async function unstable_getStaticProps({ params }) {
export async function getStaticProps({ params }) {
return {
props: {
post: params.post,
......
......@@ -14,7 +14,7 @@ describe('Legacy Prerender', () => {
const out = await nextBuild(appDir, [], { stderr: true })
expect(out.stderr).toMatch(`Build error occurred`)
expect(out.stderr).toMatch(
'unstable_getStaticParams was replaced with unstable_getStaticPaths. Please update your code.'
'unstable_getStaticParams was replaced with getStaticPaths. Please update your code.'
)
})
......@@ -27,7 +27,7 @@ describe('Legacy Prerender', () => {
await fs.remove(nextConfig)
expect(out.stderr).toMatch(`Build error occurred`)
expect(out.stderr).toMatch(
'unstable_getStaticParams was replaced with unstable_getStaticPaths. Please update your code.'
'unstable_getStaticParams was replaced with getStaticPaths. Please update your code.'
)
})
})
......
export function unstable_getStaticProps({ preview, previewData }) {
export function getStaticProps({ preview, previewData }) {
return { props: { hasProps: true, preview, previewData } }
}
......
......@@ -3,7 +3,7 @@ import fs from 'fs'
import findUp from 'find-up'
// eslint-disable-next-line camelcase
export async function unstable_getStaticProps() {
export async function getStaticProps() {
const text = fs
.readFileSync(
findUp.sync('world.txt', {
......
......@@ -2,7 +2,7 @@ import React from 'react'
import Link from 'next/link'
// eslint-disable-next-line camelcase
export async function unstable_getStaticPaths() {
export async function getStaticPaths() {
return {
paths: [
'/blog/post-1/comment-1',
......@@ -13,7 +13,7 @@ export async function unstable_getStaticPaths() {
}
// eslint-disable-next-line camelcase
export async function unstable_getStaticProps({ params }) {
export async function getStaticProps({ params }) {
return {
props: {
post: params.post,
......
......@@ -3,7 +3,7 @@ import Link from 'next/link'
import { useRouter } from 'next/router'
// eslint-disable-next-line camelcase
export async function unstable_getStaticPaths() {
export async function getStaticPaths() {
return {
paths: [
'/blog/post-1',
......@@ -20,7 +20,7 @@ export async function unstable_getStaticPaths() {
let counter = 0
// eslint-disable-next-line camelcase
export async function unstable_getStaticProps({ params }) {
export async function getStaticProps({ params }) {
if (params.post === 'post-10') {
await new Promise(resolve => {
setTimeout(() => resolve(), 1000)
......
......@@ -2,7 +2,7 @@ import React from 'react'
import Link from 'next/link'
// eslint-disable-next-line camelcase
export async function unstable_getStaticProps() {
export async function getStaticProps() {
return {
props: {
slugs: ['post-1', 'post-2'],
......
export async function unstable_getStaticProps({ params: { slug } }) {
export async function getStaticProps({ params: { slug } }) {
if (slug[0] === 'delayby3s') {
await new Promise(resolve => setTimeout(resolve, 3000))
}
......@@ -11,7 +11,7 @@ export async function unstable_getStaticProps({ params: { slug } }) {
}
}
export async function unstable_getStaticPaths() {
export async function getStaticPaths() {
return {
paths: [
{ params: { slug: ['first'] } },
......
import { useRouter } from 'next/router'
export async function unstable_getStaticProps({ params: { slug } }) {
export async function getStaticProps({ params: { slug } }) {
if (slug[0] === 'delayby3s') {
await new Promise(resolve => setTimeout(resolve, 3000))
}
......@@ -13,7 +13,7 @@ export async function unstable_getStaticProps({ params: { slug } }) {
}
}
export async function unstable_getStaticPaths() {
export async function getStaticPaths() {
return {
paths: [
{ params: { slug: ['first'] } },
......
import Link from 'next/link'
// eslint-disable-next-line camelcase
export async function unstable_getStaticProps() {
export async function getStaticProps() {
return {
props: {
world: 'world',
......
import Link from 'next/link'
// eslint-disable-next-line camelcase
export async function unstable_getStaticProps() {
export async function getStaticProps() {
// throw new Error('oops from getStaticProps')
return {
props: { world: 'world', time: new Date().getTime() },
......
......@@ -3,7 +3,7 @@ import Link from 'next/link'
import { useRouter } from 'next/router'
// eslint-disable-next-line camelcase
export async function unstable_getStaticProps({ params }) {
export async function getStaticProps({ params }) {
return {
props: {
world: 'world',
......
......@@ -2,12 +2,12 @@ import React from 'react'
import Link from 'next/link'
// eslint-disable-next-line camelcase
export async function unstable_getStaticPaths() {
export async function getStaticPaths() {
return { paths: [], fallback: true }
}
// eslint-disable-next-line camelcase
export async function unstable_getStaticProps({ params }) {
export async function getStaticProps({ params }) {
return {
props: {
user: params.user,
......
......@@ -496,7 +496,7 @@ const runTests = (dev = false, looseMode = false) => {
await fs.writeFile(
urlPropPage,
`
export async function unstable_getStaticProps() {
export async function getStaticProps() {
return {
props: {
url: 'something'
......@@ -603,7 +603,7 @@ const runTests = (dev = false, looseMode = false) => {
await fs.writeFile(
curPage,
`
export async function unstable_getStaticProps() {
export async function getStaticProps() {
return {
props: {
hello: 'world'
......@@ -617,7 +617,7 @@ const runTests = (dev = false, looseMode = false) => {
try {
const html = await renderViaHTTP(appPort, '/temp/hello')
expect(html).toMatch(
/unstable_getStaticPaths is required for dynamic SSG pages and is missing for/
/getStaticPaths is required for dynamic SSG pages and is missing for/
)
} finally {
await fs.remove(curPage)
......@@ -630,12 +630,12 @@ const runTests = (dev = false, looseMode = false) => {
await fs.writeFile(
curPage,
`
export async function unstable_getStaticPaths() {
export async function getStaticPaths() {
return {
paths: []
}
}
export async function unstable_getStaticProps() {
export async function getStaticProps() {
return {
props: {
hello: 'world'
......@@ -1013,7 +1013,7 @@ describe('SSG Prerender', () => {
await fs.writeFile(
brokenPage,
`
export async function unstable_getStaticProps() {
export async function getStaticProps() {
return {
hello: 'world'
}
......@@ -1028,7 +1028,7 @@ describe('SSG Prerender', () => {
'Additional keys were returned from `getStaticProps`'
)
expect(stderr).not.toContain(
'You can not use getInitialProps with unstable_getStaticProps'
'You can not use getInitialProps with getStaticProps'
)
})
})
......
......@@ -32,8 +32,8 @@ describe('babel plugin (next-ssg-transform)', () => {
describe('getStaticProps support', () => {
it('should remove separate named export specifiers', () => {
const output = babel(trim`
export { unstable_getStaticPaths } from '.'
export { a as unstable_getStaticProps } from '.'
export { getStaticPaths } from '.'
export { a as getStaticProps } from '.'
export default function Test() {
return <div />
......@@ -46,7 +46,7 @@ describe('babel plugin (next-ssg-transform)', () => {
it('should remove combined named export specifiers', () => {
const output = babel(trim`
export { unstable_getStaticPaths, a as unstable_getStaticProps } from '.'
export { getStaticPaths, a as getStaticProps } from '.'
export default function Test() {
return <div />
......@@ -59,7 +59,7 @@ describe('babel plugin (next-ssg-transform)', () => {
it('should retain extra named export specifiers', () => {
const output = babel(trim`
export { unstable_getStaticPaths, a as unstable_getStaticProps, foo, bar as baz } from '.'
export { getStaticPaths, a as getStaticProps, foo, bar as baz } from '.'
export default function Test() {
return <div />
......@@ -72,11 +72,11 @@ describe('babel plugin (next-ssg-transform)', () => {
it('should remove named export function declarations', () => {
const output = babel(trim`
export function unstable_getStaticPaths() {
export function getStaticPaths() {
return []
}
export function unstable_getStaticProps() {
export function getStaticProps() {
return { props: {} }
}
......@@ -92,11 +92,11 @@ describe('babel plugin (next-ssg-transform)', () => {
it('should remove named export function declarations (async)', () => {
const output = babel(trim`
export async function unstable_getStaticPaths() {
export async function getStaticPaths() {
return []
}
export async function unstable_getStaticProps() {
export async function getStaticProps() {
return { props: {} }
}
......@@ -112,7 +112,7 @@ describe('babel plugin (next-ssg-transform)', () => {
it('should not remove extra named export function declarations', () => {
const output = babel(trim`
export function unstable_getStaticProps() {
export function getStaticProps() {
return { props: {} }
}
......@@ -130,11 +130,11 @@ describe('babel plugin (next-ssg-transform)', () => {
it('should remove named export variable declarations', () => {
const output = babel(trim`
export const unstable_getStaticPaths = () => {
export const getStaticPaths = () => {
return []
}
export const unstable_getStaticProps = function() {
export const getStaticProps = function() {
return { props: {} }
}
......@@ -150,11 +150,11 @@ describe('babel plugin (next-ssg-transform)', () => {
it('should remove named export variable declarations (async)', () => {
const output = babel(trim`
export const unstable_getStaticPaths = async () => {
export const getStaticPaths = async () => {
return []
}
export const unstable_getStaticProps = async function() {
export const getStaticProps = async function() {
return { props: {} }
}
......@@ -170,11 +170,11 @@ describe('babel plugin (next-ssg-transform)', () => {
it('should not remove extra named export variable declarations', () => {
const output = babel(trim`
export const unstable_getStaticPaths = () => {
export const getStaticPaths = () => {
return []
}, foo = 2
export const unstable_getStaticProps = function() {
export const getStaticProps = function() {
return { props: {} }
}
......@@ -190,11 +190,11 @@ describe('babel plugin (next-ssg-transform)', () => {
it('should remove re-exported variable declarations', () => {
const output = babel(trim`
const unstable_getStaticPaths = () => {
const getStaticPaths = () => {
return []
}
export { unstable_getStaticPaths }
export { getStaticPaths }
export default function Test() {
return <div />
......@@ -208,11 +208,11 @@ describe('babel plugin (next-ssg-transform)', () => {
it('should remove re-exported variable declarations (safe)', () => {
const output = babel(trim`
const unstable_getStaticPaths = () => {
const getStaticPaths = () => {
return []
}, a = 2
export { unstable_getStaticPaths }
export { getStaticPaths }
export default function Test() {
return <div />
......@@ -226,11 +226,11 @@ describe('babel plugin (next-ssg-transform)', () => {
it('should remove re-exported function declarations', () => {
const output = babel(trim`
function unstable_getStaticPaths() {
function getStaticPaths() {
return []
}
export { unstable_getStaticPaths }
export { getStaticPaths }
export default function Test() {
return <div />
......@@ -244,11 +244,11 @@ describe('babel plugin (next-ssg-transform)', () => {
it('should not crash for class declarations', () => {
const output = babel(trim`
function unstable_getStaticPaths() {
function getStaticPaths() {
return []
}
export { unstable_getStaticPaths }
export { getStaticPaths }
export class MyClass {}
......@@ -288,7 +288,7 @@ describe('babel plugin (next-ssg-transform)', () => {
const b2 = function apples() {};
const bla = () => {inception1};
function unstable_getStaticProps() {
function getStaticProps() {
abc();
drop_me;
b;
......@@ -297,7 +297,7 @@ describe('babel plugin (next-ssg-transform)', () => {
return { props: {var1} }
}
export { unstable_getStaticProps }
export { getStaticProps }
export default function Test() {
return <div />
......@@ -324,7 +324,7 @@ describe('babel plugin (next-ssg-transform)', () => {
return { bug };
}
export { unstable_getStaticProps } from 'a'
export { getStaticProps } from 'a'
`)
expect(output).toMatchInlineSnapshot(
......@@ -334,7 +334,7 @@ describe('babel plugin (next-ssg-transform)', () => {
it('should support class exports', () => {
const output = babel(trim`
export function unstable_getStaticProps() {
export function getStaticProps() {
return { props: {} }
}
......@@ -352,7 +352,7 @@ describe('babel plugin (next-ssg-transform)', () => {
it('should support class exports 2', () => {
const output = babel(trim`
export function unstable_getStaticProps() {
export function getStaticProps() {
return { props: {} }
}
......@@ -372,7 +372,7 @@ describe('babel plugin (next-ssg-transform)', () => {
it('should support export { _ as default }', () => {
const output = babel(trim`
export function unstable_getStaticProps() {
export function getStaticProps() {
return { props: {} }
}
......@@ -390,7 +390,7 @@ describe('babel plugin (next-ssg-transform)', () => {
it('should support export { _ as default } with other specifiers', () => {
const output = babel(trim`
export function unstable_getStaticProps() {
export function getStaticProps() {
return { props: {} }
}
......@@ -410,7 +410,7 @@ describe('babel plugin (next-ssg-transform)', () => {
it('should support export { _ as default } with a class', () => {
const output = babel(trim`
export function unstable_getStaticProps() {
export function getStaticProps() {
return { props: {} }
}
......
......@@ -255,7 +255,7 @@ describe('next-babel-loader', () => {
`import{c,d}from"e";` +
`import{e as ee,f as ff}from"f";` +
`` +
`export function unstable_getStaticProps() {foo;bar;baz;cats;baz2;ff; return { props: {} } }`,
`export function getStaticProps() {foo;bar;baz;cats;baz2;ff; return { props: {} } }`,
{ resourcePath: pageFile }
)
expect(code).toMatchInlineSnapshot(
......@@ -276,12 +276,12 @@ describe('next-babel-loader', () => {
`import{c,d}from"e";` +
`import{e as ee,f as ff}from"f";` +
`` +
`export function unstable_getStaticProps() {foo();baz2();ff();ooo(); return { props: {} }}` +
`export function getStaticProps() {foo();baz2();ff();ooo(); return { props: {} }}` +
`export default function () { return bar(); }`,
{ resourcePath: pageFile, isServer: true }
)
expect(code).toMatchInlineSnapshot(
`"import\\"core-js\\";import{foo,bar}from\\"a\\";import baz from\\"b\\";import ooo from\\"ooo\\";import*as React from\\"react\\";import baz2,{yeet}from\\"c\\";import baz3,{cats}from\\"d\\";import{c,d}from\\"e\\";import{e as ee,f as ff}from\\"f\\";export function unstable_getStaticProps(){foo();baz2();ff();ooo();return{props:{}};}export default function(){return bar();}"`
`"import\\"core-js\\";import{foo,bar}from\\"a\\";import baz from\\"b\\";import ooo from\\"ooo\\";import*as React from\\"react\\";import baz2,{yeet}from\\"c\\";import baz3,{cats}from\\"d\\";import{c,d}from\\"e\\";import{e as ee,f as ff}from\\"f\\";export function getStaticProps(){foo();baz2();ff();ooo();return{props:{}};}export default function(){return bar();}"`
)
})
......@@ -298,7 +298,7 @@ describe('next-babel-loader', () => {
`import{c,d}from"e";` +
`import{e as ee,f as ff}from"f";` +
`` +
`export function unstable_getStaticProps() {foo();baz2();ff();ooo();cats; return { props: {} }}` +
`export function getStaticProps() {foo();baz2();ff();ooo();cats; return { props: {} }}` +
`export default function () { return cats + bar(); }`,
{ resourcePath: pageFile, isServer: false }
)
......@@ -320,7 +320,7 @@ describe('next-babel-loader', () => {
`import{c,d}from"e";` +
`import{e as ee,f as ff}from"f";` +
`` +
`export function unstable_getStaticProps() {foo();baz2();ff();ooo(); return { props: {} }}` +
`export function getStaticProps() {foo();baz2();ff();ooo(); return { props: {} }}` +
`export default function () { return <div>{cats + bar()}</div> }`,
{ resourcePath: pageFile, isServer: 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