Skip to content

Commit

Permalink
Merge branch 'canary' into why-you-render-example
Browse files Browse the repository at this point in the history
  • Loading branch information
Moti Ko committed Feb 27, 2020
2 parents 489e858 + b3ffdab commit 71cf5da
Show file tree
Hide file tree
Showing 33 changed files with 549 additions and 232 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/1.Bug_report.md
@@ -1,6 +1,6 @@
---
name: Bug report
about: Create a bug report for the Next.js core
about: Create a bug report for the Next.js core / examples
---

# Bug report
Expand Down
41 changes: 0 additions & 41 deletions .github/ISSUE_TEMPLATE/3.Example_Bug_report.md

This file was deleted.

10 changes: 0 additions & 10 deletions .github/ISSUE_TEMPLATE/8.Question_about_next.md

This file was deleted.

5 changes: 5 additions & 0 deletions .github/ISSUE_TEMPLATE/config.yml
@@ -0,0 +1,5 @@
blank_issues_enabled: false
contact_links:
- name: Ask a question
url: https://github.com/zeit/next.js/discussions
about: Ask questions and discuss with other community members
9 changes: 9 additions & 0 deletions errors/reserved-page-prop.md
@@ -0,0 +1,9 @@
# Reserved Page Prop

#### Why This Error Occurred

In a page's `getInitialProps` a reserved prop was returned. Currently the only reserved page prop is `url` for legacy reasons.

#### Possible Ways to Fix It

Change the name of the prop returned from `getInitialProps` to any other name.
5 changes: 5 additions & 0 deletions examples/with-apollo/lib/apollo.js
@@ -1,5 +1,6 @@
import React from 'react'
import App from 'next/app'
import Head from 'next/head'
import { ApolloProvider } from '@apollo/react-hooks'
import createApolloClient from '../apolloClient'

Expand Down Expand Up @@ -153,6 +154,10 @@ export const withApollo = ({ ssr = false } = {}) => PageComponent => {
// https://www.apollographql.com/docs/react/api/react-apollo.html#graphql-query-data-error
console.error('Error while running `getDataFromTree`', error)
}

