diff --git a/.circleci/config.yml b/.circleci/config.yml index d7621b77c1386..b10f6d1dfe2a2 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -35,12 +35,27 @@ commands: steps: - run: name: Installing Dependencies - command: yarn install --frozen-lockfile + command: yarn install --frozen-lockfile --check-files + - run: + name: Install correct Chrome Driver version + command: yarn add chromedriver@76 -W && git checkout yarn.lock package.json + - run: google-chrome --version + - run: chromedriver --version yarn_lint: steps: - run: name: Linting command: yarn lint + yarn_react_integration: + steps: + - run: + name: Upgrade to most recent release in React's Next channel + command: yarn upgrade react@next react-dom@next -W --dev # upgrade (vs add) will skip re-building Next.js, which doesn't bundle React internals (so this is OK!) + yarn_info: + steps: + - run: + name: React Versions + command: yarn why react && yarn why react-dom test_all: steps: - run: @@ -114,11 +129,18 @@ jobs: - yarn_install - yarn_lint - *persist_to_workspace + build-react-canary: + executor: node + steps: + - *attach_workspace + - yarn_react_integration + - *persist_to_workspace test: parallelism: 3 executor: node steps: - *attach_workspace + - yarn_info - test_all - *store_test_results test-ie11: @@ -196,3 +218,19 @@ workflows: only: - master - canary + q12h-react-canary: + triggers: + - schedule: + cron: '0 0,12 * * *' + filters: + branches: + only: + - canary + jobs: + - build + - build-react-canary: + requires: + - build + - test: + requires: + - build-react-canary diff --git a/README-zh-CN.md b/README-zh-CN.md index fb07b8038531f..9061ab8bb3677 100644 --- a/README-zh-CN.md +++ b/README-zh-CN.md @@ -133,7 +133,7 @@ export default () =>
Welcome to next.js!
- 自动打包编译 (使用 webpack 和 babel) - 热加载 - 以 `./pages`作为服务的渲染和索引 -- 静态文件服务. `./static/` 映射到 `/static/` (可以 [创建一个静态目录](#static-file-serving-eg-images) 在你的项目中) +- 静态文件服务. `./public/` 映射到 `/` (可以 [创建一个静态目录](#static-file-serving-eg-images) 在你的项目中) 这里有个简单的案例,可以下载看看 [sample app - nextgram](https://github.com/zeit/nextgram) @@ -227,13 +227,13 @@ export default () =>

hi there

### 静态文件服务(如图像) -在根目录下新建文件夹叫`static`。代码可以通过`/static/`来引入相关的静态资源。 +在根目录下新建文件夹叫`public`。代码可以通过`/`来引入相关的静态资源。 ```jsx -export default () => my image +export default () => my image ``` -_注意:不要自定义静态文件夹的名字,只能叫`static` ,因为只有这个名字 Next.js 才会把它当作静态资源。_ +_注意:不要自定义静态文件夹的名字,只能叫`public` ,因为只有这个名字 Next.js 才会把它当作静态资源。_ diff --git a/azure-pipelines.yml b/azure-pipelines.yml index cc39d77b375f1..fbb04609ca20b 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -4,6 +4,7 @@ pool: variables: NEXT_TELEMETRY_DISABLED: '1' YARN_CACHE_FOLDER: $(Pipeline.Workspace)/.yarn + CHROMEDRIVER_VERSION: '76.0.3809.68' strategy: maxParallel: 10 @@ -34,9 +35,13 @@ steps: displayName: Cache Yarn packages - script: | - yarn --frozen-lockfile --check-files + yarn install --frozen-lockfile --check-files displayName: 'Install dependencies' + - script: | + yarn add chromedriver@76 -W + displayName: 'Install correct Chrome Driver version' + - script: | node run-tests.js -c 2 -g $(group) displayName: 'Run tests' diff --git a/contributing.md b/contributing.md index c30376485a5b2..5d1c8eecf99bb 100644 --- a/contributing.md +++ b/contributing.md @@ -7,7 +7,7 @@ Our Commitment to Open Source can be found [here](https://zeit.co/blog/oss) 3. Install the dependencies: `yarn` 4. Run `yarn dev` to build and watch for code changes 5. In a new terminal, run `yarn types` to compile declaration files from TypeScript -6. The development branch is `canary`. On a release, the relevant parts of the changes in the `canary` branch are rebased into `master`. +6. The development branch is `canary` (this is the branch pull requests should be made against). On a release, the relevant parts of the changes in the `canary` branch are rebased into `master`. > You may need to run `yarn types` again if your types get outdated. diff --git a/errors/can-not-output-to-public.md b/errors/can-not-output-to-public.md new file mode 100644 index 0000000000000..5a266aeb8fc4c --- /dev/null +++ b/errors/can-not-output-to-public.md @@ -0,0 +1,15 @@ +# Cannot output to /public + +#### Why This Error Occurred + +Either you set `distDir` to `public` in your `next.config.js` or during `next export` you tried to export to the `public` directory. + +This is not allowed due to `public` being a special folder in Next.js used to serve static assets. + +#### Possible Ways to Fix It + +Use a different `distDir` or export to a different folder. + +### Useful Links + +- [Static file serving docs](https://nextjs.org/docs#static-file-serving-eg-images) diff --git a/errors/empty-object-getInitialProps.md b/errors/empty-object-getInitialProps.md index 75ccdcb68362d..da856d432162d 100644 --- a/errors/empty-object-getInitialProps.md +++ b/errors/empty-object-getInitialProps.md @@ -2,7 +2,7 @@ #### Why This Error Occurred -In one of your page components you added a `getInitialProps` that returned an empty object. This de-optimizes automatic prerendering. If you **meant** to do this and understand the **consequences** you can ignore this message as it is only shown in development. +In one of your page components you added a `getInitialProps` that returned an empty object. This de-optimizes automatic static optimization. If you **meant** to do this and understand the **consequences** you can ignore this message as it is only shown in development. #### Possible Ways to Fix It @@ -10,4 +10,4 @@ Look for any page's using `getInitialProps` that return an empty object `{}`. Yo ### Useful Links -- [Automatic Prerendering Documentation](https://nextjs.org/docs/#automatic-prerendering) +- [Automatic Static Optimization Documentation](https://nextjs.org/docs/#automatic-static-optimization) diff --git a/errors/global-css.md b/errors/global-css.md new file mode 100644 index 0000000000000..3fbe212aaab29 --- /dev/null +++ b/errors/global-css.md @@ -0,0 +1,11 @@ +# Global CSS Must Be in Your Custom + +#### Why This Error Occurred + +An attempt to import Global CSS from a file other than `pages/_app.js` was made. + +Global CSS cannot be used in files other than your Custom `` due to its side-effects and ordering problems. + +#### Possible Ways to Fix It + +Relocate all Global CSS imports to your `pages/_app.js` file. diff --git a/errors/no-cache.md b/errors/no-cache.md new file mode 100644 index 0000000000000..4c572f51237d6 --- /dev/null +++ b/errors/no-cache.md @@ -0,0 +1,76 @@ +# No Cache Detected + +#### Why This Error Occurred + +A Next.js build was triggered in a continuous integration environment, but no cache was detected. + +This results in slower builds and can hurt Next.js' persistent caching of client-side bundles across builds. + +#### Possible Ways to Fix It + +> **Note**: If this is a new project, or being built for the first time in your CI, you can ignore this error. +> However, you'll want to make sure it doesn't continue to happen and fix it if it does! + +Configure Next.js' cache to be persisted across builds. Next.js stores its cache in the `.next/cache` directory. + +Storing this folder across builds varies by CI provider. We've provided a list of a few common providers below. + +**ZEIT Now** + +Next.js caching is automatically configured for you. There's no action required on your part. + +**CircleCI** + +Edit your `save_cache` step in `.circleci/config.yml` to include `.next/cache`: + +```yaml +steps: + - save_cache: + key: dependency-cache-{{ checksum "yarn.lock" }} + paths: + - ./node_modules + - ./.next/cache +``` + +If you do not have a `save_cache` key, please follow CircleCI's [documentation on setting up build caching](https://circleci.com/docs/2.0/caching/). + +**Travis CI** + +Add or merge the following into your `.travis.yml`: + +```yaml +cache: + directories: + - $HOME/.cache/yarn + - node_modules + - .next/cache +``` + +**GitLab CI** + +Add or merge the following into your `.gitlab-ci.yml`: + +```yaml +cache: + key: ${CI_COMMIT_REF_SLUG} + paths: + - node_modules/ + - .next/cache/ +``` + +**Netlify CI** + +It is **not possible** to cache custom build files on Netlify. Please contact their support and request they support this behavior. + +You can investigate using a 3rd party solution (e.g. [`cache-me-outside`](https://github.com/DavidWells/cache-me-outside)) to manually cache the Next.js output. + +**AWS CodeBuild** + +Add (or merge in) the following to your `buildspec.yml`: + +```yaml +cache: + paths: + - 'node_modules/**/*' # Cache `node_modules` for faster `yarn` or `npm i` + - '.next/cache/**/*' # Cache Next.js for faster application rebuilds +``` diff --git a/errors/no-document-title.md b/errors/no-document-title.md index 53a3fa92a3d7b..62a3cc5d88b0f 100644 --- a/errors/no-document-title.md +++ b/errors/no-document-title.md @@ -10,7 +10,7 @@ Set `` in `pages/_app.js` instead: ```js // pages/_app.js -import App, { Container } from 'next/app' +import App from 'next/app' import Head from 'next/head' import React from 'react' @@ -29,12 +29,12 @@ export default class MyApp extends App { const { Component, pageProps } = this.props return ( - <Container> + <> <Head> <title>My new cool app - + ) } } diff --git a/errors/opt-out-auto-static-optimization.md b/errors/opt-out-auto-static-optimization.md new file mode 100644 index 0000000000000..afe98e98df4ef --- /dev/null +++ b/errors/opt-out-auto-static-optimization.md @@ -0,0 +1,35 @@ +# Opt-out of Automatic Static Optimization + +#### Why This Warning Occurred + +You are using `getInitialProps` in your [Custom ``](https://nextjs.org/docs#custom-app). + +This causes **all pages** to be executed on the server -- disabling [Automatic Static Optimization](https://nextjs.org/docs#automatic-static-optimization). + +#### Possible Ways to Fix It + +Be sure you meant to use `getInitialProps` in `pages/_app`! +There are some valid use cases for this, but it is often better to handle `getInitialProps` on a _per-page_ basis. + +If you previously copied the [Custom ``](https://nextjs.org/docs#custom-app) example, you may be able to remove your `getInitialProps`. + +The following `getInitialProps` does nothing and may be removed: + +```js +class MyApp extends App { + // Remove me, I do nothing! + static async getInitialProps({ Component, ctx }) { + let pageProps = {} + + if (Component.getInitialProps) { + pageProps = await Component.getInitialProps(ctx) + } + + return { pageProps } + } + + render() { + // ... + } +} +``` diff --git a/errors/opt-out-automatic-prerendering.md b/errors/opt-out-automatic-prerendering.md index a8613b1dfcc01..afe98e98df4ef 100644 --- a/errors/opt-out-automatic-prerendering.md +++ b/errors/opt-out-automatic-prerendering.md @@ -1,10 +1,10 @@ -# Opt-out of Automatic Prerendering +# Opt-out of Automatic Static Optimization #### Why This Warning Occurred You are using `getInitialProps` in your [Custom ``](https://nextjs.org/docs#custom-app). -This causes **all pages** to be executed on the server -- disabling [Automatic Prerendering](https://nextjs.org/docs#automatic-prerendering). +This causes **all pages** to be executed on the server -- disabling [Automatic Static Optimization](https://nextjs.org/docs#automatic-static-optimization). #### Possible Ways to Fix It diff --git a/errors/page-without-valid-component.md b/errors/page-without-valid-component.md index 31f7e7f464837..9344b712c9dbb 100644 --- a/errors/page-without-valid-component.md +++ b/errors/page-without-valid-component.md @@ -2,8 +2,15 @@ #### Why This Error Occurred -While auto exporting a page a valid React Component wasn't found. This could mean you have a file in `pages` that exports something that is not a React Component. +A page that does not export a valid React Component was found while analyzing the build output. + +This is a hard error because the page would error when rendered, and causes poor build performance. #### Possible Ways to Fix It -Move any non-page files that don't export a React Component as the default export to a different folder like `components` or `lib`. +Investigate the list of page(s) specified in the error message. +For each, you'll want to check if the file is meant to be a page. + +If the file is not meant to be a page, and instead, is a shared component or file, move the file to a different folder like `components` or `lib`. + +If the file is meant to be a page, double check you have an `export default` with the React Component instead of an `export`. If you're already using `export default`, make sure the returned valid is a valid React Component. diff --git a/errors/serverless-publicRuntimeConfig.md b/errors/serverless-publicRuntimeConfig.md index deb4ca5cecd93..800a1e664049a 100644 --- a/errors/serverless-publicRuntimeConfig.md +++ b/errors/serverless-publicRuntimeConfig.md @@ -1,8 +1,8 @@ -# Using `publicRuntimeConfig` with `target` set to `serverless` +# Using `publicRuntimeConfig` or `serverRuntimeConfig` with `target` set to `serverless` #### Why This Error Occurred -In the `serverless` target environment `next.config.js` is not loaded, so we don't support `publicRuntimeConfig`. +In the `serverless` target environment `next.config.js` is not loaded, so we don't support `publicRuntimeConfig` or `serverRuntimeConfig`. #### Possible Ways to Fix It diff --git a/errors/static-dir-deprecated.md b/errors/static-dir-deprecated.md new file mode 100644 index 0000000000000..303e7311c8b48 --- /dev/null +++ b/errors/static-dir-deprecated.md @@ -0,0 +1,38 @@ +# Static directory is deprecated + +#### Why This Error Occurred + +In versions prior to 9.0.6 the `static` directory was used to serve static assets in a Next.js application. This has been deprecated in favor of a `public` directory. + +The reason we want to support a `public` directory instead is to not require the `/static` prefix for assets anymore and there is no reason to maintain both paths. + +#### Possible Ways to Fix It + +You can move your `static` directory inside of the `public` directory and all URLs will remain the same as they were before. + +**Before** + +```sh +static/ + my-image.jpg +pages/ + index.js +components/ + my-image.js +``` + +**After** + +```sh +public/ + static/ + my-image.jpg +pages/ + index.js +components/ + my-image.js +``` + +### Useful Links + +- [Static file serving docs](https://nextjs.org/docs#static-file-serving-eg-images) diff --git a/examples/active-class-name/README.md b/examples/active-class-name/README.md index 6a11c34bd60cc..e4770280263c6 100644 --- a/examples/active-class-name/README.md +++ b/examples/active-class-name/README.md @@ -4,7 +4,7 @@ ### Using `create-next-app` -Execute [`create-next-app`](https://github.com/segmentio/create-next-app) with [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) or [npx](https://github.com/zkat/npx#readme) to bootstrap the example: +Execute [`create-next-app`](https://github.com/zeit/next.js/tree/canary/packages/create-next-app) with [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) or [npx](https://github.com/zkat/npx#readme) to bootstrap the example: ```bash npx create-next-app --example active-class-name active-class-name-app diff --git a/examples/amp-story/.gitignore b/examples/amp-story/.gitignore new file mode 100644 index 0000000000000..1f1d31514a8f2 --- /dev/null +++ b/examples/amp-story/.gitignore @@ -0,0 +1,3 @@ +.DS_Store +.next +node_modules diff --git a/examples/amp-story/README.md b/examples/amp-story/README.md new file mode 100644 index 0000000000000..d349cff030988 --- /dev/null +++ b/examples/amp-story/README.md @@ -0,0 +1,42 @@ +# Google AMP Story + +## How to use + +### Using `create-next-app` + +Execute [`create-next-app`](https://github.com/zeit/next.js/tree/canary/packages/create-next-app) with [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) or [npx](https://github.com/zkat/npx#readme) to bootstrap the example: + +```bash +npx create-next-app --example amp-story amp-app +# or +yarn create next-app --example amp-story amp-app +``` + +### Download manually + +Download the example: + +```bash +curl https://codeload.github.com/zeit/next.js/tar.gz/canary | tar -xz --strip=2 next.js-canary/examples/amp-story +cd amp-story +``` + +Install it and run: + +```bash +npm install +npm run dev +# or +yarn +yarn dev +``` + +Deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.co/download)) + +```bash +now +``` + +## The idea behind the example + +This example shows how to create an AMP page with `amp-story` using Next.js and the AMP feature. diff --git a/examples/amp-story/package.json b/examples/amp-story/package.json new file mode 100644 index 0000000000000..c5b61de231dd7 --- /dev/null +++ b/examples/amp-story/package.json @@ -0,0 +1,15 @@ +{ + "name": "amp-story", + "version": "1.0.0", + "scripts": { + "dev": "next", + "build": "next build", + "start": "next start" + }, + "dependencies": { + "next": "latest", + "react": "^16.7.0", + "react-dom": "^16.7.0" + }, + "license": "ISC" +} diff --git a/examples/amp-story/pages/index.js b/examples/amp-story/pages/index.js new file mode 100644 index 0000000000000..c0e09e4ee20c4 --- /dev/null +++ b/examples/amp-story/pages/index.js @@ -0,0 +1,123 @@ +import Head from 'next/head' + +export const config = { amp: true } + +export default () => ( + <> + + Example AMP Story in Next.js + + + + + + + diff --git a/examples/with-netlify-cms/public/static/img/1200px-whio_blue_duck_at_staglands_akatarawa_new_zealand.jpg b/examples/with-netlify-cms/public/static/img/1200px-whio_blue_duck_at_staglands_akatarawa_new_zealand.jpg new file mode 100644 index 0000000000000..44c1757cbc068 Binary files /dev/null and b/examples/with-netlify-cms/public/static/img/1200px-whio_blue_duck_at_staglands_akatarawa_new_zealand.jpg differ diff --git a/examples/with-netlify-cms/public/static/img/puppy-and-adult-dog.jpg b/examples/with-netlify-cms/public/static/img/puppy-and-adult-dog.jpg new file mode 100644 index 0000000000000..9a1b54c547dd5 Binary files /dev/null and b/examples/with-netlify-cms/public/static/img/puppy-and-adult-dog.jpg differ diff --git a/examples/with-netlify-cms/readme.md b/examples/with-netlify-cms/readme.md new file mode 100644 index 0000000000000..4ca2b0c5306f7 --- /dev/null +++ b/examples/with-netlify-cms/readme.md @@ -0,0 +1,51 @@ +# Example app using Netlify CMS + +## How to use + +### Using `create-next-app` + +Execute [`create-next-app`](https://github.com/segmentio/create-next-app) with [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) or [npx](https://github.com/zkat/npx#readme) to bootstrap the example: + +```bash +npx create-next-app --example with-netlify-cms with-netlify-cms-app +# or +yarn create next-app --example with-netlify-cms with-netlify-cms-app +``` + +### Download manually + +Download the example: + +```bash +curl https://codeload.github.com/zeit/next.js/tar.gz/canary | tar -xz --strip=2 next.js-canary/examples/with-netlify-cms +cd nested-components +``` + +Install it and run: + +```bash +npm install +npm run dev +# or +yarn +yarn dev +``` + +Deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.co/download)) + +```bash +now +``` + +## The idea behind the example + +[Netlify CMS](https://www.netlifycms.org/) is an open source content management system for your Git workflow that enables you to provide editors with a friendly UI and intuitive workflows. You can use it with any static site generator to create faster, more flexible web projects. Content is stored in your Git repository alongside your code for easier versioning, multi-channel publishing, and the option to handle content updates directly in Git. + +## How it works + +Sites take its content from markdown files in `/content`. Two of pages (`home` and `about`) are referencing directly their respective markdown files. + +Blog component loads all posts (during build!) and lists them out [How to load multiple md files](https://medium.com/@shawnstern/importing-multiple-markdown-files-into-a-react-component-with-webpack-7548559fce6f) + +Posts are separate static sites thanks to dynamically created export map. I took inspiration on how to do it from +[here](https://medium.com/@joranquinten/for-my-own-website-i-used-next-js-725678e65b09) diff --git a/examples/with-next-css/README.md b/examples/with-next-css/README.md index 69532d61f30fc..17c757ff577f1 100644 --- a/examples/with-next-css/README.md +++ b/examples/with-next-css/README.md @@ -4,7 +4,7 @@ ### Using `create-next-app` -Execute [`create-next-app`](https://github.com/segmentio/create-next-app) with [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) or [npx](https://github.com/zkat/npx#readme) to bootstrap the example: +Execute [`create-next-app`](https://github.com/zeit/next.js/tree/canary/packages/create-next-app) with [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) or [npx](https://github.com/zkat/npx#readme) to bootstrap the example: ```bash npx create-next-app --example with-next-css with-next-css-app diff --git a/examples/with-next-less/README.md b/examples/with-next-less/README.md index c6e9af0ef1af2..69c106fd236b2 100644 --- a/examples/with-next-less/README.md +++ b/examples/with-next-less/README.md @@ -4,7 +4,7 @@ ### Using `create-next-app` -Execute [`create-next-app`](https://github.com/segmentio/create-next-app) with [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) or [npx](https://github.com/zkat/npx#readme) to bootstrap the example: +Execute [`create-next-app`](https://github.com/zeit/next.js/tree/canary/packages/create-next-app) with [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) or [npx](https://github.com/zkat/npx#readme) to bootstrap the example: ```bash npx create-next-app --example with-next-less with-next-less-app diff --git a/examples/with-next-offline/README.md b/examples/with-next-offline/README.md new file mode 100644 index 0000000000000..680e93630ac79 --- /dev/null +++ b/examples/with-next-offline/README.md @@ -0,0 +1,46 @@ +# next-offline example + +## How to use + +### Using `create-next-app` + +Execute [`create-next-app`](https://github.com/zeit/next.js/tree/canary/packages/create-next-app) with [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) or [npx](https://github.com/zkat/npx#readme) to bootstrap the example: + +```bash +npx create-next-app --example with-next-offline with-next-offline-app +# or +yarn create next-app --example with-next-offline with-next-offline-app +``` + +### Download manually + +Download the example: + +```bash +curl https://codeload.github.com/zeit/next.js/tar.gz/canary | tar -xz --strip=2 next.js-canary/examples/with-next-offline +cd with-next-offline +``` + +Install it and run: + +```bash +npm install +npm run dev +npm run export +serve -s out +# or +yarn +yarn dev +yarn export +serve -s out +``` + +Deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.co/download)) + +```bash +now +``` + +## The idea behind the example + +This example demonstrates how to use the [next-offline plugin](https://github.com/hanford/next-offline) It includes manifest.json to install app via chrome diff --git a/examples/with-next-offline/next.config.js b/examples/with-next-offline/next.config.js new file mode 100644 index 0000000000000..c08c9bcf11297 --- /dev/null +++ b/examples/with-next-offline/next.config.js @@ -0,0 +1,5 @@ +const withOffline = require('next-offline') + +const nextConfig = {} + +module.exports = withOffline(nextConfig) diff --git a/examples/with-next-offline/package.json b/examples/with-next-offline/package.json new file mode 100644 index 0000000000000..356d8a0a38e55 --- /dev/null +++ b/examples/with-next-offline/package.json @@ -0,0 +1,18 @@ +{ + "name": "with-next-offline", + "version": "1.0.0", + "main": "index.js", + "scripts": { + "dev": "next", + "build": "next build", + "start": "next start", + "export": "next build && next export" + }, + "dependencies": { + "next": "latest", + "next-offline": "4.0.6", + "react": "^16.10.2", + "react-dom": "^16.10.2", + "serve": "11.2.0" + } +} diff --git a/examples/with-next-offline/pages/_document.js b/examples/with-next-offline/pages/_document.js new file mode 100644 index 0000000000000..7c0d43d24ed9e --- /dev/null +++ b/examples/with-next-offline/pages/_document.js @@ -0,0 +1,24 @@ +import Document, { Html, Head, Main, NextScript } from 'next/document' + +class MyDocument extends Document { + static async getInitialProps (ctx) { + const initialProps = await Document.getInitialProps(ctx) + return { ...initialProps } + } + + render () { + return ( + + + + + +
+ + + + ) + } +} + +export default MyDocument diff --git a/examples/with-next-offline/pages/index.js b/examples/with-next-offline/pages/index.js new file mode 100644 index 0000000000000..0e81e1203bd28 --- /dev/null +++ b/examples/with-next-offline/pages/index.js @@ -0,0 +1 @@ +export default () =>
Next-Offline Example, try to install app via chrome
diff --git a/examples/with-next-offline/public/manifest.json b/examples/with-next-offline/public/manifest.json new file mode 100644 index 0000000000000..c0aca31d4e549 --- /dev/null +++ b/examples/with-next-offline/public/manifest.json @@ -0,0 +1,16 @@ +{ + "name": "next-offline", + "short_name": "next-offline", + "description": "Nextjs using serveice worker via next-offline", + "icons": [ + { + "src": "/static/pwa.png", + "sizes": "192x192", + "type": "image/png" + } + ], + "theme_color": "#ffffff", + "background_color": "#ffffff", + "start_url": "/", + "display": "standalone" +} \ No newline at end of file diff --git a/examples/with-next-offline/public/static/pwa.png b/examples/with-next-offline/public/static/pwa.png new file mode 100644 index 0000000000000..2b1536f62043f Binary files /dev/null and b/examples/with-next-offline/public/static/pwa.png differ diff --git a/examples/with-next-page-transitions/README.md b/examples/with-next-page-transitions/README.md index f951275dbb744..14c0b254a8385 100644 --- a/examples/with-next-page-transitions/README.md +++ b/examples/with-next-page-transitions/README.md @@ -4,7 +4,7 @@ ### Using `create-next-app` -Execute [`create-next-app`](https://github.com/segmentio/create-next-app) with [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) or [npx](https://github.com/zkat/npx#readme) to bootstrap the example: +Execute [`create-next-app`](https://github.com/zeit/next.js/tree/canary/packages/create-next-app) with [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) or [npx](https://github.com/zkat/npx#readme) to bootstrap the example: ```bash npx create-next-app --example with-next-page-transitions with-next-page-transitions diff --git a/examples/with-next-routes/README.md b/examples/with-next-routes/README.md index 1da4696e14b9d..537a8f8561321 100644 --- a/examples/with-next-routes/README.md +++ b/examples/with-next-routes/README.md @@ -4,7 +4,7 @@ ### Using `create-next-app` -Execute [`create-next-app`](https://github.com/segmentio/create-next-app) with [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) or [npx](https://github.com/zkat/npx#readme) to bootstrap the example: +Execute [`create-next-app`](https://github.com/zeit/next.js/tree/canary/packages/create-next-app) with [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) or [npx](https://github.com/zkat/npx#readme) to bootstrap the example: ```bash npx create-next-app --example with-next-routes with-next-routes-app diff --git a/examples/with-next-sass/README.md b/examples/with-next-sass/README.md index dd6469d57f617..4a8541f1c0895 100644 --- a/examples/with-next-sass/README.md +++ b/examples/with-next-sass/README.md @@ -4,7 +4,7 @@ ### Using `create-next-app` -Execute [`create-next-app`](https://github.com/segmentio/create-next-app) with [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) or [npx](https://github.com/zkat/npx#readme) to bootstrap the example: +Execute [`create-next-app`](https://github.com/zeit/next.js/tree/canary/packages/create-next-app) with [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) or [npx](https://github.com/zkat/npx#readme) to bootstrap the example: ```bash npx create-next-app --example with-next-sass with-next-sass-app diff --git a/examples/with-next-sass/pages/_document.js b/examples/with-next-sass/pages/_document.js deleted file mode 100644 index 58fa5204afbc3..0000000000000 --- a/examples/with-next-sass/pages/_document.js +++ /dev/null @@ -1,15 +0,0 @@ -import Document, { Head, Main, NextScript } from 'next/document' - -export default class MyDocument extends Document { - render () { - return ( - - - -
- - - - ) - } -} diff --git a/examples/with-next-seo/README.md b/examples/with-next-seo/README.md index 14e14ae8ca7a5..5b8c023e939b3 100644 --- a/examples/with-next-seo/README.md +++ b/examples/with-next-seo/README.md @@ -4,7 +4,7 @@ ### Using `create-next-app` -Execute [`create-next-app`](https://github.com/segmentio/create-next-app) with [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) or [npx](https://github.com/zkat/npx#readme) to bootstrap the example: +Execute [`create-next-app`](https://github.com/zeit/next.js/tree/canary/packages/create-next-app) with [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) or [npx](https://github.com/zkat/npx#readme) to bootstrap the example: ```bash npx create-next-app --example with-next-seo next-seo-app diff --git a/examples/with-noscript/README.md b/examples/with-noscript/README.md index e873a17089546..51c08194f8f8e 100644 --- a/examples/with-noscript/README.md +++ b/examples/with-noscript/README.md @@ -4,7 +4,7 @@ ### Using `create-next-app` -Execute [`create-next-app`](https://github.com/segmentio/create-next-app) with [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) or [npx](https://github.com/zkat/npx#readme) to bootstrap the example: +Execute [`create-next-app`](https://github.com/zeit/next.js/tree/canary/packages/create-next-app) with [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) or [npx](https://github.com/zkat/npx#readme) to bootstrap the example: ```bash npx create-next-app --example with-noscript with-noscript-app diff --git a/examples/with-noscript/components/Noscript.js b/examples/with-noscript/components/Noscript.js index 6dc373552ef3d..32eed3bae2fc1 100644 --- a/examples/with-noscript/components/Noscript.js +++ b/examples/with-noscript/components/Noscript.js @@ -1,7 +1,15 @@ import React from 'react' -import ReactDOMServer from 'react-dom/server' -export default function Noscript (props) { - const staticMarkup = ReactDOMServer.renderToStaticMarkup(props.children) +// We don't want to send 'react-dom/server' to the client +let ReactDOMServer +if (typeof window === 'undefined') { + ReactDOMServer = require('react-dom/server') +} + +export default function Noscript ({ children }) { + if (!ReactDOMServer) { + return null + } + const staticMarkup = ReactDOMServer.renderToStaticMarkup(children) return