1. 18 Aug, 2023 1 commit
  2. 17 Aug, 2023 18 commits
  3. 16 Aug, 2023 18 commits
    • vercel-release-bot's avatar
      v13.4.17-canary.0 · 93259caa
      vercel-release-bot authored
      93259caa
    • Will Binns-Smith's avatar
      Next build: use exported `handle_issues` from turbopack (#52972) · 8589a6da
      Will Binns-Smith authored
      Note: depends on next Turbopack publish
      
      https://github.com/vercel/turbo/pull/5487 exports a reusable `handle_issues` function for reporting issues and erroring when failing issues are encountered.
      
      This uses it for `next build` with a failing severity level of error.
      8589a6da
    • Zack Tanner's avatar
      cleanup: remove unnecessary effect dep (#54134) · 4f7fc05f
      Zack Tanner authored
      Accidentally left this in after making some changes in:
      
      - https://github.com/vercel/next.js/pull/54081
      4f7fc05f
    • Dima Voytenko's avatar
      OpenTel: remove the internal (ipc) fetched from traces in a non-verbose mode (#54083) · bdd0f545
      Dima Voytenko authored
      The internal IPC fetches are an internal framework detail and they shouldn't pollute the tracing in a non-verbose mode.
      
      Examples of internal fetch output:
      
      <img width="600" alt="image" src="https://github.com/vercel/next.js/assets/726049/64a25c02-bf39-4f54-8fe3-86018c7720dc">
      
      
      <img width="1369" alt="image" src="https://github.com/vercel/next.js/assets/726049/f8f1d65c-5444-42c7-9e7d-6cdf9865eace">
      bdd0f545
    • Balázs Orbán's avatar
      fix(edge): override init when cloning with `NextRequest` (#54108) · af97755e
      Balázs Orbán authored
      ### What?
      
      When cloning a `Request` with `NextRequest` the second argument needs to take precedence over the `Headers` set on the original request.
      
      ### Why?
      
      Follow-up of #53157
      
      I checked the `Request` spec https://fetch.spec.whatwg.org/#request-class and following the order of execution, `init.headers` should indeed override the headers if the first param was `Request`.
      
      I verified this in the browser too:
      
      ```js
      const req1 = new Request("http://n", {headers: {"x-header": "foo"}})
      const req2 = new Request(req1, {headers: {"x-header-2": "bar"}})
      Object.fromEntries(req2.headers) // {x-header-2: "bar"}
      ```
      
      So we should match `NextRequest` with this behavior.
      
      ### How?
      
      Pass the `init` to `super` when cloning the request.
      
      Closes NEXT-1521
      Fixes #54094
      af97755e
    • Will Binns-Smith's avatar
      Tracing: add opt-in flag to send a subset of development traces to url (#53880) · 96dd8ff4
      Will Binns-Smith authored
      This adds an **opt-in** feature to send a subset of trace spans and metadata to a remote http server. The url must be provided as an option like so:
      
      `next dev --experimental-upload-trace=http://localhost:3000/traces`
      
      These traces are derived from the tracing data stored at `.next/trace`. The request payload looks like this:
      
      ```json
      {
        "metadata": {
          "commit": "69b0a3366734182f4efce6c0089c2592044d7124",
          "mode": "dev",
          "pkgName": "nextjs-project",
          "arch": "arm64",
          "cpus": 10,
          "platform": "darwin"
        },
        "traces": [
          [
            {
              "traceId": "2f041a20b06027ab",
              "name": "hot-reloader",
              "id": 1,
              "timestamp": 28712742599,
              "duration": 21,
              "tags": {
                "version": "13.4.14-canary.1"
              },
              "startTime": 1691707223226
            },
            {
              "traceId": "2f041a20b06027ab",
              "parentId": 1,
              "name": "webpack-invalidated-server",
              "id": 63,
              "timestamp": 28713776446,
              "duration": 244628,
              "tags": {
                "trigger": "manual"
              },
              "startTime": 1691707224260
            },
            {
              "traceId": "2f041a20b06027ab",
              "parentId": 1,
              "name": "webpack-invalidated-server",
              "id": 111,
              "timestamp": 28714080210,
              "duration": 115267,
              "tags": {
                "trigger": "manual"
              },
              "startTime": 1691707224563
            },
            {
              "traceId": "2f041a20b06027ab",
              "parentId": 1,
              "name": "webpack-invalidated-server",
              "id": 168,
              "timestamp": 28715243617,
              "duration": 69471,
              "tags": {
                "trigger": "[project]/pages/index.tsx"
              },
              "startTime": 1691707225727
            },
            {
              "traceId": "2f041a20b06027ab",
              "parentId": 1,
              "name": "client-hmr-latency",
              "id": 222,
              "timestamp": 1691707225727000,
              "duration": 72000,
              "tags": {
                "clientId": 1691707224946
              },
              "startTime": 1691707225799
            },
            {
              "traceId": "2f041a20b06027ab",
              "parentId": 1,
              "name": "webpack-invalidated-server",
              "id": 223,
              "timestamp": 28716999898,
              "duration": 47425,
              "tags": {
                "trigger": "[project]/pages/index.tsx"
              },
              "startTime": 1691707227483
            }
          ]
        ]
      }
      ```
      
      Currently only events of type `client-hmr-latency`, `hot-reloader`, `webpack-invalid-client`, `webpack-invalidated-server` are included, as well as all root spans. Traces are expected to include the ancestry of any given span through the `parentId` property.
      96dd8ff4
    • Zack Tanner's avatar
      fix routing bug when bfcache is hit following an mpa navigation (#54081) · 0b3e366f
      Zack Tanner authored
      When an mpa navigation takes place, we currently push the user to the new route and suspend the page indefinitely (x-ref: #49058). When navigating back, if the browser opts into using the [bfcache](https://web.dev/bfcache/), it will remain suspended and `pushRef.mpaNavigation` will be true. This means that anything that would cause the component to re-render will trigger the mpa navigation again (such as hovering over another `Link`, as reported in #53347)
      
      This PR checks to see if bfcache is being used by observing `PageTransitionEvent.persisted` and if so, resets the router state to clear out `pushRef`. 
      
      Closes NEXT-1511
      Fixes #53347
      0b3e366f
    • Steven's avatar
      chore(image): remove apple silicon workaround for versions older than `node@16.5.0` (#54125) · 86d2ead1
      Steven authored
      Since Next.js already requires [`node@16.8.0`](https://github.com/vercel/next.js/blob/88b8d15f41f894011cf33af0b1f4a3fb24aed46b/packages/next/package.json#L319) or newer, we can drop this workaround for squoosh/wasm on apple silicon.
      
      - x-ref: https://github.com/vercel/next.js/pull/27031
      86d2ead1
    • Jiachi Liu's avatar
      Refactor layout router creation in app-render (#54126) · 73217b56
      Jiachi Liu authored
      Merge the rendering of `<LayoutRouter>` component into one place, with different props in different branches.
      73217b56
    • Will Binns-Smith's avatar
      install-native.mjs: include `packageManager` field (#54132) · 662dcedd
      Will Binns-Smith authored
      This ensures that corepack uses the correct package manager and version for the tmpdir install as it does for the rest of the repo. It reads the value from the root `package.json`.
      
      
      Closes WEB-1401
      662dcedd
    • Steven's avatar
      chore: refactor to use `fs.promises.rm()` (#54076) · f944e984
      Steven authored
      Since Next.js already requires [`node@16.8.0`](https://github.com/vercel/next.js/blob/88b8d15f41f894011cf33af0b1f4a3fb24aed46b/packages/next/package.json#L319) or newer, we can drop old techniques for removing a directory recursively and instead rely on the native [`fs.promises.rm()`](https://nodejs.org/api/fs.html#fspromisesrmpath-options) function (available since `node@14.14.0`).
      
      x-ref: https://github.com/vercel/next.js/pull/34210
      f944e984
    • Steven's avatar
      chore: remove `as any` type cast (#54074) · 9f3fd5d7
      Steven authored
      This PR refactors some types to remove `as any`, but the runtime logic is the same.
      9f3fd5d7
    • Jiachi Liu's avatar
      Fix root not-found page tree loader structure (#54080) · 594f3d1f
      Jiachi Liu authored
      ### What & Why
      
      Previously when rendering the root `/_not-found` in production, we'll always override the parallel routes component children with not-found component, this will break the navigation in build mode from root 404 `/_not-found` path.
      
      ### How
      
      The new solution is to change the root `/_not-found` rendering strategy. Previously the loader tree of `/_not-found` look like this
      
      ```js
      ['',
        {
          children: ['not-found', {}, {}]
        },
        { layout: ..., 'not-found': ...}
      ]
      ```
      
      it's not a pretty valid tree, which could lead to problems during rendering.
      
      New solution is to change the children to render a page, but the page content is `not-found.js` component. The new tree of root not-found will look like
      
      ```js
      ['',
        {
          children: ['__PAGE__', {}, {
            page: ... // same as root 'not-found'
          }]
        },
        { layout: ..., 'not-found': ...}
      ]
      ```
      
      This change could fix the navigation on the root not-found page.
      
      Fixes #52264
      594f3d1f
    • Kiko Beats's avatar
      upgrade edge-runtime dependency (#54117) · b676fce0
      Kiko Beats authored
      Hello,
      
      This PR upgrades `edge-runtime` and associated packages, mostly fixing issues.
      b676fce0
    • Donny/강동윤's avatar
      Update `swc_core` to `v0.79.59` (#54082) · bc76784b
      Donny/강동윤 authored
      ### What?
      
      Update swc crates to https://github.com/swc-project/swc/commit/023042dfb9c941e95f2fc0e1cd9b245d0cc64aa5
      
      ### Why?
      
      To apply https://github.com/swc-project/swc/pull/7813
      
      ### How?
      
      Closes WEB-1396
      Fixes #54054
      bc76784b
    • Tim Neutkens's avatar
      Update Docker example to remove HOSTNAME (#54102) · d60690e2
      Tim Neutkens authored
      With the latest changes in stable Next.js setting HOSTNAME is not longer required for the image to function correctly 👍 
      
      Fixes #54093
      
      d60690e2
    • Balázs Orbán's avatar
      chore: update lock bot wording (#54099) · a6415c62
      Balázs Orbán authored
      Follow-up of #54048. We changed the lock action from waiting 1 month to 2 weeks, but the wording was not reflecting it.
      a6415c62
    • Damien Simonin Feugas's avatar
      fix(47299): allow testing pages with metadata in jsdom test environment (#53578) · 77acd164
      Damien Simonin Feugas authored
      ### 🧐 What's in there?
      
      This is another attempt to allow testing server-only code with Jest.
      
      ### 🧪 How to test?
      
      There's an integration tests which can be triggered with `pnpm testheadless server-only`
      
      Here is a more comprehensive setup:
      <details>
      <summary><code>app/lib/index.ts</code></summary>
      
      ```ts
      import 'server-only'
      
      export function add(num1: number, num2: number) {
        return num1 + num2
      }
      ```
      </details>
      <details>
      <summary><code>app/lib/index.test.ts</code></summary>
      
      ```ts
      import { add } from '.'
      
      it('adds two numbers', () => {
        expect(add(1, 3)).toEqual(4)
      })
      ```
      </details>
      <details>
      <summary><code>app/client-component.tsx</code></summary>
      
      ```ts
      'use client'
      
      import { useState } from 'react'
      
      export default function ClientComponent() {
        const [text, setText] = useState('not clicked yet')
        return <button onClick={() => setText('clicked!')}>{text}</button>
      }
      ```
      </details>
      <details>
      <summary><code>app/client-component.test.tsx</code></summary>
      
      ```ts
      import { fireEvent, render, screen } from '@testing-library/react'
      import ClientComponent from './client-component'
      
      it('can be clicked', async () => {
        render(<ClientComponent />)
        const button = screen.getByRole('button')
        expect(button).toHaveTextContent('not clicked yet')
        await fireEvent.click(button)
        expect(button).toHaveTextContent('clicked!')
      })
      ```
      </details>
      <details>
      <summary><code>app/server-component.tsx</code></summary>
      
      ```ts
      import { add } from '@/lib'
      
      export default function ServerComponent({ a, b }: { a: number; b: number }) {
        return (
          <code role="comment">
            {a} + {b} = {add(a, b)}
          </code>
        )
      }
      ```
      </details>
      <details>
      <summary><code>app/server-component.test.tsx</code></summary>
      
      ```ts
      import { render, screen } from '@testing-library/react'
      import ServerComponent from './server-component'
      
      it('renders', () => {
        render(<ServerComponent a={2} b={3} />)
        expect(screen.getByRole('comment')).toHaveTextContent('2 + 3 = 5')
      })
      ```
      </details>
      <details>
      <summary><code>app/page.tsx</code></summary>
      
      ```ts
      import Link from 'next/link'
      import ClientComponent from './client-component'
      import ServerComponent from './server-component'
      
      export default function Page() {
        return (
          <>
            <h1>Hello World</h1>
            <Link href="/dave">Dave?</Link>
            <p>
              <ClientComponent />
            </p>
            <p>
              <ServerComponent a={5} b={2} />
            </p>
          </>
        )
      }
      ```
      </details>
      <details>
      <summary><code>app/page.test.tsx</code></summary>
      
      ```ts
      import { render, screen } from '@testing-library/react'
      import Page from './page'
      
      it('greets', () => {
        render(<Page />)
        expect(screen.getByRole('link')).toHaveTextContent('Dave?')
        expect(screen.getByRole('heading')).toHaveTextContent('Hello World')
        expect(screen.getByRole('button')).toHaveTextContent('not clicked yet')
        expect(screen.getByRole('comment')).toHaveTextContent('5 + 2 = 7')
      })
      ```
      </details>
      <details>
      <summary><code>app/[blog]/page.tsx</code></summary>
      
      ```ts
      import { Metadata } from 'next'
      import Link from 'next/link'
      
      type Props = {
        params: { blog: string }
      }
      
      export async function generateMetadata({
        params: { blog: title },
      }: Props): Promise<Metadata> {
        return { title, description: `A blog post about ${title}` }
      }
      
      export default function Page({ params }: Props) {
        return (
          <>
            <div>
              <Link href="/">Back</Link>
            </div>
            <h1>All about {params.blog}</h1>
          </>
        )
      }
      ```
      </details>
      <details>
      <summary><code>app/[blog]/page.test.tsx</code></summary>
      
      ```ts
      import { render, screen } from '@testing-library/react'
      import Page from './page'
      
      it('has the appropriate title', () => {
        const title = 'Jane'
        render(<Page params={{ blog: title }} />)
        expect(screen.getByRole('heading')).toHaveTextContent(`All about ${title}`)
        expect(screen.getByRole('link')).toHaveTextContent('Back')
      })
      ```
      </details>
      <details>
      <summary><code>app/layout.tsx</code></summary>
      
      ```ts
      export default function RootLayout({ children }) {
        return (
          <html lang="en">
            <body>{children}</body>
          </html>
        )
      }
      ```
      </details>
      <details>
      <summary><code>jest.config.js</code></summary>
      
      ```ts
      const nextJest = require('next/jest')
      
      const createJestConfig = nextJest({ dir: './' })
      
      module.exports = createJestConfig({
        testEnvironment: 'jsdom',
        setupFilesAfterEnv: ['<rootDir>/test-setup.ts'],
      })
      ```
      </details>
      <details>
      <summary><code>package.json</code></summary>
      
      ```ts
      {
        "name": "rsc-test",
        "version": "0.0.0",
        "private": true,
        "scripts": {
          "test": "jest"
        },
        "devDependencies": {
          "@testing-library/jest-dom": "latest"
        }
      }
      ```
      </details>
      <details>
      <summary><code>test-setup.ts</code></summary>
      
      ```ts
      import '@testing-library/jest-dom'
      ```
      </details>
         
      The app should run and all test should pass.
      
      ### ❗ Notes to reviewers
      
      #### The problem:
      
      1. next/jest configures jest with a transformer ([jest-transformer](https://github.com/vercel/next.js/blob/canary/packages/next/src/build/swc/jest-transformer.ts)) to compile react code with next -swc
      2. the transformers configures next -swc for a given environment: Server or Client, based on jest global environment
      3. Based on the environment, next -swc checks for invalid usage of `import('server-only')`  `“use client”`, `export const metadata` or `export async function generateMetadata` 
      4. Because the global test environment is either jsdom or node, the same test suite can not include both client and server components
      
      #### Possible mitigations
      
      *A. Using jest projects*
      
      When configured with [multiple projects](https://jestjs.io/docs/next/configuration/#projects-arraystring--projectconfig), Jest can launch different runners with different environment. This would allow running server-only code in node and client-only code in jsdom. 
      
      However, it requires user to completely change their jest configuration. It would also require a different setup when scaffolding new app-directory project with create-next.
      
      *B. Using doc blocks*
      
      Jest allows changing the environment per test file [with docBlock](https://jestjs.io/docs/configuration#testenvironment-string). 
      
      However, by the time jest is invoking next -swc on a source file to transform it, this information is gone, and next -swc is still invoked with the (wrong) global environment.
      
      The PR #52393 provides a workaround for files with `import('server-only')`, but does not allow testing pages with metadata.
      
      *C. Always compile for node*
      
      Our jest-transformer could always configure next -swc for server:
      
      - pass Server-specific validations `import('server-only')`  `export const metadata` or `export async function generateMetadata`
      - does not complain about `"use client"`
      
      This is what this PR is about!
      
      Fixes #47299
      Co-authored-by: 's avatarJiachi Liu <4800338+huozhi@users.noreply.github.com>
      77acd164
  4. 15 Aug, 2023 3 commits