Skip to content

Commit

Permalink
Merge branch 'canary' into types/sass
Browse files Browse the repository at this point in the history
  • Loading branch information
Timer authored Feb 3, 2020
2 parents 46409d9 + f7880f3 commit fdb31a7
Show file tree
Hide file tree
Showing 52 changed files with 755 additions and 112 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/build_test_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ jobs:
with:
path: '.'
key: ${{ github.sha }}

# TODO: remove after we fix watchpack watching too much
- run: echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p

- run: node run-tests.js --timings -g ${{ matrix.group }}/6 -c 3

testsPass:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/test_react_next.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,7 @@ jobs:

- run: yarn upgrade react@next react-dom@next -W --dev

# TODO: remove after we fix watchpack watching too much
- run: echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p

- run: node run-tests.js --timings -g ${{ matrix.group }}/6 -c 3
15 changes: 15 additions & 0 deletions errors/404-get-initial-props.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# 404.js Cannot Have getInitialProps

#### 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.

#### Possible Ways to Fix It

Remove `getInitialProps` from `404.js` and make sure no HOC's used in `404.js` attach `getInitialProps`.

If you want to fetch data for your `404.js` page move it to a client side fetch inside of `componentDidMount` or `useEffect(() => {}, [])`.

### Useful Links