// getDataFromTree does not call componentWillUnmount
// head side effect therefore need to be cleared manually
Head.rewind()
}
}

Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Expand Up @@ -12,5 +12,5 @@
"registry": "https://registry.npmjs.org/"
}
},
"version": "9.2.3-canary.12"
"version": "9.2.3-canary.13"
}
2 changes: 1 addition & 1 deletion packages/create-next-app/package.json
@@ -1,6 +1,6 @@
{
"name": "create-next-app",
"version": "9.2.3-canary.12",
"version": "9.2.3-canary.13",
"keywords": [
"react",
"next",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-bundle-analyzer/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/bundle-analyzer",
"version": "9.2.3-canary.12",
"version": "9.2.3-canary.13",
"main": "index.js",
"license": "MIT",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/next-mdx/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/mdx",
"version": "9.2.3-canary.12",
"version": "9.2.3-canary.13",
"main": "index.js",
"license": "MIT",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/next-plugin-google-analytics/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/plugin-google-analytics",
"version": "9.2.3-canary.12",
"version": "9.2.3-canary.13",
"nextjs": {
"name": "Google Analytics",
"required-env": [
Expand Down
2 changes: 1 addition & 1 deletion packages/next-plugin-material-ui/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/plugin-material-ui",
"version": "9.2.3-canary.12",
"version": "9.2.3-canary.13",
"nextjs": {
"name": "Material UI",
"required-env": []
Expand Down
2 changes: 1 addition & 1 deletion packages/next-plugin-sentry/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/plugin-sentry",
"version": "9.2.3-canary.12",
"version": "9.2.3-canary.13",
"nextjs": {
"name": "Sentry",
"required-env": [
Expand Down
2 changes: 1 addition & 1 deletion packages/next-polyfill-nomodule/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/polyfill-nomodule",
"version": "9.2.3-canary.12",
"version": "9.2.3-canary.13",
"description": "A polyfill for non-dead, nomodule browsers.",
"main": "dist/polyfill-nomodule.js",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/next/README.md
Expand Up @@ -10,7 +10,7 @@
<a aria-label="License" href="https://github.com/zeit/next.js/blob/canary/license.md">
<img alt="" src="https://img.shields.io/npm/l/next.svg?style=for-the-badge&labelColor=000000">
</a>
<a aria-label="join us in spectrum" href="https://spectrum.chat/next-js">
<a aria-label="join us in spectrum" href="https://github.com/zeit/next.js/discussions">
<img alt="" src="https://img.shields.io/badge/Join%20the%20community-blueviolet.svg?style=for-the-badge&logo=Next.js&labelColor=000000&logoWidth=20">
</a>
</p>
Expand Down
10 changes: 6 additions & 4 deletions packages/next/build/babel/plugins/next-ssg-transform.ts
@@ -1,10 +1,12 @@
import { NodePath, PluginObj } from '@babel/core'
import * as BabelTypes from '@babel/types'
import { SERVER_PROPS_SSG_CONFLICT } from '../../../lib/constants'
import {
STATIC_PROPS_ID,
SERVER_PROPS_ID,
} from '../../../next-server/lib/constants'

const pageComponentVar = '__NEXT_COMP'
const prerenderId = '__N_SSG'
const serverPropsId = '__N_SSP'

export const EXPORT_NAME_GET_STATIC_PROPS = 'unstable_getStaticProps'
export const EXPORT_NAME_GET_STATIC_PATHS = 'unstable_getStaticPaths'
Expand Down Expand Up @@ -53,7 +55,7 @@ function decorateSsgExport(
'=',
t.memberExpression(
t.identifier(pageComponentVar),
t.identifier(state.isPrerender ? prerenderId : serverPropsId)
t.identifier(state.isPrerender ? STATIC_PROPS_ID : SERVER_PROPS_ID)
),
t.booleanLiteral(true)
),
Expand All @@ -80,7 +82,7 @@ function decorateSsgExport(
'=',
t.memberExpression(
t.identifier((defaultSpecifier as any).local.name),
t.identifier(state.isPrerender ? prerenderId : serverPropsId)
t.identifier(state.isPrerender ? STATIC_PROPS_ID : SERVER_PROPS_ID)
),
t.booleanLiteral(true)
),
Expand Down
15 changes: 8 additions & 7 deletions packages/next/build/index.ts
Expand Up @@ -569,20 +569,21 @@ export default async function build(dir: string, conf = null): Promise<void> {
)
staticCheckWorkers.end()

if (serverPropsPages.size > 0) {
if (serverPropsPages.size > 0 || ssgPages.size > 0) {
// We update the routes manifest after the build with the
// serverProps routes since we can't determine this until after build
routesManifest.serverPropsRoutes = {}

for (const page of serverPropsPages) {
// data routes since we can't determine these until after build
routesManifest.dataRoutes = getSortedRoutes([
...serverPropsPages,
...ssgPages,
]).map(page => {
const pagePath = normalizePagePath(page)
const dataRoute = path.posix.join(
'/_next/data',
buildId,
`${pagePath}.json`
)

routesManifest.serverPropsRoutes[page] = {
return {
page,
dataRouteRegex: isDynamicRoute(page)
? getRouteRegex(dataRoute.replace(/\.json$/, '')).re.source.replace(
Expand All @@ -597,7 +598,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
)}$`
).source,
}
}
})

await fsWriteFile(
routesManifestPath,
Expand Down
20 changes: 8 additions & 12 deletions packages/next/build/webpack/loaders/next-serverless-loader.ts
Expand Up @@ -93,26 +93,22 @@ const nextServerlessLoader: loader.Loader = function() {

const handleRewrites = `
const getCustomRouteMatcher = pathMatch(true)
const {prepareDestination} = require('next/dist/next-server/server/router')
function handleRewrites(parsedUrl) {
for (const rewrite of rewrites) {
const matcher = getCustomRouteMatcher(rewrite.source)
const params = matcher(parsedUrl.pathname)
if (params) {
parsedUrl.query = {
...parsedUrl.query,
...params
}
const parsedDest = parse(rewrite.destination)
const destCompiler = pathToRegexp.compile(
\`\${parsedDest.pathname}\${parsedDest.hash || ''}\`
const { parsedDestination } = prepareDestination(
rewrite.destination,
params
)
const newUrl = destCompiler(params)
const parsedNewUrl = parse(newUrl)
Object.assign(parsedUrl.query, parsedDestination.query, params)
delete parsedDestination.query
parsedUrl.pathname = parsedNewUrl.pathname
parsedUrl.hash = parsedNewUrl.hash
Object.assign(parsedUrl, parsedDestination)
if (parsedUrl.pathname === '${page}'){
break
Expand Down Expand Up @@ -170,7 +166,7 @@ const nextServerlessLoader: loader.Loader = function() {
`
: ''
}
const parsedUrl = parse(req.url, true)
const parsedUrl = handleRewrites(parse(req.url, true))
const params = ${
pageIsDynamicRoute
Expand Down

0 comments on commit 71cf5da

Please sign in to comment.