From 2789e7e0c25c72fbf6be3ef070e530186af14430 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Thu, 27 Feb 2020 11:04:30 -0600 Subject: [PATCH] Rename getServerProps to getServerSideProps (#10722) --- docs/concepts/_data-fetching.md | 4 ++-- errors/404-get-initial-props.md | 2 +- examples/with-apollo/lib/apollo.js | 2 +- .../build/babel/plugins/next-ssg-transform.ts | 2 +- packages/next/build/utils.ts | 4 ++-- .../webpack/loaders/next-serverless-loader.ts | 12 +++++------ packages/next/lib/constants.ts | 6 +++--- .../next-server/server/load-components.ts | 20 +++++++++---------- .../next/next-server/server/next-server.ts | 2 +- packages/next/next-server/server/render.tsx | 20 +++++++++---------- packages/next/pages/_app.tsx | 2 +- test/integration/404-page/test/index.test.js | 4 ++-- .../pages/another/index.js | 2 +- .../pages/blog/[post]/[comment].js | 2 +- .../pages/blog/[post]/index.js | 2 +- .../pages/blog/index.js | 2 +- .../pages/catchall/[...path].js | 2 +- .../pages/default-revalidate.js | 2 +- .../pages/index.js | 2 +- .../pages/invalid-keys.js | 2 +- .../pages/normal.js | 0 .../pages/something.js | 2 +- .../pages/user/[user]/profile.js | 2 +- .../test/index.test.js | 14 ++++++------- .../world.txt | 0 .../pages/index.js | 2 +- .../pages/index.js.alt | 2 +- .../test/index.test.js | 6 +++--- 28 files changed, 62 insertions(+), 62 deletions(-) rename test/integration/{getserverprops => getserversideprops}/pages/another/index.js (93%) rename test/integration/{getserverprops => getserversideprops}/pages/blog/[post]/[comment].js (87%) rename test/integration/{getserverprops => getserversideprops}/pages/blog/[post]/index.js (92%) rename test/integration/{getserverprops => getserversideprops}/pages/blog/index.js (89%) rename test/integration/{getserverprops => getserversideprops}/pages/catchall/[...path].js (92%) rename test/integration/{getserverprops => getserversideprops}/pages/default-revalidate.js (88%) rename test/integration/{getserverprops => getserversideprops}/pages/index.js (95%) rename test/integration/{getserverprops => getserversideprops}/pages/invalid-keys.js (91%) rename test/integration/{getserverprops => getserversideprops}/pages/normal.js (100%) rename test/integration/{getserverprops => getserversideprops}/pages/something.js (92%) rename test/integration/{getserverprops => getserversideprops}/pages/user/[user]/profile.js (86%) rename test/integration/{getserverprops => getserversideprops}/test/index.test.js (96%) rename test/integration/{getserverprops => getserversideprops}/world.txt (100%) diff --git a/docs/concepts/_data-fetching.md b/docs/concepts/_data-fetching.md index 0e850853018414c..b5496b255f37de9 100644 --- a/docs/concepts/_data-fetching.md +++ b/docs/concepts/_data-fetching.md @@ -46,7 +46,7 @@ export default HomePage [Read more about how Server-Side Rendering works](). -To opt-in to Server-Side Rendering, making every request render HTML on-demand you use the `getServerProps` method. +To opt-in to Server-Side Rendering, making every request render HTML on-demand you use the `getServerSideProps` method. It allows you to fetch data before rendering starts when a request comes in. @@ -56,7 +56,7 @@ Taking the same example as Static Generation, but opted into rendering the page import fetch from 'isomorphic-unfetch' // Called when a request comes in. -export async function getServerProps() { +export async function getServerSideProps() { const res = await fetch('https://api.github.com/repos/zeit/next.js') const json = await res.json() diff --git a/errors/404-get-initial-props.md b/errors/404-get-initial-props.md index dc0e1ecb3510c7f..af7fde5a3b48b2e 100644 --- a/errors/404-get-initial-props.md +++ b/errors/404-get-initial-props.md @@ -2,7 +2,7 @@ #### Why This Error Occurred -In your `404.js` page you added `getInitialProps` or `getServerProps` which is not allowed as this prevents the page from being static and `404.js` is meant to provide more flexibility for a static 404 page. Having a static 404 page is the most ideal as this page can be served very often and if not static puts extra strain on your server and more invocations for serverless functions which increase the cost of hosting your site unnecessarily. +In your `404.js` page you added `getInitialProps` or `getServerSideProps` which is not allowed as this prevents the page from being static and `404.js` is meant to provide more flexibility for a static 404 page. Having a static 404 page is the most ideal as this page can be served very often and if not static puts extra strain on your server and more invocations for serverless functions which increase the cost of hosting your site unnecessarily. #### Possible Ways to Fix It diff --git a/examples/with-apollo/lib/apollo.js b/examples/with-apollo/lib/apollo.js index 17a40a6d309c702..bff375c2cf927c7 100644 --- a/examples/with-apollo/lib/apollo.js +++ b/examples/with-apollo/lib/apollo.js @@ -11,7 +11,7 @@ let globalApolloClient = null /** * Installs the Apollo Client on NextPageContext * or NextAppContext. Useful if you want to use apolloClient - * inside getStaticProps, getStaticPaths or getServerProps + * inside getStaticProps, getStaticPaths or getServerSideProps * @param {NextPageContext | NextAppContext} ctx */ export const initOnContext = ctx => { diff --git a/packages/next/build/babel/plugins/next-ssg-transform.ts b/packages/next/build/babel/plugins/next-ssg-transform.ts index 2a7cea08e6b7490..97a27c7f8ff1453 100644 --- a/packages/next/build/babel/plugins/next-ssg-transform.ts +++ b/packages/next/build/babel/plugins/next-ssg-transform.ts @@ -10,7 +10,7 @@ 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_getServerProps' +export const EXPORT_NAME_GET_SERVER_PROPS = 'unstable_getServerSideProps' const ssgExports = new Set([ EXPORT_NAME_GET_STATIC_PROPS, diff --git a/packages/next/build/utils.ts b/packages/next/build/utils.ts index c7ed129ecfad87c..8269949a55dd9b4 100644 --- a/packages/next/build/utils.ts +++ b/packages/next/build/utils.ts @@ -202,7 +202,7 @@ export async function printTreeView( serverless ? '(Lambda)' : '(Server)', `server-side renders at runtime (uses ${chalk.cyan( 'getInitialProps' - )} or ${chalk.cyan('getServerProps')})`, + )} or ${chalk.cyan('getServerSideProps')})`, ], [ '○', @@ -636,7 +636,7 @@ export async function isPageStatic( const hasGetInitialProps = !!(Comp as any).getInitialProps const hasStaticProps = !!mod.unstable_getStaticProps const hasStaticPaths = !!mod.unstable_getStaticPaths - const hasServerProps = !!mod.unstable_getServerProps + const hasServerProps = !!mod.unstable_getServerSideProps const hasLegacyStaticParams = !!mod.unstable_getStaticParams if (hasLegacyStaticParams) { diff --git a/packages/next/build/webpack/loaders/next-serverless-loader.ts b/packages/next/build/webpack/loaders/next-serverless-loader.ts index 47ab3582dcf4875..0b6c770fc1a31c7 100644 --- a/packages/next/build/webpack/loaders/next-serverless-loader.ts +++ b/packages/next/build/webpack/loaders/next-serverless-loader.ts @@ -220,7 +220,7 @@ const nextServerlessLoader: loader.Loader = function() { export const unstable_getStaticProps = ComponentInfo['unstable_getStaticProp' + 's'] export const unstable_getStaticParams = ComponentInfo['unstable_getStaticParam' + 's'] export const unstable_getStaticPaths = ComponentInfo['unstable_getStaticPath' + 's'] - export const unstable_getServerProps = ComponentInfo['unstable_getServerProp' + 's'] + export const unstable_getServerSideProps = ComponentInfo['unstable_getServerSideProp' + 's'] ${dynamicRouteMatcher} ${handleRewrites} @@ -242,7 +242,7 @@ const nextServerlessLoader: loader.Loader = function() { Document, buildManifest, unstable_getStaticProps, - unstable_getServerProps, + unstable_getServerSideProps, unstable_getStaticPaths, reactLoadableManifest, canonicalBase: "${canonicalBase}", @@ -275,7 +275,7 @@ const nextServerlessLoader: loader.Loader = function() { ${page === '/_error' ? `res.statusCode = 404` : ''} ${ pageIsDynamicRoute - ? `const params = fromExport && !unstable_getStaticProps && !unstable_getServerProps ? {} : dynamicRouteMatcher(parsedUrl.pathname) || {};` + ? `const params = fromExport && !unstable_getStaticProps && !unstable_getServerSideProps ? {} : dynamicRouteMatcher(parsedUrl.pathname) || {};` : `const params = {};` } ${ @@ -331,7 +331,7 @@ const nextServerlessLoader: loader.Loader = function() { 'Cache-Control', isPreviewMode ? \`private, no-cache, no-store, max-age=0, must-revalidate\` - : unstable_getServerProps + : unstable_getServerSideProps ? \`no-cache, no-store, must-revalidate\` : \`s-maxage=\${renderOpts.revalidate}, stale-while-revalidate\` ) @@ -352,7 +352,7 @@ const nextServerlessLoader: loader.Loader = function() { const result = await renderToHTML(req, res, "/_error", parsedUrl.query, Object.assign({}, options, { unstable_getStaticProps: undefined, unstable_getStaticPaths: undefined, - unstable_getServerProps: undefined, + unstable_getServerSideProps: undefined, Component: Error })) return result @@ -362,7 +362,7 @@ const nextServerlessLoader: loader.Loader = function() { const result = await renderToHTML(req, res, "/_error", parsedUrl.query, Object.assign({}, options, { unstable_getStaticProps: undefined, unstable_getStaticPaths: undefined, - unstable_getServerProps: undefined, + unstable_getServerSideProps: undefined, Component: Error, err })) diff --git a/packages/next/lib/constants.ts b/packages/next/lib/constants.ts index 4391cbc755c04b2..1070627fad7a23a 100644 --- a/packages/next/lib/constants.ts +++ b/packages/next/lib/constants.ts @@ -26,8 +26,8 @@ export const PUBLIC_DIR_MIDDLEWARE_CONFLICT = `You can not have a '_next' folder export const SSG_GET_INITIAL_PROPS_CONFLICT = `You can not use getInitialProps with unstable_getStaticProps. To use SSG, please remove your getInitialProps` -export const SERVER_PROPS_GET_INIT_PROPS_CONFLICT = `You can not use getInitialProps with unstable_getServerProps. Please remove one or the other` +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_SSG_CONFLICT = `You can not use unstable_getStaticProps with unstable_getServerProps. To use SSG, please remove your unstable_getServerProps` +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 PAGES_404_GET_INITIAL_PROPS_ERROR = `\`pages/404\` can not have getInitialProps/getServerProps, 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` diff --git a/packages/next/next-server/server/load-components.ts b/packages/next/next-server/server/load-components.ts index e4052770e8aebac..856ea05a6efd8b2 100644 --- a/packages/next/next-server/server/load-components.ts +++ b/packages/next/next-server/server/load-components.ts @@ -21,13 +21,13 @@ export function interopDefault(mod: any) { function addComponentPropsId( Component: any, getStaticProps: any, - getServerProps: any + getServerSideProps: any ) { // Mark the component with the SSG or SSP id here since we don't run // the SSG babel transform for server mode if (getStaticProps) { Component[STATIC_PROPS_ID] = true - } else if (getServerProps) { + } else if (getServerSideProps) { Component[SERVER_PROPS_ID] = true } } @@ -55,7 +55,7 @@ export type Unstable_getStaticPaths = () => Promise<{ fallback: boolean }> -type Unstable_getServerProps = (context: { +type Unstable_getServerSideProps = (context: { params: ParsedUrlQuery | undefined req: IncomingMessage res: ServerResponse @@ -72,7 +72,7 @@ export type LoadComponentsReturnType = { App: AppType unstable_getStaticProps?: Unstable_getStaticProps unstable_getStaticPaths?: Unstable_getStaticPaths - unstable_getServerProps?: Unstable_getServerProps + unstable_getServerSideProps?: Unstable_getServerSideProps } export async function loadComponents( @@ -86,13 +86,13 @@ export async function loadComponents( const { unstable_getStaticProps, unstable_getStaticPaths, - unstable_getServerProps, + unstable_getServerSideProps, } = Component addComponentPropsId( Component, unstable_getStaticProps, - unstable_getServerProps + unstable_getServerSideProps ) return { @@ -100,7 +100,7 @@ export async function loadComponents( pageConfig: Component.config || {}, unstable_getStaticProps, unstable_getStaticPaths, - unstable_getServerProps, + unstable_getServerSideProps, } as LoadComponentsReturnType } const documentPath = join( @@ -142,7 +142,7 @@ export async function loadComponents( ]) const { - unstable_getServerProps, + unstable_getServerSideProps, unstable_getStaticProps, unstable_getStaticPaths, } = ComponentMod @@ -150,7 +150,7 @@ export async function loadComponents( addComponentPropsId( Component, unstable_getStaticProps, - unstable_getServerProps + unstable_getServerSideProps ) return { @@ -161,7 +161,7 @@ export async function loadComponents( DocumentMiddleware, reactLoadableManifest, pageConfig: ComponentMod.config || {}, - unstable_getServerProps, + unstable_getServerSideProps, unstable_getStaticProps, unstable_getStaticPaths, } diff --git a/packages/next/next-server/server/next-server.ts b/packages/next/next-server/server/next-server.ts index c02696bcf707941..4e1ec838ac3eefa 100644 --- a/packages/next/next-server/server/next-server.ts +++ b/packages/next/next-server/server/next-server.ts @@ -889,7 +889,7 @@ export default class Server { typeof components.Component === 'object' && typeof (components.Component as any).renderReqToHTML === 'function' const isSSG = !!components.unstable_getStaticProps - const isServerProps = !!components.unstable_getServerProps + const isServerProps = !!components.unstable_getServerSideProps const hasStaticPaths = !!components.unstable_getStaticPaths // Toggle whether or not this is a Data request diff --git a/packages/next/next-server/server/render.tsx b/packages/next/next-server/server/render.tsx index 8e848519c1c8119..287dd361ed7dc21 100644 --- a/packages/next/next-server/server/render.tsx +++ b/packages/next/next-server/server/render.tsx @@ -275,7 +275,7 @@ export async function renderToHTML( ErrorDebug, unstable_getStaticProps, unstable_getStaticPaths, - unstable_getServerProps, + unstable_getServerSideProps, isDataReq, params, previewProps, @@ -323,7 +323,7 @@ export async function renderToHTML( !hasPageGetInitialProps && defaultAppGetInitialProps && !isSpr && - !unstable_getServerProps + !unstable_getServerSideProps if ( process.env.NODE_ENV !== 'production' && @@ -349,11 +349,11 @@ export async function renderToHTML( throw new Error(SSG_GET_INITIAL_PROPS_CONFLICT + ` ${pathname}`) } - if (hasPageGetInitialProps && unstable_getServerProps) { + if (hasPageGetInitialProps && unstable_getServerSideProps) { throw new Error(SERVER_PROPS_GET_INIT_PROPS_CONFLICT + ` ${pathname}`) } - if (unstable_getServerProps && isSpr) { + if (unstable_getServerSideProps && isSpr) { throw new Error(SERVER_PROPS_SSG_CONFLICT + ` ${pathname}`) } @@ -529,8 +529,8 @@ export async function renderToHTML( console.error(err) } - if (unstable_getServerProps && !isFallback) { - const data = await unstable_getServerProps({ + if (unstable_getServerSideProps && !isFallback) { + const data = await unstable_getServerSideProps({ params, query, req, @@ -540,7 +540,7 @@ export async function renderToHTML( const invalidKeys = Object.keys(data).filter(key => key !== 'props') if (invalidKeys.length) { - throw new Error(invalidKeysMsg('getServerProps', invalidKeys)) + throw new Error(invalidKeysMsg('getServerSideProps', invalidKeys)) } props.pageProps = data.props @@ -549,7 +549,7 @@ export async function renderToHTML( if ( !isSpr && // we only show this warning for legacy pages - !unstable_getServerProps && + !unstable_getServerSideProps && process.env.NODE_ENV !== 'production' && Object.keys(props?.pageProps || {}).includes('url') ) { @@ -560,10 +560,10 @@ export async function renderToHTML( } // We only need to do this if we want to support calling - // _app's getInitialProps for getServerProps if not this can be removed + // _app's getInitialProps for getServerSideProps if not this can be removed if (isDataReq) return props - // We don't call getStaticProps or getServerProps while generating + // We don't call getStaticProps or getServerSideProps while generating // the fallback so make sure to set pageProps to an empty object if (isFallback) { props.pageProps = {} diff --git a/packages/next/pages/_app.tsx b/packages/next/pages/_app.tsx index 0132f5ab4825ddc..32727d7f2ea94a5 100644 --- a/packages/next/pages/_app.tsx +++ b/packages/next/pages/_app.tsx @@ -48,7 +48,7 @@ export default class App

extends React.Component< {...pageProps} { // we don't add the legacy URL prop if it's using non-legacy - // methods like getStaticProps and getServerProps + // methods like getStaticProps and getServerSideProps ...(!((Component as any).__N_SSG || (Component as any).__N_SSP) ? { url: createUrl(router) } : {}) diff --git a/test/integration/404-page/test/index.test.js b/test/integration/404-page/test/index.test.js index 0656fe67c1c3bb4..9029af04c2f982d 100644 --- a/test/integration/404-page/test/index.test.js +++ b/test/integration/404-page/test/index.test.js @@ -149,7 +149,7 @@ describe('404 Page Support', () => { await fs.move(`${pages404}.bak`, pages404) expect(stderr).toContain( - `\`pages/404\` can not have getInitialProps/getServerProps, https://err.sh/zeit/next.js/404-get-initial-props` + `\`pages/404\` can not have getInitialProps/getServerSideProps, https://err.sh/zeit/next.js/404-get-initial-props` ) expect(code).toBe(1) }) @@ -180,7 +180,7 @@ describe('404 Page Support', () => { await fs.remove(pages404) await fs.move(`${pages404}.bak`, pages404) - const error = `\`pages/404\` can not have getInitialProps/getServerProps, https://err.sh/zeit/next.js/404-get-initial-props` + const error = `\`pages/404\` can not have getInitialProps/getServerSideProps, https://err.sh/zeit/next.js/404-get-initial-props` expect(stderr).toContain(error) }) diff --git a/test/integration/getserverprops/pages/another/index.js b/test/integration/getserversideprops/pages/another/index.js similarity index 93% rename from test/integration/getserverprops/pages/another/index.js rename to test/integration/getserversideprops/pages/another/index.js index a5c3afb6343c63f..de46cda8bd03413 100644 --- a/test/integration/getserverprops/pages/another/index.js +++ b/test/integration/getserversideprops/pages/another/index.js @@ -3,7 +3,7 @@ import fs from 'fs' import findUp from 'find-up' // eslint-disable-next-line camelcase -export async function unstable_getServerProps() { +export async function unstable_getServerSideProps() { const text = fs .readFileSync( findUp.sync('world.txt', { diff --git a/test/integration/getserverprops/pages/blog/[post]/[comment].js b/test/integration/getserversideprops/pages/blog/[post]/[comment].js similarity index 87% rename from test/integration/getserverprops/pages/blog/[post]/[comment].js rename to test/integration/getserversideprops/pages/blog/[post]/[comment].js index 292c98024942dc3..a5a42247ecb12a9 100644 --- a/test/integration/getserverprops/pages/blog/[post]/[comment].js +++ b/test/integration/getserversideprops/pages/blog/[post]/[comment].js @@ -2,7 +2,7 @@ import React from 'react' import Link from 'next/link' // eslint-disable-next-line camelcase -export async function unstable_getServerProps({ query }) { +export async function unstable_getServerSideProps({ query }) { return { props: { post: query.post, diff --git a/test/integration/getserverprops/pages/blog/[post]/index.js b/test/integration/getserversideprops/pages/blog/[post]/index.js similarity index 92% rename from test/integration/getserverprops/pages/blog/[post]/index.js rename to test/integration/getserversideprops/pages/blog/[post]/index.js index aa4e0c5cc2bd12a..ba9c5978ea8891c 100644 --- a/test/integration/getserverprops/pages/blog/[post]/index.js +++ b/test/integration/getserversideprops/pages/blog/[post]/index.js @@ -3,7 +3,7 @@ import Link from 'next/link' import { useRouter } from 'next/router' // eslint-disable-next-line camelcase -export async function unstable_getServerProps({ params }) { +export async function unstable_getServerSideProps({ params }) { if (params.post === 'post-10') { await new Promise(resolve => { setTimeout(() => resolve(), 1000) diff --git a/test/integration/getserverprops/pages/blog/index.js b/test/integration/getserversideprops/pages/blog/index.js similarity index 89% rename from test/integration/getserverprops/pages/blog/index.js rename to test/integration/getserversideprops/pages/blog/index.js index 056a1860a3e3dfa..be51f782e42d6ca 100644 --- a/test/integration/getserverprops/pages/blog/index.js +++ b/test/integration/getserversideprops/pages/blog/index.js @@ -2,7 +2,7 @@ import React from 'react' import Link from 'next/link' // eslint-disable-next-line camelcase -export async function unstable_getServerProps() { +export async function unstable_getServerSideProps() { return { props: { slugs: ['post-1', 'post-2'], diff --git a/test/integration/getserverprops/pages/catchall/[...path].js b/test/integration/getserversideprops/pages/catchall/[...path].js similarity index 92% rename from test/integration/getserverprops/pages/catchall/[...path].js rename to test/integration/getserversideprops/pages/catchall/[...path].js index 5e1bd3543f63fec..45efb3e6c85f68f 100644 --- a/test/integration/getserverprops/pages/catchall/[...path].js +++ b/test/integration/getserversideprops/pages/catchall/[...path].js @@ -3,7 +3,7 @@ import Link from 'next/link' import { useRouter } from 'next/router' // eslint-disable-next-line camelcase -export async function unstable_getServerProps({ params }) { +export async function unstable_getServerSideProps({ params }) { return { props: { world: 'world', diff --git a/test/integration/getserverprops/pages/default-revalidate.js b/test/integration/getserversideprops/pages/default-revalidate.js similarity index 88% rename from test/integration/getserverprops/pages/default-revalidate.js rename to test/integration/getserversideprops/pages/default-revalidate.js index 15bb81ba617e876..582ef524ec1a408 100644 --- a/test/integration/getserverprops/pages/default-revalidate.js +++ b/test/integration/getserversideprops/pages/default-revalidate.js @@ -1,7 +1,7 @@ import Link from 'next/link' // eslint-disable-next-line camelcase -export async function unstable_getServerProps() { +export async function unstable_getServerSideProps() { return { props: { world: 'world', diff --git a/test/integration/getserverprops/pages/index.js b/test/integration/getserversideprops/pages/index.js similarity index 95% rename from test/integration/getserverprops/pages/index.js rename to test/integration/getserversideprops/pages/index.js index f906758f846b1d8..fc84e9848d8d6f6 100644 --- a/test/integration/getserverprops/pages/index.js +++ b/test/integration/getserversideprops/pages/index.js @@ -1,7 +1,7 @@ import Link from 'next/link' // eslint-disable-next-line camelcase -export async function unstable_getServerProps() { +export async function unstable_getServerSideProps() { return { props: { world: 'world', diff --git a/test/integration/getserverprops/pages/invalid-keys.js b/test/integration/getserversideprops/pages/invalid-keys.js similarity index 91% rename from test/integration/getserverprops/pages/invalid-keys.js rename to test/integration/getserversideprops/pages/invalid-keys.js index 6eeba67fb6a7730..4184eb8bcfabca8 100644 --- a/test/integration/getserverprops/pages/invalid-keys.js +++ b/test/integration/getserversideprops/pages/invalid-keys.js @@ -3,7 +3,7 @@ import Link from 'next/link' import { useRouter } from 'next/router' // eslint-disable-next-line camelcase -export async function unstable_getServerProps({ params, query }) { +export async function unstable_getServerSideProps({ params, query }) { return { world: 'world', query: query || {}, diff --git a/test/integration/getserverprops/pages/normal.js b/test/integration/getserversideprops/pages/normal.js similarity index 100% rename from test/integration/getserverprops/pages/normal.js rename to test/integration/getserversideprops/pages/normal.js diff --git a/test/integration/getserverprops/pages/something.js b/test/integration/getserversideprops/pages/something.js similarity index 92% rename from test/integration/getserverprops/pages/something.js rename to test/integration/getserversideprops/pages/something.js index f3d5ef1ef4de2f0..361bbb44b5097ce 100644 --- a/test/integration/getserverprops/pages/something.js +++ b/test/integration/getserversideprops/pages/something.js @@ -3,7 +3,7 @@ import Link from 'next/link' import { useRouter } from 'next/router' // eslint-disable-next-line camelcase -export async function unstable_getServerProps({ params, query }) { +export async function unstable_getServerSideProps({ params, query }) { return { props: { world: 'world', diff --git a/test/integration/getserverprops/pages/user/[user]/profile.js b/test/integration/getserversideprops/pages/user/[user]/profile.js similarity index 86% rename from test/integration/getserverprops/pages/user/[user]/profile.js rename to test/integration/getserversideprops/pages/user/[user]/profile.js index a4fb1e13403bf04..c14992d56d4dc22 100644 --- a/test/integration/getserverprops/pages/user/[user]/profile.js +++ b/test/integration/getserversideprops/pages/user/[user]/profile.js @@ -2,7 +2,7 @@ import React from 'react' import Link from 'next/link' // eslint-disable-next-line camelcase -export async function unstable_getServerProps({ query }) { +export async function unstable_getServerSideProps({ query }) { return { props: { user: query.user, diff --git a/test/integration/getserverprops/test/index.test.js b/test/integration/getserversideprops/test/index.test.js similarity index 96% rename from test/integration/getserverprops/test/index.test.js rename to test/integration/getserversideprops/test/index.test.js index 84707e9eccf540e..963215c85850225 100644 --- a/test/integration/getserverprops/test/index.test.js +++ b/test/integration/getserversideprops/test/index.test.js @@ -186,7 +186,7 @@ const runTests = (dev = false) => { expect(html).toMatch(/hello.*?world/) }) - it('should SSR getServerProps page correctly', async () => { + it('should SSR getServerSideProps page correctly', async () => { const html = await renderViaHTTP(appPort, '/blog/post-1') expect(html).toMatch(/Post:.*?post-1/) }) @@ -298,7 +298,7 @@ const runTests = (dev = false) => { expect(await browser.eval('window.beforeClick')).not.toBe('true') }) - it('should always call getServerProps without caching', async () => { + it('should always call getServerSideProps without caching', async () => { const initialRes = await fetchViaHTTP(appPort, '/something') const initialHtml = await initialRes.text() expect(initialHtml).toMatch(/hello.*?world/) @@ -314,7 +314,7 @@ const runTests = (dev = false) => { expect(newHtml !== newerHtml).toBe(true) }) - it('should not re-call getServerProps when updating query', async () => { + it('should not re-call getServerSideProps when updating query', async () => { const browser = await webdriver(appPort, '/something?hello=world') await waitFor(2000) @@ -337,7 +337,7 @@ const runTests = (dev = false) => { await fs.writeFile( urlPropPage, ` - export async function unstable_getServerProps() { + export async function unstable_getServerSideProps() { return { props: { url: 'something' @@ -357,10 +357,10 @@ const runTests = (dev = false) => { expect(html).toMatch(/url:.*?something/) }) - it('should show error for extra keys returned from getServerProps', async () => { + it('should show error for extra keys returned from getServerSideProps', async () => { const html = await renderViaHTTP(appPort, '/invalid-keys') expect(html).toContain( - `Additional keys were returned from \`getServerProps\`. Properties intended for your component must be nested under the \`props\` key, e.g.:` + `Additional keys were returned from \`getServerSideProps\`. Properties intended for your component must be nested under the \`props\` key, e.g.:` ) expect(html).toContain( `Keys that need to be moved: world, query, params, time, random` @@ -396,7 +396,7 @@ const runTests = (dev = false) => { } } -describe('unstable_getServerProps', () => { +describe('unstable_getServerSideProps', () => { describe('dev mode', () => { beforeAll(async () => { stderr = '' diff --git a/test/integration/getserverprops/world.txt b/test/integration/getserversideprops/world.txt similarity index 100% rename from test/integration/getserverprops/world.txt rename to test/integration/getserversideprops/world.txt diff --git a/test/integration/mixed-ssg-serverprops-error/pages/index.js b/test/integration/mixed-ssg-serverprops-error/pages/index.js index dedf3d00be14bed..7bf4d452e293240 100644 --- a/test/integration/mixed-ssg-serverprops-error/pages/index.js +++ b/test/integration/mixed-ssg-serverprops-error/pages/index.js @@ -4,7 +4,7 @@ export const unstable_getStaticProps = async () => { } } -export const unstable_getServerProps = async () => { +export const unstable_getServerSideProps = async () => { return { props: { world: 'world' }, } diff --git a/test/integration/mixed-ssg-serverprops-error/pages/index.js.alt b/test/integration/mixed-ssg-serverprops-error/pages/index.js.alt index 4756984cc3a9369..9d6334f42ef07ad 100644 --- a/test/integration/mixed-ssg-serverprops-error/pages/index.js.alt +++ b/test/integration/mixed-ssg-serverprops-error/pages/index.js.alt @@ -4,7 +4,7 @@ export const unstable_getStaticPaths = async () => { } } -export const unstable_getServerProps = async () => { +export const unstable_getServerSideProps = async () => { return { props: { world: 'world' } } diff --git a/test/integration/mixed-ssg-serverprops-error/test/index.test.js b/test/integration/mixed-ssg-serverprops-error/test/index.test.js index 794cf77cae22f8b..27fdee631a1a118 100644 --- a/test/integration/mixed-ssg-serverprops-error/test/index.test.js +++ b/test/integration/mixed-ssg-serverprops-error/test/index.test.js @@ -11,13 +11,13 @@ const indexPage = join(appDir, 'pages/index.js') const indexPageAlt = `${indexPage}.alt` const indexPageBak = `${indexPage}.bak` -describe('Mixed getStaticProps and getServerProps error', () => { - it('should error when exporting both getStaticProps and getServerProps', async () => { +describe('Mixed getStaticProps and getServerSideProps error', () => { + it('should error when exporting both getStaticProps and getServerSideProps', async () => { const { stderr } = await nextBuild(appDir, [], { stderr: true }) expect(stderr).toContain(SERVER_PROPS_SSG_CONFLICT) }) - it('should error when exporting both getStaticPaths and getServerProps', async () => { + it('should error when exporting both getStaticPaths and getServerSideProps', async () => { await fs.move(indexPage, indexPageBak) await fs.move(indexPageAlt, indexPage)