Skip to content

Commit

Permalink
Merge branch 'canary' into referrer
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Nov 15, 2021
2 parents 1c35fa8 + 8c84b4a commit 1437f26
Show file tree
Hide file tree
Showing 73 changed files with 2,175 additions and 163 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Expand Up @@ -24,6 +24,7 @@ packages/next-codemod/**/*.d.ts
packages/next-env/**/*.d.ts
packages/create-next-app/templates/**
test/integration/eslint/**
test/development/basic/legacy-decorators/**/*
test-timings.json
packages/next/build/swc/tests/**
bench/nested-deps/pages/**
Expand Down
2 changes: 1 addition & 1 deletion docs/api-reference/data-fetching/getInitialProps.md
Expand Up @@ -139,6 +139,6 @@ For more information on what to do next, we recommend the following sections:
<div class="card">
<a href="/docs/advanced-features/automatic-static-optimization.md">
<b>Automatic Static Optimization:</b>
<small>Learn about how Nextjs automatically optimizes your pages.</small>
<small>Learn about how Next.js automatically optimizes your pages.</small>
</a>
</div>
2 changes: 1 addition & 1 deletion docs/api-reference/next.config.js/headers.md
Expand Up @@ -365,7 +365,7 @@ module.exports = {
headers: [
{
key: 'x-hello',
value: 'worlld',
value: 'world',
},
],
},
Expand Down
2 changes: 1 addition & 1 deletion docs/api-reference/next/image.md
Expand Up @@ -123,7 +123,7 @@ If you are using `layout="fill"` or `layout="responsive"`, it's important to ass

For example, when the parent element will constrain the image to always be less than half the viewport width, use `sizes="50vw"`. Without `sizes`, the image will be sent at twice the necessary resolution, decreasing performance.

If you are using `layout="intrinsic"` or `layout="fixed"`, then `sizes` is not needed because the upperbound width is constrained already.
If you are using `layout="intrinsic"` or `layout="fixed"`, then `sizes` is not needed because the upper bound width is constrained already.

[Learn more](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#attr-sizes).

Expand Down
2 changes: 1 addition & 1 deletion docs/basic-features/data-fetching.md
Expand Up @@ -68,7 +68,7 @@ The `context` parameter is an object containing the following keys:
- `previewData` contains the preview data set by `setPreviewData`. See the [Preview Mode documentation](/docs/advanced-features/preview-mode.md).
- `locale` contains the active locale (if you've enabled [Internationalized Routing](/docs/advanced-features/i18n-routing.md)).
- `locales` contains all supported locales (if you've enabled [Internationalized Routing](/docs/advanced-features/i18n-routing.md)).
- `defaultLocale` contains the configured default locale (if you've enabled Internationalized Routing).
- `defaultLocale` contains the configured default locale (if you've enabled [Internationalized Routing](/docs/advanced-features/i18n-routing.md)).

`getStaticProps` should return an object with:

Expand Down
2 changes: 1 addition & 1 deletion docs/basic-features/image-optimization.md
Expand Up @@ -187,7 +187,7 @@ The recommended way to style the inner `<img>` is to set the `className` prop on

Alternatively, you can import a [global stylesheet](/docs/basic-features/built-in-css-support#adding-a-global-stylesheet) and manually set the `className` prop to the same name used in the global stylesheet.

You cannot use [styled-jsx](/basic-features/built-in-css-support.md#css-in-js) because its scoped to the current component.
You cannot use [styled-jsx](/docs/basic-features/built-in-css-support.md#css-in-js) because it's scoped to the current component.

You cannot use the `style` prop because the `<Image>` component does not pass it through to the underlying `<img>`.

Expand Down
2 changes: 1 addition & 1 deletion docs/testing.md
Expand Up @@ -114,7 +114,7 @@ Since Cypress is testing a real Next.js application, it requires the Next.js ser

Run `npm run build` and `npm run start`, then run `npm run cypress` in another terminal window to start Cypress.

> **Note:** Alternatively, you can install the `start-server-and-test` package and add it to the `package.json` scripts field: `"test": "start-server-and-test start http://localhost:3000 cypress"` to start the Next.js production server in conjuction with Cypress. Remember to rebuild your application after new changes.
> **Note:** Alternatively, you can install the `start-server-and-test` package and add it to the `package.json` scripts field: `"test": "start-server-and-test start http://localhost:3000 cypress"` to start the Next.js production server in conjunction with Cypress. Remember to rebuild your application after new changes.
### Getting ready for Continuous Integration (CI)

Expand Down
4 changes: 4 additions & 0 deletions errors/manifest.json
Expand Up @@ -339,6 +339,10 @@
"title": "no-router-instance",
"path": "/errors/no-router-instance.md"
},
{
"title": "no-server-import-in-page",
"path": "/errors/no-server-import-in-page.md"
},
{
"title": "no-sync-scripts",
"path": "/errors/no-sync-scripts.md"
Expand Down
23 changes: 23 additions & 0 deletions errors/no-server-import-in-page.md
@@ -0,0 +1,23 @@
# No Server Import In Page

### Why This Error Occurred

`next/server` was imported in a page outside of `pages/_middleware.js` (or `pages/_middleware.tsx` if you are using TypeScript)

### Possible Ways to Fix It

Only import and use `next/server` within `pages/_middleware.js` (or `pages/_middleware.tsx`) to add middlewares.

```jsx
// pages/_middleware.ts

import type { NextFetchEvent, NextRequest } from 'next/server'

export function middleware(req: NextRequest, ev: NextFetchEvent) {
return new Response('Hello, world!')
}
```

### Useful Links

- [Middleware](https://nextjs.org/docs/middleware)
4 changes: 2 additions & 2 deletions examples/with-google-analytics/README.md
@@ -1,6 +1,6 @@
# Example app with analytics

This example shows how to use [Next.js](https://github.com/vercel/next.js) along with [Google Analytics](https://developers.google.com/analytics/devguides/collection/gtagjs/). A custom [\_document](https://nextjs.org/docs/advanced-features/custom-document) is used to inject [tracking snippet](https://developers.google.com/analytics/devguides/collection/gtagjs/) and track [pageviews](https://developers.google.com/analytics/devguides/collection/gtagjs/pages) and [event](https://developers.google.com/analytics/devguides/collection/gtagjs/events).
This example shows how to use [Next.js](https://github.com/vercel/next.js) along with [Google Analytics](https://developers.google.com/analytics/devguides/collection/gtagjs/). A custom [\_app](https://nextjs.org/docs/advanced-features/custom-app) is used to inject [tracking snippet](https://developers.google.com/analytics/devguides/collection/gtagjs/) and track [pageviews](https://developers.google.com/analytics/devguides/collection/gtagjs/pages) and [event](https://developers.google.com/analytics/devguides/collection/gtagjs/events).

## Deploy your own

Expand All @@ -10,7 +10,7 @@ Deploy the example using [Vercel](https://vercel.com?utm_source=github&utm_mediu

## How to use

Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init) or [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) to bootstrap the example::
Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init) or [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) to bootstrap the example:

```bash
npx create-next-app --example with-google-analytics with-google-analytics-app
Expand Down
35 changes: 35 additions & 0 deletions examples/with-playwright/.gitignore
@@ -0,0 +1,35 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env.local
.env.development.local
.env.test.local
.env.production.local

# vercel
.vercel
test-results/
27 changes: 27 additions & 0 deletions examples/with-playwright/README.md
@@ -0,0 +1,27 @@
# Next.js + Playwright

This example shows how to configure Playwright to work with Next.js.

## Preview

Preview the example live on [StackBlitz](http://stackblitz.com/):

[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/vercel/next.js/tree/canary/examples/with-playwright)

## Deploy your own

Deploy the example using [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=next-example):

[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/git/external?repository-url=https://github.com/vercel/next.js/tree/canary/examples/with-playwright&project-name=with-playwright&repository-name=with-playwright)

## How to use

Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init) or [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) to bootstrap the example:

```bash
npx create-next-app --example with-playwright with-playwright-app
# or
yarn create next-app --example with-playwright with-playwright-app
```

Deploy it to the cloud with [Vercel](https://vercel.com/new?utm_source=github&utm_medium=readme&utm_campaign=next-example) ([Documentation](https://nextjs.org/docs/deployment)).
12 changes: 12 additions & 0 deletions examples/with-playwright/e2e/example.spec.ts
@@ -0,0 +1,12 @@
import { test, expect } from '@playwright/test'

test('should navigate to the about page', async ({ page }) => {
// Start from the index page (the baseURL is set via the webServer in the playwright.config.ts)
await page.goto('/')
// Find an element with the text 'About Page' and click on it
await page.click('text=About Page')
// The new url should be "/about" (baseURL is used there)
await expect(page).toHaveURL('/about')
// The new page should contain an h1 with "About Page"
await expect(page.locator('h1')).toContainText('About Page')
})
17 changes: 17 additions & 0 deletions examples/with-playwright/package.json
@@ -0,0 +1,17 @@
{
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"test:e2e": "playwright test"
},
"dependencies": {
"next": "latest",
"react": "17.0.2",
"react-dom": "17.0.2"
},
"devDependencies": {
"@playwright/test": "^1.15.0"
}
}
7 changes: 7 additions & 0 deletions examples/with-playwright/pages/_app.js
@@ -0,0 +1,7 @@
import '../styles/globals.css'

function MyApp({ Component, pageProps }) {
return <Component {...pageProps} />
}

export default MyApp
17 changes: 17 additions & 0 deletions examples/with-playwright/pages/about.js
@@ -0,0 +1,17 @@
import styles from '../styles/Home.module.css'
import Link from 'next/link'

export default function About() {
return (
<div className={styles.container}>
<main className={styles.main}>
<h1>About Page</h1>
<p className={styles.description}>
<Link href="/">
<a>&larr; Go Back</a>
</Link>
</p>
</main>
</div>
)
}
77 changes: 77 additions & 0 deletions examples/with-playwright/pages/index.js
@@ -0,0 +1,77 @@
import Head from 'next/head'
import Image from 'next/image'
import Link from 'next/link'
import styles from '../styles/Home.module.css'

export default function Home() {
return (
<div className={styles.container}>
<Head>
<title>Create Next App</title>
<meta name="description" content="Generated by create next app" />
<link rel="icon" href="/favicon.ico" />
</Head>

<main className={styles.main}>
<h1 className={styles.title}>
Welcome to <a href="https://nextjs.org">Next.js!</a>
</h1>

<p className={styles.description}>
Get started by editing{' '}
<code className={styles.code}>pages/index.js</code>
</p>

<div className={styles.grid}>
<Link href="/about">
<a className={styles.card}>
<h2>About Page &rarr;</h2>
<p>Playwright will test if this link is working.</p>
</a>
</Link>

<a href="https://nextjs.org/docs" className={styles.card}>
<h2>Documentation &rarr;</h2>
<p>Find in-depth information about Next.js features and API.</p>
</a>

<a href="https://nextjs.org/learn" className={styles.card}>
<h2>Learn &rarr;</h2>
<p>Learn about Next.js in an interactive course with quizzes!</p>
</a>

<a
href="https://github.com/vercel/next.js/tree/master/examples"
className={styles.card}
>
<h2>Examples &rarr;</h2>
<p>Discover and deploy boilerplate example Next.js projects.</p>
</a>

<a
href="https://vercel.com/new?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
className={styles.card}
>
<h2>Deploy &rarr;</h2>
<p>
Instantly deploy your Next.js site to a public URL with Vercel.
</p>
</a>
</div>
</main>

<footer className={styles.footer}>
<a
href="https://vercel.com?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
Powered by{' '}
<span className={styles.logo}>
<Image src="/vercel.svg" alt="Vercel Logo" width={72} height={16} />
</span>
</a>
</footer>
</div>
)
}
67 changes: 67 additions & 0 deletions examples/with-playwright/playwright.config.ts
@@ -0,0 +1,67 @@
import { PlaywrightTestConfig, devices } from '@playwright/test'
import path from 'path'

// Reference: https://playwright.dev/docs/test-configuration
const config: PlaywrightTestConfig = {
// Timeout per test
timeout: 30 * 1000,
// Test directory
testDir: path.join(__dirname, 'e2e'),
// If a test fails, retry it additional 2 times
retries: 2,
// Artifacts folder where screenshots, videos, and traces are stored.
outputDir: 'test-results/',

// Run your local dev server before starting the tests:
// https://playwright.dev/docs/test-advanced#launching-a-development-web-server-during-the-tests
webServer: {
command: 'npm run dev',
port: 3000,
timeout: 120 * 1000,
reuseExistingServer: !process.env.CI,
},

use: {
// Retry a test if its failing with enabled tracing. This allows you to analyse the DOM, console logs, network traffic etc.
// More information: https://playwright.dev/docs/trace-viewer
trace: 'retry-with-trace',

// All available context options: https://playwright.dev/docs/api/class-browser#browser-new-context
// contextOptions: {
// ignoreHTTPSErrors: true,
// },
},

projects: [
{
name: 'Desktop Chrome',
use: {
...devices['Desktop Chrome'],
},
},
// {
// name: 'Desktop Firefox',
// use: {
// ...devices['Desktop Firefox'],
// },
// },
// {
// name: 'Desktop Safari',
// use: {
// ...devices['Desktop Safari'],
// },
// },
// Test against mobile viewports.
{
name: 'Mobile Chrome',
use: {
...devices['Pixel 5'],
},
},
{
name: 'Mobile Safari',
use: devices['iPhone 12'],
},
],
}
export default config
Binary file added examples/with-playwright/public/favicon.ico
Binary file not shown.
4 changes: 4 additions & 0 deletions examples/with-playwright/public/vercel.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 1437f26

Please sign in to comment.