Skip to content

Commit

Permalink
Merge branch 'canary' into canary
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] committed Jan 25, 2021
2 parents 87675e5 + 47cb4cf commit 61a4cb9
Show file tree
Hide file tree
Showing 21 changed files with 148 additions and 34 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
"registry": "https://registry.npmjs.org/"
}
},
"version": "10.0.6-canary.7"
"version": "10.0.6-canary.8"
}
2 changes: 1 addition & 1 deletion packages/create-next-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-next-app",
"version": "10.0.6-canary.7",
"version": "10.0.6-canary.8",
"keywords": [
"react",
"next",
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/eslint-plugin-next",
"version": "10.0.6-canary.7",
"version": "10.0.6-canary.8",
"description": "ESLint plugin for NextJS.",
"main": "lib/index.js",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-bundle-analyzer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/bundle-analyzer",
"version": "10.0.6-canary.7",
"version": "10.0.6-canary.8",
"main": "index.js",
"license": "MIT",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/next-codemod/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/codemod",
"version": "10.0.6-canary.7",
"version": "10.0.6-canary.8",
"license": "MIT",
"dependencies": {
"chalk": "4.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-env/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/env",
"version": "10.0.6-canary.7",
"version": "10.0.6-canary.8",
"keywords": [
"react",
"next",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-mdx/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/mdx",
"version": "10.0.6-canary.7",
"version": "10.0.6-canary.8",
"main": "index.js",
"license": "MIT",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/next-plugin-google-analytics/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/plugin-google-analytics",
"version": "10.0.6-canary.7",
"version": "10.0.6-canary.8",
"repository": {
"url": "vercel/next.js",
"directory": "packages/next-plugin-google-analytics"
Expand Down
2 changes: 1 addition & 1 deletion packages/next-plugin-sentry/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/plugin-sentry",
"version": "10.0.6-canary.7",
"version": "10.0.6-canary.8",
"repository": {
"url": "vercel/next.js",
"directory": "packages/next-plugin-sentry"
Expand Down
2 changes: 1 addition & 1 deletion packages/next-plugin-storybook/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/plugin-storybook",
"version": "10.0.6-canary.7",
"version": "10.0.6-canary.8",
"repository": {
"url": "vercel/next.js",
"directory": "packages/next-plugin-storybook"
Expand Down
2 changes: 1 addition & 1 deletion packages/next-polyfill-module/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/polyfill-module",
"version": "10.0.6-canary.7",
"version": "10.0.6-canary.8",
"description": "A standard library polyfill for ES Modules supporting browsers (Edge 16+, Firefox 60+, Chrome 61+, Safari 10.1+)",
"main": "dist/polyfill-module.js",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-polyfill-nomodule/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/polyfill-nomodule",
"version": "10.0.6-canary.7",
"version": "10.0.6-canary.8",
"description": "A polyfill for non-dead, nomodule browsers.",
"main": "dist/polyfill-nomodule.js",
"license": "MIT",
Expand Down
30 changes: 16 additions & 14 deletions packages/next/next-server/server/next-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1347,11 +1347,12 @@ export default class Server {
typeof components.Component === 'object' &&
typeof (components.Component as any).renderReqToHTML === 'function'
const isSSG = !!components.getStaticProps
const isServerProps = !!components.getServerSideProps
const hasServerProps = !!components.getServerSideProps
const hasStaticPaths = !!components.getStaticPaths
const hasGetInitialProps = !!(components.Component as any).getInitialProps

// Toggle whether or not this is a Data request
const isDataReq = !!query._nextDataReq && (isSSG || isServerProps)
const isDataReq = !!query._nextDataReq && (isSSG || hasServerProps)
delete query._nextDataReq

// we need to ensure the status code if /404 is visited directly
Expand Down Expand Up @@ -1379,7 +1380,7 @@ export default class Server {
let previewData: string | false | object | undefined
let isPreviewMode = false

if (isServerProps || isSSG) {
if (hasServerProps || isSSG) {
previewData = tryGetPreviewData(req, res, this.renderOpts.previewProps)
isPreviewMode = previewData !== false
}
Expand Down Expand Up @@ -1603,17 +1604,18 @@ export default class Server {
locale,
locales,
defaultLocale,
// For getServerSideProps we need to ensure we use the original URL
// For getServerSideProps and getInitialProps we need to ensure we use the original URL
// and not the resolved URL to prevent a hydration mismatch on
// asPath
resolvedAsPath: isServerProps
? formatUrl({
// we use the original URL pathname less the _next/data prefix if
// present
pathname: `${urlPathname}${hadTrailingSlash ? '/' : ''}`,
query: origQuery,
})
: resolvedUrl,
resolvedAsPath:
hasServerProps || hasGetInitialProps
? formatUrl({
// we use the original URL pathname less the _next/data prefix if
// present
pathname: `${urlPathname}${hadTrailingSlash ? '/' : ''}`,
query: origQuery,
})
: resolvedUrl,
}

renderResult = await renderToHTML(
Expand Down Expand Up @@ -1720,7 +1722,7 @@ export default class Server {
let resHtml = html

const revalidateOptions =
!this.renderOpts.dev || (isServerProps && !isDataReq)
!this.renderOpts.dev || (hasServerProps && !isDataReq)
? {
private: isPreviewMode,
stateful: !isSSG,
Expand All @@ -1731,7 +1733,7 @@ export default class Server {
if (
!isResSent(res) &&
!isNotFound &&
(isSSG || isDataReq || isServerProps)
(isSSG || isDataReq || hasServerProps)
) {
if (isRedirect && !isDataReq) {
await handleRedirect(pageData)
Expand Down
12 changes: 6 additions & 6 deletions packages/next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "next",
"version": "10.0.6-canary.7",
"version": "10.0.6-canary.8",
"description": "The React Framework",
"main": "./dist/server/next.js",
"license": "MIT",
Expand Down Expand Up @@ -63,10 +63,10 @@
"@ampproject/toolbox-optimizer": "2.7.1-alpha.0",
"@babel/runtime": "7.12.5",
"@hapi/accept": "5.0.1",
"@next/env": "10.0.6-canary.7",
"@next/polyfill-module": "10.0.6-canary.7",
"@next/react-dev-overlay": "10.0.6-canary.7",
"@next/react-refresh-utils": "10.0.6-canary.7",
"@next/env": "10.0.6-canary.8",
"@next/polyfill-module": "10.0.6-canary.8",
"@next/react-dev-overlay": "10.0.6-canary.8",
"@next/react-refresh-utils": "10.0.6-canary.8",
"@opentelemetry/api": "0.14.0",
"ast-types": "0.13.2",
"browserslist": "4.16.1",
Expand Down Expand Up @@ -135,7 +135,7 @@
"@babel/preset-react": "7.12.10",
"@babel/preset-typescript": "7.12.7",
"@babel/types": "7.12.12",
"@next/polyfill-nomodule": "10.0.6-canary.7",
"@next/polyfill-nomodule": "10.0.6-canary.8",
"@taskr/clear": "1.1.0",
"@taskr/esnext": "1.1.0",
"@taskr/watch": "1.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/react-dev-overlay/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/react-dev-overlay",
"version": "10.0.6-canary.7",
"version": "10.0.6-canary.8",
"description": "A development-only overlay for developing React applications.",
"repository": {
"url": "vercel/next.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/react-refresh-utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/react-refresh-utils",
"version": "10.0.6-canary.7",
"version": "10.0.6-canary.8",
"description": "An experimental package providing utilities for React Refresh.",
"repository": {
"url": "vercel/next.js",
Expand Down
11 changes: 11 additions & 0 deletions test/integration/getinitialprops/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
// replace me
async rewrites() {
return [
{
source: '/blog/post/:pid',
destination: '/blog/:pid',
},
]
},
}
16 changes: 16 additions & 0 deletions test/integration/getinitialprops/pages/blog/[post].js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react'
import { useRouter } from 'next/router'

const Post = () => {
const router = useRouter()

return (
<>
<div id="as-path">{router.asPath}</div>
</>
)
}

Post.getInitialProps = () => ({ hello: 'hi' })

export default Post
3 changes: 3 additions & 0 deletions test/integration/getinitialprops/pages/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const page = () => 'hello from sub id'
page.getInitialProps = () => ({ hello: 'hi' })
export default page
1 change: 1 addition & 0 deletions test/integration/getinitialprops/pages/normal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default () => <p id="normal-text">a normal page</p>
81 changes: 81 additions & 0 deletions test/integration/getinitialprops/test/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import cheerio from 'cheerio'
import { join } from 'path'
import {
findPort,
launchApp,
killApp,
nextStart,
nextBuild,
renderViaHTTP,
File,
} from 'next-test-utils'

jest.setTimeout(1000 * 60 * 5)
let app
let appPort
const appDir = join(__dirname, '..')
const nextConfig = new File(join(appDir, 'next.config.js'))

const runTests = () => {
it('should have gip in __NEXT_DATA__', async () => {
const html = await renderViaHTTP(appPort, '/')
const $ = cheerio.load(html)
expect(JSON.parse($('#__NEXT_DATA__').text()).gip).toBe(true)
})

it('should not have gip in __NEXT_DATA__ for non-GIP page', async () => {
const html = await renderViaHTTP(appPort, '/normal')
const $ = cheerio.load(html)
expect('gip' in JSON.parse($('#__NEXT_DATA__').text())).toBe(false)
})

it('should have correct router.asPath for direct visit dynamic page', async () => {
const html = await renderViaHTTP(appPort, '/blog/1')
const $ = cheerio.load(html)
expect($('#as-path').text()).toBe('/blog/1')
})

it('should have correct router.asPath for direct visit dynamic page rewrite direct', async () => {
const html = await renderViaHTTP(appPort, '/blog/post/1')
const $ = cheerio.load(html)
expect($('#as-path').text()).toBe('/blog/post/1')
})
}

describe('getInitialProps', () => {
describe('dev mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))

runTests()
})

describe('serverless mode', () => {
beforeAll(async () => {
await nextConfig.replace('// replace me', `target: 'serverless', `)
await nextBuild(appDir)
appPort = await findPort()
app = await nextStart(appDir, appPort)
})
afterAll(async () => {
await killApp(app)
nextConfig.restore()
})

runTests()
})

describe('production mode', () => {
beforeAll(async () => {
await nextBuild(appDir)
appPort = await findPort()
app = await nextStart(appDir, appPort)
})
afterAll(() => killApp(app))

runTests()
})
})

0 comments on commit 61a4cb9

Please sign in to comment.