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