Skip to content

Commit

Permalink
Merge branch 'canary' into examples/cms-wordpress-migrate-to-typescript
Browse files Browse the repository at this point in the history
# Conflicts:
#	examples/cms-wordpress/next.config.js
  • Loading branch information
ijjk committed Aug 8, 2022
2 parents 0a38422 + 1cc6e47 commit 7230675
Show file tree
Hide file tree
Showing 130 changed files with 1,123 additions and 329 deletions.
24 changes: 24 additions & 0 deletions .eslintrc.json
Expand Up @@ -145,6 +145,30 @@
}
]
}
},
{
"files": [
"packages/eslint-plugin-next/**/*.js",
"test/unit/eslint-plugin-next/**/*.test.ts"
],
"extends": ["plugin:eslint-plugin/recommended"],
"parserOptions": {
"sourceType": "script"
},
"rules": {
"eslint-plugin/prefer-replace-text": "error",
"eslint-plugin/report-message-format": [
"error",
".+\\. See: https://nextjs.org/docs/messages/[a-z\\-]+$"
],
"eslint-plugin/require-meta-docs-description": [
"error",
{
"pattern": ".+"
}
],
"eslint-plugin/require-meta-docs-url": "error"
}
}
],
"rules": {
Expand Down
2 changes: 2 additions & 0 deletions docs/advanced-features/preview-mode.md
Expand Up @@ -194,10 +194,12 @@ Then, send a request to `/api/clear-preview-mode-cookies` to invoke the API Rout
`setPreviewData` takes an optional second parameter which should be an options object. It accepts the following keys:

- `maxAge`: Specifies the number (in seconds) for the preview session to last for.
- `path`: Specifies the path the cookie should be applied under. Defaults to `/` enabling preview mode for all paths.

```js
setPreviewData(data, {
maxAge: 60 * 60, // The preview mode cookies expire in 1 hour
path: '/about', // The preview mode cookies apply to paths with /about
})
```

Expand Down
2 changes: 2 additions & 0 deletions docs/basic-features/data-fetching/get-static-props.md
Expand Up @@ -30,6 +30,8 @@ You should use `getStaticProps` if:
`getStaticProps` always runs on the server and never on the client. You can validate code written inside `getStaticProps` is removed from the client-side bundle [with this tool](https://next-code-elimination.vercel.app/).

- `getStaticProps` always runs during `next build`
- `getStaticProps` runs in the background when using [`fallback: true`](/docs/api-reference/data-fetching/get-static-paths#fallback-true)
- `getStaticProps` is called before initial render when using [`fallback: blocking`](/docs/api-reference/data-fetching/get-static-paths#fallback-blocking)
- `getStaticProps` runs in the background when using `revalidate`
- `getStaticProps` runs on-demand in the background when using [`revalidate()`](/docs/basic-features/data-fetching/incremental-static-regeneration.md#on-demand-revalidation)

Expand Down
6 changes: 5 additions & 1 deletion docs/basic-features/script.md
Expand Up @@ -240,6 +240,7 @@ Or by using the `dangerouslySetInnerHTML` property:
```jsx
<Script
id="show-banner"
strategy="lazyOnload"
dangerouslySetInnerHTML={{
__html: `document.getElementById('banner').classList.remove('hidden')`,
}}
Expand Down Expand Up @@ -280,16 +281,19 @@ export default function Home() {
Some third-party scripts require users to run JavaScript code after the script has finished loading and every time the component is mounted (after a route navigation for example). You can execute code after the script's `load` event when it first loads and then after every subsequent component re-mount using the `onReady` property:

```jsx
import { useRef } from 'react'
import Script from 'next/script'

export default function Home() {
const mapRef = useRef()
return (
<>
<div ref={mapRef}></div>
<Script
id="google-maps"
src="https://maps.googleapis.com/maps/api/js"
onReady={() => {
new google.maps.Map(ref.current, {
new google.maps.Map(mapRef.current, {
center: { lat: -34.397, lng: 150.644 },
zoom: 8,
})
Expand Down
18 changes: 18 additions & 0 deletions errors/failed-to-fetch-devpagesmanifest.md
@@ -0,0 +1,18 @@
# Failed to fetch devPagesManifest

#### Why This Error Occurred

The network request to load `_devPagesManifest.json` did not succeed.

The dev pages manifest file is used by `next/link` to retrieve the list of pages to be (pre-)loaded by Next.js.
If it fails, Next.js cannot properly navigate and link between pages.

#### Possible Ways to Fix It

- Make sure your browser developer tools, extensions, and any other network tools aren't blocking that request.
- If you're running your Next.js application through a proxy, nginx, or other network layer, make sure links like `/_next/*` are configured to be allowed.

### Useful Links

- [Original GitHub Issue Thread](https://github.com/vercel/next.js/issues/16874)
- [GitHub Issue Thread With Reproduction](https://github.com/vercel/next.js/issues/38047)
8 changes: 8 additions & 0 deletions errors/manifest.json
Expand Up @@ -715,6 +715,14 @@
{
"title": "invalid-next-config",
"path": "/errors/invalid-next-config.md"
},
{
"title": "failed-to-fetch-devpagesmanifest",
"path": "/errors/failed-to-fetch-devpagesmanifest.md"
},
{
"title": "middleware-parse-user-agent",
"path": "/errors/middleware-parse-user-agent.md"
}
]
}
Expand Down
34 changes: 34 additions & 0 deletions errors/middleware-parse-user-agent.md
@@ -0,0 +1,34 @@
# Removed parsed User Agent from Middleware API

#### Why This Error Occurred

Your application is interacting with `req.ua` which has been deprecated.

```ts
// middleware.ts
import { NextRequest, NextResponse } from 'next/server'

export function middleware(request: NextRequest) {
const viewport = request.ua.device.type === 'mobile' ? 'mobile' : 'desktop'

request.nextUrl.searchParams.set('viewport', viewport)
return NextResponse.rewrites(request.nextUrl)
}
```

#### Possible Ways to Fix It

The internal logic has been moved into a separate `userAgent` function that you can import from `next/server` and wrap your request instead.

```ts
// middleware.ts
import { NextRequest, NextResponse, userAgent } from 'next/server'

export function middleware(request: NextRequest) {
const { device } = userAgent(request)
const viewport = device.type === 'mobile' ? 'mobile' : 'desktop'

request.nextUrl.searchParams.set('viewport', viewport)
return NextResponse.rewrites(request.nextUrl)
}
```
2 changes: 1 addition & 1 deletion errors/middleware-request-page.md
Expand Up @@ -2,7 +2,7 @@

#### Why This Error Occurred

Your application is interacting with `request.page`, and it's being deprecated.
Your application is interacting with `request.page` which has been deprecated.

```typescript
// middleware.ts
Expand Down
8 changes: 4 additions & 4 deletions examples/custom-server-fastify/package.json
Expand Up @@ -6,10 +6,10 @@
"start": "cross-env NODE_ENV=production node ./server.js"
},
"dependencies": {
"cross-env": "^7.0.2",
"fastify": "^3.19.1",
"cross-env": "^7.0.3",
"fastify": "^4.2.0",
"next": "latest",
"react": "^17.0.2",
"react-dom": "^17.0.2"
"react": "^18.2.0",
"react-dom": "^18.2.0"
}
}
13 changes: 7 additions & 6 deletions examples/custom-server-fastify/server.js
@@ -1,3 +1,4 @@
/** @type {import('fastify').FastifyInstance} */
const fastify = require('fastify')({
logger: { level: 'error' },
pluginTimeout: 0,
Expand All @@ -16,32 +17,32 @@ fastify.register((fastify, opts, next) => {
if (dev) {
fastify.get('/_next/*', (req, reply) => {
return handle(req.raw, reply.raw).then(() => {
reply.sent = true
reply.hijack()
})
})
}

fastify.get('/a', (req, reply) => {
return app.render(req.raw, reply.raw, '/a', req.query).then(() => {
reply.sent = true
reply.hijack()
})
})

fastify.get('/b', (req, reply) => {
return app.render(req.raw, reply.raw, '/b', req.query).then(() => {
reply.sent = true
reply.hijack()
})
})

fastify.all('/*', (req, reply) => {
return handle(req.raw, reply.raw).then(() => {
reply.sent = true
reply.hijack()
})
})

fastify.setNotFoundHandler((request, reply) => {
return app.render404(request.raw, reply.raw).then(() => {
reply.sent = true
reply.hijack()
})
})

Expand All @@ -50,7 +51,7 @@ fastify.register((fastify, opts, next) => {
.catch((err) => next(err))
})

fastify.listen(port, (err) => {
fastify.listen({ port }, (err) => {
if (err) throw err
console.log(`> Ready on http://localhost:${port}`)
})
2 changes: 1 addition & 1 deletion examples/progressive-web-app/package.json
Expand Up @@ -7,7 +7,7 @@
},
"dependencies": {
"next": "latest",
"next-pwa": "^5.4.1",
"next-pwa": "5.5.4",
"react": "^17.0.2",
"react-dom": "^17.0.2"
},
Expand Down
15 changes: 10 additions & 5 deletions examples/with-apivideo-upload/README.md
Expand Up @@ -18,10 +18,14 @@ Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packag

```bash
npx create-next-app --example with-apivideo-upload with-apivideo-upload-app
# or
```

```bash
yarn create next-app --example with-apivideo-upload with-apivideo-upload-app
# or
pnpm create next-app -- --example with-apivideo-upload with-apivideo-upload-app
```

```bash
pnpm create next-app --example with-apivideo-upload with-apivideo-upload-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)).
Expand All @@ -36,8 +40,9 @@ You can choose to stay in sandbox and have watermark over your videos, or enter
### 2. Get you API key

Once in the dashboard, find your API keys directly in the `/overview` or navigate to `/apikeys` with the "API Keys" button in the side navigation.
Copy your API key and paste it in `.env.development` as value for `API_KEY`.
You can now try the application locally by running `npm run dev` from the root directory.
Copy your API key, and paste it in `.env.local.example` as value for `API_KEY`.
Rename `.env.local.example` to `.env.local`.
You can now try the application locally by running `npm run dev`, `yarn dev` or `pnpm dev` from the root directory.

### 3. Deployment

Expand Down
12 changes: 6 additions & 6 deletions examples/with-docker-compose/README.md
Expand Up @@ -41,10 +41,10 @@ First, run the development server:
docker network create my_network

# Build dev using new BuildKit engine
COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_BUILDKIT=1 docker-compose -f docker-compose.dev.yml build --parallel
docker compose -f docker-compose.dev.yml build

# Up dev
docker-compose -f docker-compose.dev.yml up
docker compose -f docker-compose.dev.yml up
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
Expand All @@ -63,10 +63,10 @@ First, run the production server (Final image approximately 110 MB).
docker network create my_network

# Build prod using new BuildKit engine
COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_BUILDKIT=1 docker-compose -f docker-compose.prod.yml build --parallel
docker compose -f docker-compose.prod.yml build

# Up prod in detached mode
docker-compose -f docker-compose.prod.yml up -d
docker compose -f docker-compose.prod.yml up -d
```

Alternatively, run the production server without without multistage builds (Final image approximately 1 GB).
Expand All @@ -77,10 +77,10 @@ Alternatively, run the production server without without multistage builds (Fina
docker network create my_network

# Build prod without multistage using new BuildKit engine
COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_BUILDKIT=1 docker-compose -f docker-compose.prod-without-multistage.yml build --parallel
docker compose -f docker-compose.prod-without-multistage.yml build

# Up prod without multistage in detached mode
docker-compose -f docker-compose.prod-without-multistage.yml up -d
docker compose -f docker-compose.prod-without-multistage.yml up -d
```

Open [http://localhost:3000](http://localhost:3000).
Expand Down
4 changes: 3 additions & 1 deletion examples/with-emotion-swc/shared/styles.tsx
Expand Up @@ -62,7 +62,9 @@ export const Pink = styled(Basic)({
color: 'hotpink',
})

export const BasicExtended = styled(Basic)``
export const BasicExtended = styled(Basic, {
shouldForwardProp: (propertyName: string) => !propertyName.startsWith('$'),
})``

export const ComponentSelectorsExtended = styled.div`
${BasicExtended} {
Expand Down
@@ -1,6 +1,7 @@
import Link from 'next/link'
import { PostData } from '../types/postdata'

export default function Post({ title, body, id }) {
export default function Post({ title, body, id }: PostData) {
return (
<article>
<h2>{title}</h2>
Expand Down
17 changes: 17 additions & 0 deletions examples/with-static-export/lib/postdata_api.ts
@@ -0,0 +1,17 @@
import { PostData } from '../types/postdata'

export async function GetPost(id: string): Promise<PostData> {
const response = await fetch(
`https://jsonplaceholder.typicode.com/posts/${id}`
)
const postData: PostData = (await response.json()) as PostData
return postData
}

export async function GetPosts(): Promise<PostData[]> {
const response = await fetch(
'https://jsonplaceholder.typicode.com/posts?_page=1'
)
const postList: PostData[] = (await response.json()) as PostData[]
return postList
}
5 changes: 5 additions & 0 deletions examples/with-static-export/next-env.d.ts
@@ -0,0 +1,5 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
23 changes: 16 additions & 7 deletions examples/with-static-export/package.json
@@ -1,17 +1,26 @@
{
"private": true,
"dependencies": {
"next": "latest",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"serve": "11.2.0"
},
"scripts": {
"dev": "next",
"build": "next build",
"preexport": "npm run build",
"export": "next export",
"prestart": "npm run export",
"start": "serve out"
"start": "serve out",
"lint": "next lint"
},
"dependencies": {
"next": "latest",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"serve": "^14.0.1"
},
"devDependencies": {
"@types/node": "^18.0.0",
"@types/react": "^18.0.14",
"@types/react-dom": "^18.0.5",
"eslint": "8.19.0",
"eslint-config-next": "12.2.0",
"typescript": "^4.7.4"
}
}

0 comments on commit 7230675

Please sign in to comment.