- [Automatic Static Optimization](https://nextjs.org/docs/advanced-features/automatic-static-optimization)
23 changes: 0 additions & 23 deletions errors/serverless-publicRuntimeConfig.md

This file was deleted.

2 changes: 1 addition & 1 deletion examples/using-preact/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Preact example

This example uses [Preact](https://github.com/developit/preact) instead of React. It's a React like UI framework which is fast and small. Here we've customized Next.js to use Preact instead of React.
This example uses [Preact](https://github.com/preactjs/preact) instead of React. It's a React like UI framework which is fast and small. Here we've customized Next.js to use Preact instead of React.

Here's how we did it:

Expand Down
4 changes: 2 additions & 2 deletions examples/using-preact/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"dependencies": {
"module-alias": "2.2.2",
"next": "latest",
"preact": "10.0.0",
"preact-render-to-string": "5.0.7"
"preact": "10.2.1",
"preact-render-to-string": "5.1.4"
},
"license": "ISC",
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion examples/with-firebase-hosting/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"preserve": "npm run build-public && npm run build-funcs && npm run build-app && npm run copy-deps && npm run install-deps",
"serve": "cross-env NODE_ENV=production firebase serve",
"predeploy": "npm run build-public && npm run build-funcs && npm run build-app && npm run copy-deps",
"deploy": "firebase deploy",
"deploy": "NODE_ENV=production firebase deploy",
"clean": "rimraf \"dist/functions/**\" && rimraf \"dist/public\"",
"build-public": "cpx \"src/public/**/*.*\" \"dist/public\" -C",
"build-funcs": "babel \"src/functions\" --out-dir \"dist/functions\"",
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
"registry": "https://registry.npmjs.org/"
}
},
"version": "9.2.2-canary.4"
"version": "9.2.2-canary.7"
}
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": "9.2.2-canary.4",
"version": "9.2.2-canary.7",
"keywords": [
"react",
"next",
Expand Down
15 changes: 6 additions & 9 deletions packages/create-next-app/templates/default/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ After creating an app, it should look something like:
```
.
├── README.md
├── components
│ ├── head.js
│ └── nav.js
├── node_modules
│ ├── [...]
├── package.json
Expand All @@ -54,7 +51,7 @@ Out of the box, we get:
- Server rendering and indexing of `./pages/`
- Static file serving. `./public/` is mapped to `/`

Read more about [Next's Routing](https://github.com/zeit/next.js#routing)
Read more about [Next's Routing](https://nextjs.org/docs/routing/introduction)

## Available Scripts

Expand All @@ -78,7 +75,7 @@ It correctly bundles React in production mode and optimizes the build for the be
Starts the application in production mode.
The application should be compiled with \`next build\` first.

See the section in Next docs about [deployment](https://github.com/zeit/next.js/wiki/Deployment) for more information.
See the section in Next docs about [deployment](https://nextjs.org/docs/deployment) for more information.

## Using CSS

Expand Down Expand Up @@ -107,7 +104,7 @@ export default () => (
)
```

Read more about [Next's CSS features](https://github.com/zeit/next.js#css).
Read more about [Next's CSS features](https://nextjs.org/docs/basic-features/built-in-css-support).

## Adding Components

Expand Down Expand Up @@ -147,15 +144,15 @@ For the initial page load, `getInitialProps` will execute on the server only. `g

_Note: `getInitialProps` can **not** be used in children components. Only in `./pages/`._

Read more about [fetching data and the component lifecycle](https://github.com/zeit/next.js#fetching-data-and-component-lifecycle)
Read more about [fetching data and the component lifecycle](https://nextjs.org/docs/basic-features/data-fetching)

## Syntax Highlighting

To configure the syntax highlighting in your favorite text editor, head to the [relevant Babel documentation page](https://babeljs.io/docs/editors) and follow the instructions. Some of the most popular editors are covered.

## Deploy to Now

[now](https://zeit.co/now) offers a zero-configuration single-command deployment.
[ZEIT Now](https://zeit.co/home?utm_source=create-next-app&utm_medium=referral&utm_campaign=Create%20Next%20App) offers a zero-configuration single-command deployment.

1. Install the `now` command-line tool either via npm `npm install -g now` or Yarn `yarn global add now`.

Expand All @@ -167,7 +164,7 @@ To configure the syntax highlighting in your favorite text editor, head to the [
Paste that URL into your browser when the build is complete, and you will see your deployed app.
You can find more details about [`now` here](https://zeit.co/now).
You can find more details about [`ZEIT Now` here](https://zeit.co/home?utm_source=create-next-app&utm_medium=referral&utm_campaign=Create%20Next%20App).
## Something Missing?
Expand Down
11 changes: 9 additions & 2 deletions packages/create-next-app/templates/default/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ const Home = () => (
<p>Discover and deploy boilerplate example Next.js projects.</p>
</a>

<a href="https://zeit.co/new/nextjs" className="card">
<a
href="https://zeit.co/new?utm_source=create-next-app&utm_medium=referral&utm_campaign=Create%20Next%20App"
className="card"
>
<h3>Deploy &rarr;</h3>
<p>
Instantly deploy your Next.js site to a public URL with ZEIT Now.
Expand All @@ -46,7 +49,11 @@ const Home = () => (
</main>

<footer>
<a href="https://zeit.co" target="_blank" rel="noopener noreferrer">
<a
href="https://zeit.co?utm_source=create-next-app&utm_medium=referral&utm_campaign=Create%20Next%20App"
target="_blank"
rel="noopener noreferrer"
>
Powered by <img src="/zeit.svg" alt="ZEIT Logo" />
</a>
</footer>
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": "9.2.2-canary.4",
"version": "9.2.2-canary.7",
"main": "index.js",
"license": "MIT",
"repository": {
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": "9.2.2-canary.4",
"version": "9.2.2-canary.7",
"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": "9.2.2-canary.4",
"version": "9.2.2-canary.7",
"nextjs": {
"name": "Google Analytics",
"required-env": [
Expand Down
2 changes: 1 addition & 1 deletion packages/next-plugin-material-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/plugin-material-ui",
"version": "9.2.2-canary.4",
"version": "9.2.2-canary.7",
"nextjs": {
"name": "Material UI",
"required-env": []
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": "9.2.2-canary.4",
"version": "9.2.2-canary.7",
"nextjs": {
"name": "Sentry",
"required-env": [
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": "9.2.2-canary.4",
"version": "9.2.2-canary.7",
"description": "A polyfill for non-dead, nomodule browsers.",
"main": "dist/polyfill-nomodule.js",
"license": "MIT",
Expand Down
10 changes: 10 additions & 0 deletions packages/next/build/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ export function createEntrypoints(
const client: WebpackEntrypoints = {}
const server: WebpackEntrypoints = {}

const hasRuntimeConfig =
Object.keys(config.publicRuntimeConfig).length > 0 ||
Object.keys(config.serverRuntimeConfig).length > 0

const defaultServerlessOptions = {
absoluteAppPath: pages['/_app'],
absoluteDocumentPath: pages['/_document'],
Expand All @@ -77,6 +81,12 @@ export function createEntrypoints(
generateEtags: config.generateEtags,
canonicalBase: config.canonicalBase,
basePath: config.experimental.basePath,
runtimeConfig: hasRuntimeConfig
? JSON.stringify({
publicRuntimeConfig: config.publicRuntimeConfig,
serverRuntimeConfig: config.serverRuntimeConfig,
})
: '',
}

Object.keys(pages).forEach(page => {
Expand Down
28 changes: 24 additions & 4 deletions packages/next/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ import checkCustomRoutes, {
Rewrite,
Header,
} from '../lib/check-custom-routes'
import { PUBLIC_DIR_MIDDLEWARE_CONFLICT } from '../lib/constants'
import {
PUBLIC_DIR_MIDDLEWARE_CONFLICT,
PAGES_404_GET_INITIAL_PROPS_ERROR,
} from '../lib/constants'
import { findPagesDir } from '../lib/find-pages-dir'
import { recursiveDelete } from '../lib/recursive-delete'
import { recursiveReadDir } from '../lib/recursive-readdir'
Expand Down Expand Up @@ -202,6 +205,10 @@ export default async function build(dir: string, conf = null): Promise<void> {
const hasCustomErrorPage = mappedPages['/_error'].startsWith(
'private-next-pages'
)
const hasPages404 =
config.experimental.pages404 &&
mappedPages['/404'] &&
mappedPages['/404'].startsWith('private-next-pages')

if (hasPublicDir) {
try {
Expand Down Expand Up @@ -262,6 +269,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
const routesManifestPath = path.join(distDir, ROUTES_MANIFEST)
const routesManifest: any = {
version: 1,
pages404: !!hasPages404,
basePath: config.experimental.basePath,
redirects: redirects.map(r => buildCustomRoute(r, 'redirect')),
rewrites: rewrites.map(r => buildCustomRoute(r, 'rewrite')),
Expand Down Expand Up @@ -511,6 +519,17 @@ export default async function build(dir: string, conf = null): Promise<void> {
staticPages.add(page)
isStatic = true
}

if (hasPages404 && page === '/404') {
if (!result.isStatic) {
throw new Error(PAGES_404_GET_INITIAL_PROPS_ERROR)
}
// we need to ensure the 404 lambda is present since we use
// it when _app has getInitialProps
if (customAppGetInitialProps) {
staticPages.delete(page)
}
}
} catch (err) {
if (err.message !== 'INVALID_DEFAULT_EXPORT') throw err
invalidPages.add(page)
Expand Down Expand Up @@ -569,8 +588,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
// Only export the static 404 when there is no /_error present
const useStatic404 =
!customAppGetInitialProps &&
!hasCustomErrorPage &&
config.experimental.static404
((!hasCustomErrorPage && config.experimental.static404) || hasPages404)

if (invalidPages.size > 0) {
throw new Error(
Expand Down Expand Up @@ -640,7 +658,9 @@ export default async function build(dir: string, conf = null): Promise<void> {
})

if (useStatic404) {
defaultMap['/_errors/404'] = { page: '/_error' }
defaultMap['/_errors/404'] = {
page: hasPages404 ? '/404' : '/_error',
}
}

return defaultMap
Expand Down
8 changes: 3 additions & 5 deletions packages/next/build/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -592,11 +592,9 @@ export async function isPageStatic(

builtPage = builtPage.replace(
`[${repeat ? '...' : ''}${validParamKey}]`,
encodeURIComponent(
repeat
? (paramValue as string[]).join('/')
: (paramValue as string)
)
repeat
? (paramValue as string[]).map(encodeURIComponent).join('/')
: encodeURIComponent(paramValue as string)
)
})

Expand Down
Loading

0 comments on commit fdb31a7

Please sign in to comment.