Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] canary from vercel:canary #552

Merged
merged 59 commits into from
Dec 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
7a2ec41
Refactor more tests to createNextDescribe (#44104)
timneutkens Dec 19, 2022
e45bbbe
Add jsdoc/no-types eslint rule for TypeScript files (#44049)
timneutkens Dec 19, 2022
fa880d0
Add test for rewriting in middleware in app-dir (#43971)
jankaifer Dec 19, 2022
723311b
Revert "Remove `useState` from `next/image` (#43587)" (#44094)
l1qu1d Dec 19, 2022
ded93bf
should not contain pages css in app dir (#44151)
huozhi Dec 19, 2022
887cbe4
Add types as a default dependency into tests (#44140)
jankaifer Dec 19, 2022
ae5502e
docs: Add missing type to import statement (#44111)
nyedidikeke Dec 19, 2022
60b8468
Suggest contributors to use shallow clone (#44158)
jankaifer Dec 19, 2022
397fc57
Update pnpm new-test to use createNextDescribe (#44147)
timneutkens Dec 19, 2022
4796fb3
Upgrade undici to 5.14.0 to fix fetch redirect bug (#44133)
jaslong Dec 19, 2022
68d06fe
Update README templates to include snippet on `next/font` (#44088)
iteratetograceness Dec 19, 2022
43c9d89
Wrap CSS variable in var (#44153)
iteratetograceness Dec 19, 2022
ea7d856
Fix styled-components setup in turbo example (#44165)
huozhi Dec 19, 2022
3dd9af7
build(cargo): fix turbopack + next-swc build (#43983)
kwonoj Dec 19, 2022
19013a5
Ensure next.url is used instead of next.appPort (#44163)
ijjk Dec 19, 2022
6827b58
docs: update next/dynamic docs (#44067)
huozhi Dec 19, 2022
13a9fb9
Align onRecoverableError callback between pages and app dir (#44161)
huozhi Dec 19, 2022
9855fd7
test: add test for notFound during streaming (#44078)
huozhi Dec 19, 2022
2f79baf
Update disabling-http-keep-alive.md for server-side only (#43374)
longzheng Dec 19, 2022
e8dc27b
build(cargo): update turbopack (#44167)
kwonoj Dec 19, 2022
e27a7bd
Update styled-jsx (#44070)
huozhi Dec 19, 2022
a32b3dd
Fix test template example (#44170)
styfle Dec 20, 2022
c3d1f02
Remove devcontainer network host argument (#44157)
akshitsinha Dec 20, 2022
7368b6f
v13.0.8-canary.1
ijjk Dec 20, 2022
3816564
Fix crash in GraalVM (#44176)
Brooooooklyn Dec 20, 2022
5a35be1
Fix pnpm install on Azure (#44179)
ijjk Dec 20, 2022
9203386
Enable ReactRefreshLogBox scss test (#44180)
hanneslund Dec 20, 2022
f6cba80
Increase recommended git clone depth (#44181)
jankaifer Dec 20, 2022
6640846
Document how chain works in BrowserInterface and chain to `browser.ev…
jankaifer Dec 20, 2022
39f30fb
Remove browser.refresh in app tests (#44186)
hanneslund Dec 20, 2022
2f0b5a2
Also check error.message as digest for recoverable errors in pages (#…
huozhi Dec 20, 2022
2b3a38e
docs: fix spelling error (#44191)
gish Dec 20, 2022
cafb886
Move options to stable (#44195)
shuding Dec 20, 2022
04daf7e
Move `transpilePackages` out of experimental (#44194)
shuding Dec 20, 2022
966d2b1
Fix CSS resources being duplicated in app dir (#44168)
shuding Dec 20, 2022
e847b49
Add telemetry for stable features (#44201)
shuding Dec 20, 2022
186e25f
Add warning for experimental flags that have moved (#44202)
shuding Dec 20, 2022
1f8dbf2
build(cargo): bump up turbopack (#44206)
kwonoj Dec 20, 2022
54e95c1
Bump `@vercel/[email protected]` (#44193)
styfle Dec 20, 2022
0ac617e
v13.0.8-canary.2
ijjk Dec 20, 2022
6f1f3e6
Disable Image Optimization API when next.config.js has `unoptimized: …
styfle Dec 21, 2022
6713ce4
Move tests into their test folder (#44183)
jankaifer Dec 21, 2022
f07f69d
Add test checking that repeated edits won't cause hydration issues (#…
jankaifer Dec 21, 2022
2c70bc7
Write tests for navigation between app-dir and pages (#43881)
jankaifer Dec 21, 2022
e27c7fa
Honour `distDir` in type generation (#44207)
shuding Dec 21, 2022
c24643e
Only once for the next/head usage in app dir (#44233)
huozhi Dec 21, 2022
8049ad3
Update labeler.json with current next.js team members (#44231)
jankaifer Dec 21, 2022
52fb820
Add docs for middleware flags (#44235)
ijjk Dec 21, 2022
9ee4c0c
Enable allowMiddlewareResponseBody by default (#44224)
timneutkens Dec 21, 2022
7c8d006
Move `modularizeImports` out of experimental (#44240)
shuding Dec 21, 2022
e8b2387
Update config validation for latest turbopack changes (#44223)
sokra Dec 21, 2022
152411c
build(cargo): update turbopack (#44241)
kwonoj Dec 21, 2022
13a3a9c
v13.0.8-canary.3
ijjk Dec 21, 2022
6349db8
update turbopack for bugfixes (#44251)
sokra Dec 22, 2022
0572e21
v13.0.8-canary.4
timneutkens Dec 22, 2022
3020c44
update with-turbopack example for postcss/tailwind support (#44261)
sokra Dec 22, 2022
87ca16f
v13.0.8-canary.5
timneutkens Dec 22, 2022
02489c2
v13.1.0
timneutkens Dec 22, 2022
fd9ec64
Use turbo for packing files in test setup (#44074)
jankaifer Dec 22, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
// Github latest can't be installed due to GPG issues: https://github.com/cli/cli/discussions/6222
// "github-cli": "latest",
},
// This is needed for forwarding X11: https://github.com/microsoft/vscode-remote-release/issues/3841
"runArgs": ["--net=host"],
"remoteEnv": {
"DISPLAY": ":0"
}
Expand Down
13 changes: 11 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"root": true,
"parser": "@babel/eslint-parser",
"plugins": ["react", "react-hooks", "jest", "import"],
"plugins": ["react", "react-hooks", "jest", "import", "jsdoc"],
"env": {
"browser": true,
"commonjs": true,
Expand Down Expand Up @@ -96,7 +96,16 @@
"@typescript-eslint/no-useless-constructor": "warn",
"@typescript-eslint/prefer-literal-enum-member": "error",
"@typescript-eslint/prefer-namespace-keyword": "error"
}
},
"overrides": [
{
"files": ["packages/**"],
"rules": {
"jsdoc/no-types": "error",
"jsdoc/no-undefined-types": "error"
}
}
]
},
{
"files": [
Expand Down
6 changes: 5 additions & 1 deletion .github/actions/next-stats-action/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"private": true,
"main": "src/index.js",
"scripts": {
"turbo": "turbo"
},
"dependencies": {
"async-sema": "^3.1.0",
"fs-extra": "^8.1.0",
Expand All @@ -12,6 +15,7 @@
"prettier": "^1.18.2",
"pretty-bytes": "^5.3.0",
"pretty-ms": "^5.0.0",
"semver": "7.3.4"
"semver": "7.3.4",
"turbo": "1.6.3"
}
}
48 changes: 44 additions & 4 deletions .github/actions/next-stats-action/src/prepare/repo-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ const mockTrace = () => ({
traceChild: () => mockTrace(),
})

let turboRepoRoot = path.join(__dirname, '..', '..', '..', '..', '..')

// stats-action runs this code without access to the original repo.
// In that case we just use the temporary directory (everything is temporary anyway in CI)
if (turboRepoRoot === '/') {
turboRepoRoot = path.join(__dirname, '..', '..')
}

/** Save turbo cache to persistent storage */
const turboCacheLocation = path.join(turboRepoRoot, 'node_modules/.cache/turbo')
const packedPkgsDir = path.join(turboRepoRoot, 'test/tmp/packedPkgs')

module.exports = (actionInfo) => {
return {
async cloneRepo(repoPath = '', dest = '') {
Expand Down Expand Up @@ -81,9 +93,15 @@ module.exports = (actionInfo) => {
await rootSpan
.traceChild('prepare packages for packing')
.traceAsyncFn(async () => {
await fs.ensureDir(packedPkgsDir)
const repoData = require(path.join(repoDir, 'package.json'))

for (const pkg of pkgs) {
const pkgPath = path.join(repoDir, 'packages', pkg)
const packedPkgPath = path.join(pkgPath, `${pkg}-packed.tgz`)
const packedPkgPath = path.join(
packedPkgsDir,
`${pkg}-packed.tgz`
)

const pkgDataPath = path.join(pkgPath, 'package.json')
if (!fs.existsSync(pkgDataPath)) {
Expand All @@ -103,7 +121,8 @@ module.exports = (actionInfo) => {
}

for (const pkg of pkgDatas.keys()) {
const { pkgDataPath, pkgData } = pkgDatas.get(pkg)
const { pkgDataPath, pkgData, pkgPath, packedPkgPath } =
pkgDatas.get(pkg)

for (const pkg of pkgDatas.keys()) {
const { packedPkgPath } = pkgDatas.get(pkg)
Expand Down Expand Up @@ -139,6 +158,27 @@ module.exports = (actionInfo) => {
}
}

// Turbo requires package manager specification
pkgData.packageManager =
pkgData.packageManager || repoData.packageManager

pkgData.scripts = {
...pkgData.scripts,
'test-pack': `yarn pack -f ${packedPkgPath}`,
}

await fs.writeJSON(path.join(pkgPath, 'turbo.json'), {
pipeline: {
'test-pack': {
outputs: [packedPkgPath],
inputs: ['*', '!node_modules/', '!.turbo/'],
},
},
})

// Turbo requires pnpm-lock.yaml that is not empty
await fs.writeFile(path.join(pkgPath, 'pnpm-lock.yaml'), '')

await fs.writeFile(
pkgDataPath,
JSON.stringify(pkgData, null, 2),
Expand All @@ -157,9 +197,9 @@ module.exports = (actionInfo) => {
await packingSpan
.traceChild(`pack ${pkgName}`)
.traceAsyncFn(async () => {
const { pkg, pkgPath } = pkgDatas.get(pkgName)
const { pkgPath } = pkgDatas.get(pkgName)
await exec(
`cd ${pkgPath} && yarn pack -f '${pkg}-packed.tgz'`,
`pnpm run --dir="${turboRepoRoot}" turbo run test-pack --cache-dir="${turboCacheLocation}" --cwd="${pkgPath}"`,
true
)
})
Expand Down
13 changes: 12 additions & 1 deletion .github/labeler.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,18 @@
{ "type": "user", "pattern": "styfle" },
{ "type": "user", "pattern": "leerob" },
{ "type": "user", "pattern": "kdy1" },
{ "type": "user", "pattern": "timneutkens" }
{ "type": "user", "pattern": "timneutkens" },
{ "type": "user", "pattern": "sebmarkbage" },
{ "type": "user", "pattern": "wyattjoh" },
{ "type": "user", "pattern": "kwonoj" },
{ "type": "user", "pattern": "gnoff" },
{ "type": "user", "pattern": "padmaia" },
{ "type": "user", "pattern": "Brooooooklyn" },
{ "type": "user", "pattern": "ForsakenHarmony" },
{ "type": "user", "pattern": "feedthejim" },
{ "type": "user", "pattern": "JanKaifer" },
{ "type": "user", "pattern": "balazsorban44" },
{ "type": "user", "pattern": "hanneslund" }
],
"created-by: Next.js docs team": [
{ "type": "user", "pattern": "MaedahBatool" },
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build_test_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
name: Build, test, and deploy

env:
NAPI_CLI_VERSION: 2.12.0
NAPI_CLI_VERSION: 2.13.3
TURBO_VERSION: 1.6.3
RUST_TOOLCHAIN: nightly-2022-11-04
PNPM_VERSION: 7.3.0
Expand Down Expand Up @@ -1128,7 +1128,7 @@ jobs:
target: 'aarch64-pc-windows-msvc'
build: |
npm i -g "@napi-rs/cli@${NAPI_CLI_VERSION}" "turbo@${TURBO_VERSION}" "pnpm@${PNPM_VERSION}"
turbo run build-native-no-plugin -- --release --target aarch64-pc-windows-msvc --cargo-flags=--no-default-features
turbo run build-native-no-plugin-woa -- --release --target aarch64-pc-windows-msvc --cargo-flags=--no-default-features
if: ${{ needs.build.outputs.isRelease == 'true' || (needs.build.outputs.swcChange == 'yup' && needs.build.outputs.turboToken != 'empty') }}
needs: build
name: stable - ${{ matrix.settings.target }} - node@16
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pull_request_stats.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
name: Generate Pull Request Stats

env:
NAPI_CLI_VERSION: 2.12.0
NAPI_CLI_VERSION: 2.13.3
TURBO_VERSION: 1.6.3
RUST_TOOLCHAIN: nightly-2022-11-04
PNPM_VERSION: 7.3.0
Expand Down
4 changes: 2 additions & 2 deletions contributing/core/developing.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
To develop locally:

1. Install the [GitHub CLI](https://github.com/cli/cli#installation).
1. Clone the Next.js repository:
1. Clone the Next.js repository (download only recent commits for faster clone):
```
gh repo clone vercel/next.js
gh repo clone vercel/next.js --depth=3000 --branch canary --single-branch
```
1. Create a new branch:
```
Expand Down
11 changes: 3 additions & 8 deletions docs/advanced-features/dynamic-import.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,21 @@ description: Dynamically import JavaScript modules and React Components and spli

Next.js supports lazy loading external libraries with `import()` and React components with `next/dynamic`. Deferred loading helps improve the initial loading performance by decreasing the amount of JavaScript necessary to render the page. Components or libraries are only imported and included in the JavaScript bundle when they're used.

`next/dynamic` is an extension of [`React.lazy`](https://reactjs.org/docs/code-splitting.html#reactlazy). When used in combination with [`Suspense`](https://reactjs.org/docs/react-api.html#reactsuspense), components can delay hydration until the Suspense boundary is resolved.
`next/dynamic` is a composite extension of [`React.lazy`](https://reactjs.org/docs/code-splitting.html#reactlazy) and [`Suspense`](https://reactjs.org/docs/react-api.html#reactsuspense), components can delay hydration until the Suspense boundary is resolved.

## Example

By using `next/dynamic`, the header component will not be included in the page's initial JavaScript bundle. The page will render the Suspense `fallback` first, followed by the `Header` component when the `Suspense` boundary is resolved.

```jsx
import dynamic from 'next/dynamic'
import { Suspense } from 'react'

const DynamicHeader = dynamic(() => import('../components/header'), {
suspense: true,
loading: () => 'Loading...',
})

export default function Home() {
return (
<Suspense fallback={`Loading...`}>
<DynamicHeader />
</Suspense>
)
return <DynamicHeader />
}
```

Expand Down
74 changes: 62 additions & 12 deletions docs/advanced-features/middleware.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ description: Learn how to use Middleware to run code before a request is complet

| Version | Changes |
| --------- | ------------------------------------------------------------------------------------------ |
| `v13.1.0` | Advanced Middleware flags added |
| `v13.0.0` | Middleware can modify request headers, response headers, and send responses |
| `v12.2.0` | Middleware is stable |
| `v12.0.9` | Enforce absolute URLs in Edge Runtime ([PR](https://github.com/vercel/next.js/pull/33410)) |
Expand Down Expand Up @@ -220,18 +221,7 @@ export function middleware(request: NextRequest) {

## Producing a Response

You can respond to middleware directly by returning a `NextResponse` (responding from middleware is available since Next.js v13.0.0).

To enable middleware responses, update `next.config.js`:

```js
// next.config.js
module.exports = {
experimental: {
allowMiddlewareResponseBody: true,
},
}
```
You can respond to middleware directly by returning a `NextResponse` (responding from middleware is available since Next.js v13.1.0).

Once enabled, you can provide a response from middleware using the `Response` or `NextResponse` API:

Expand All @@ -257,6 +247,66 @@ export function middleware(request: NextRequest) {
}
```

## Advanced Middleware Flags

In `v13.1` of Next.js two additional flags were introduced for middleware, `skipMiddlewareUrlNormalize` and `skipTrailingSlashRedirect` to handle advanced use cases.

`skipTrailingSlashRedirect` allows disabling Next.js default redirects for adding or removing trailing slashes allowing custom handling inside middleware which can allow maintaining the trailing slash for some paths but not others allowing easier incremental migrations.

```js
// next.config.js
module.exports = {
skipTrailingSlashRedirect: true,
}
```

```js
// middleware.js

const legacyPrefixes = ['/docs', '/blog']

export default async function middleware(req) {
const { pathname } = req.nextUrl

if (legacyPrefixes.some((prefix) => pathname.startsWith(prefix))) {
return NextResponse.next()
}

// apply trailing slash handling
if (
!pathname.endsWith('/') &&
!pathname.match(/((?!\.well-known(?:\/.*)?)(?:[^/]+\/)*[^/]+\.\w+)/)
) {
req.nextUrl.pathname += '/'
return NextResponse.redirect(req.nextUrl)
}
}
```

`skipMiddlewareUrlNormalize` allows disabling the URL normalizing Next.js does to make handling direct visits and client-transitions the same. There are some advanced cases where you need full control using the original URL which this unlocks.

```js
// next.config.js

module.exports = {
skipMiddlewareUrlNormalize: true,
}
```

```js
// middleware.js

export default async function middleware(req) {
const { pathname } = req.nextUrl

// GET /_next/data/build-id/hello.json

console.log(pathname)
// with the flag this now /_next/data/build-id/hello.json
// without the flag this would be normalized to /hello
}
```

## Related

<div class="card">
Expand Down
3 changes: 1 addition & 2 deletions docs/api-reference/data-fetching/get-static-props.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,7 @@ export const getStaticProps: GetStaticProps<{ posts: Post[] }> = async (
If you want to get inferred typings for your props, you can use `InferGetStaticPropsType<typeof getStaticProps>`:

```tsx
import { InferGetStaticPropsType } from 'next'
import { GetStaticProps } from 'next'
import type { InferGetStaticPropsType, GetStaticProps } from 'next'

type Post = {
author: string
Expand Down
14 changes: 2 additions & 12 deletions docs/api-reference/next.config.js/disabling-http-keep-alive.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,9 @@ description: Next.js will automatically use HTTP Keep-Alive by default. Learn mo

# Disabling HTTP Keep-Alive

Next.js automatically polyfills [node-fetch](/docs/basic-features/supported-browsers-features#polyfills) and enables [HTTP Keep-Alive](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Keep-Alive) by default. You may want to disable HTTP Keep-Alive for certain `fetch()` calls or globally.
In Node.js versions prior to 18, Next.js automatically polyfills `fetch()` with [node-fetch](/docs/basic-features/supported-browsers-features#polyfills) and enables [HTTP Keep-Alive](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Keep-Alive) by default.

For a single `fetch()` call, you can add the agent option:

```js
import { Agent } from 'https'

const url = 'https://example.com'
const agent = new Agent({ keepAlive: false })
fetch(url, { agent })
```

To override all `fetch()` calls globally, you can use `next.config.js`:
To disable HTTP Keep-Alive for all `fetch()` calls on the server-side, open `next.config.js` and add the `httpAgentOptions` config:

```js
module.exports = {
Expand Down
2 changes: 1 addition & 1 deletion errors/no-img-element.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function Home() {
export default Home
```

If you would like to use `next/image` featrues such as blur-up placeholders but disable Image Optimization, you can do so using [unoptimized](https://nextjs.org/docs/api-reference/next/image#unoptimized).
If you would like to use `next/image` features such as blur-up placeholders but disable Image Optimization, you can do so using [unoptimized](https://nextjs.org/docs/api-reference/next/image#unoptimized).

<br />

Expand Down
16 changes: 1 addition & 15 deletions examples/with-turbopack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,7 @@ This playground is a mirror of the [Next.js v13 App Directory Playground](https:
1. Install dependencies: `yarn`
1. Start the dev server: `yarn dev`

**Note:** The playground uses [Tailwind CSS](https://tailwindcss.com). However, Turbopack does not yet support fully [PostCSS](https://turbo.build/pack/docs/features/css#postcss), but it does support CSS and CSS Modules. [As a workaround](https://turbo.build/pack/docs/features/css#tailwind-css), we run Tailwind through it's CLI upon `postinstall`. For live reload of CSS, you can run Tailwind in another process with the `--watch` flag or install `concurrently` and modify your `dev` script:

```bash
yarn add concurrently --dev
```

Then modify your `dev` script in `package.json`:

```json
{
"scripts": {
"dev": "concurrently \"next dev --turbo\" \"npm run tailwind --watch\""
}
}
```
**Note:** The playground uses [Tailwind CSS](https://tailwindcss.com) via [PostCSS](https://turbo.build/pack/docs/features/css#postcss).

For more information, see: https://turbo.build/pack/docs/features/css#tailwind-css

Expand Down
2 changes: 1 addition & 1 deletion examples/with-turbopack/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '@/styles/dist.css';
import '@/styles/globals.css';
import React from 'react';
import AddressBar from '@/ui/AddressBar';
import GlobalNav from './GlobalNav';
Expand Down
Loading