Commit graph

891 commits

Author SHA1 Message Date
Tim Neutkens
00106b7ef4
Optimize webpack memory cache garbage collection (#54397)
## What

Adds a reworked version of webpack's [built-in memory cache garbage
collection
plugin](853bfda35a/lib/cache/MemoryWithGcCachePlugin.js (L15))
that is more aggressive in cleaning up unused modules than the default.

The default marks 1/5th of the modules as "up for potentially being
garbage collected". The new plugin always checks all modules. In my
testing this does not cause much overhead compared to the current
approach which leverages writing to two separate maps. The change also
makes the memory cache eviction more predictable: when an item has not
been accessed for 5 compilations it is evicted from the memory cache, it
could still be in the disk cache.


In order to test this change I had to spin up the benchmarks but these
were a bit outdated so I've cleaned up the benchmark applications.

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2023-08-23 15:46:32 +02:00
vercel-release-bot
93e4e6d438 v13.4.20-canary.3 2023-08-23 13:13:36 +00:00
Jiachi Liu
9834ab7e15
Fix not found css not being preloaded while navigation (#53906)
### Problem

One style of `not-found` has `precendence` property with "undefined" value, which can't be handled by React Float, then during navigation the style could not load properly, lead to the style missing in issue #53210.

### Solution

Always enable `precendence` for all links, so all the css styles of page and convention components can be hoist by react properly. Float will decide which one should be handled. Previously this change only applies to template, actually we can apply it to all components so that they can all be handled properly especially during client navigation.

Related react change: https://github.com/facebook/react/pull/27265
Fixes #53210
2023-08-23 13:07:30 +00:00
Jiachi Liu
1e3920c3dd
Upgrade precompiled ua-parser-js (#54404)
Upgrade `ua-parser-js` which is used by `userAgentFromString` to latest version

Closes NEXT-1552
2023-08-22 23:56:05 +00:00
Jiachi Liu
6d769d0eb8
Upgrade vendored react (#54399)
### React upstream changes

- https://github.com/facebook/react/pull/27265
- https://github.com/facebook/react/pull/27259
- https://github.com/facebook/react/pull/27264
- https://github.com/facebook/react/pull/27257
- https://github.com/facebook/react/pull/27258
- https://github.com/facebook/react/pull/27187
- https://github.com/facebook/react/pull/27243
- https://github.com/facebook/react/pull/27205
- https://github.com/facebook/react/pull/27220
- https://github.com/facebook/react/pull/27238
- https://github.com/facebook/react/pull/27234
- https://github.com/facebook/react/pull/27224
- https://github.com/facebook/react/pull/27223
- https://github.com/facebook/react/pull/27222

This will help unblock https://github.com/vercel/next.js/pull/53906
2023-08-22 22:27:54 +00:00
vercel-release-bot
8bbf674a4d v13.4.20-canary.2 2023-08-22 12:43:03 +00:00
vercel-release-bot
1a56fb9483 v13.4.20-canary.1 2023-08-21 22:41:53 +00:00
vercel-release-bot
f1c286fff2 v13.4.20-canary.0 2023-08-20 12:56:16 +00:00
Jiachi Liu
311eea4c6a
Fix emotion-js transform for server components (#54284)
### What & Why

emotion-js has its own [jsx transform](https://emotion.sh/docs/typescript#emotionreact) which is being applied when `compiler.emotion` is enabled in `next.config.js`.

Thanks to emotion-js team that provided an emotion-js example setup with app router [here](https://github.com/emotion-js/emotion/issues/2928#issuecomment-1319792703), so that we can use it as test example with app router. Based on the setup, we create a test case working with emotion js but failed with error mentioned in #41994 that some client hooks appearing in server components. That is because the emotion-js jsx factory includes some client hooks.

### How

For server components, css-in-js is not recommended to apply so we disabled the transform before, the emotion jsx factory is a separate config that should also not be applied in server components. So in this case we still use react jsx factory instead of the emotion-js one for server components then it won't error. The test case can also be used as an example for basic emotion-js use case with app router.


Fixes #41994
Closes NEXT-1368
2023-08-20 03:14:16 +00:00
vercel-release-bot
d96e0258de v13.4.19 2023-08-19 00:23:31 +00:00
vercel-release-bot
1cf4aa6e51 v13.4.19-canary.0 2023-08-18 23:39:41 +00:00
Tim Neutkens
819a163fce
Update dd-trace used for internal tools (#54214)
This is only used for internal tools 👍
2023-08-18 13:55:22 +00:00
vercel-release-bot
87b66f64e5 v13.4.18 2023-08-18 00:16:08 +00:00
vercel-release-bot
89ed4dd105 v13.4.18-canary.0 2023-08-17 22:11:33 +00:00
Jiachi Liu
71149293e5
Allow range version for eslint config (#53751)
Fixes #52365

In #52275 that eslint config changed to a fixed canary version to leverage the improvement of `react-hooks` eslint plugin but breaks the installation when 3rd party packages having strict matching for certain version of eslint plugin.

This PR allows both previous version and the canary version be present.
2023-08-17 18:39:03 +00:00
Justin Ridgewell
11dfdf8d7a
Turbopack: Strip relative path prefix when generating PageLoaderAsset (#54040)
### What?

Strip the relative path prefix (`_next/`) when generating the `PageLoaderAsset`. This is necessary because the page loader will internally use `__turbopack_load__`, which prepends the prefix back onto the path.

### Why?

Without this, we'd try loading `_next/_next/path/to/file.js`, because we'd prepend the prefix onto a path that already contains it.

### How?

When generating the page loader asset, we "proxy" the `OutputAsset` onto a path which has the prefix removed.

~~Depends on https://github.com/vercel/turbo/pull/5717~~

Closes WEB-1377
2023-08-17 17:29:30 +00:00
vercel-release-bot
236075362a v13.4.17 2023-08-17 09:32:20 +00:00
vercel-release-bot
645ba004d6 v13.4.17-canary.2 2023-08-17 08:55:11 +00:00
Jiachi Liu
02c258dd91
Revert "fix(47299): allow testing pages with metadata in jsdom test environment" (#54160)
Reverts vercel/next.js#53578

This PR (#53578) will break client components test, revert it for now.

Can repro by adding `"use client"` to `app/page.tsx` in `test/production/jest/server-only.test.ts`

```
    FAIL app/page.test.jsx
      ● Test suite failed to run·
        Cannot find module 'private-next-rsc-mod-ref-proxy' from 'app/page.jsx'·
        Require stack:
```
2023-08-17 08:49:08 +00:00
vercel-release-bot
fc3bf373c5 v13.4.17-canary.1 2023-08-17 07:33:02 +00:00
vercel-release-bot
93259caac4 v13.4.17-canary.0 2023-08-16 21:11:24 +00:00
Kiko Beats
b676fce090
upgrade edge-runtime dependency (#54117)
Hello,

This PR upgrades `edge-runtime` and associated packages, mostly fixing issues.
2023-08-16 13:57:01 +00:00
Damien Simonin Feugas
77acd164d3
fix(47299): allow testing pages with metadata in jsdom test environment (#53578)
### 🧐 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: Jiachi Liu <4800338+huozhi@users.noreply.github.com>
2023-08-16 07:14:27 +00:00
Dima Voytenko
88b8d15f41
Test proxy mode: intercept the http and https client APIs (#54014)
Followup on the https://github.com/vercel/next.js/pull/52520. The enhancements:

1. Both `fetch` and `http(s)` APIs are intercepted in the testmode.
2. The loopback mode that would allow the test-side to use any fetch-mocking library of their choice.
2023-08-15 02:31:00 +00:00
vercel-release-bot
2fac86480c v13.4.16 2023-08-15 01:03:24 +00:00
vercel-release-bot
33d9bf2a8f v13.4.16-canary.1 2023-08-15 00:42:45 +00:00
vercel-release-bot
4d0aaafdef v13.4.16-canary.0 2023-08-14 22:26:27 +00:00
Will Binns-Smith
bd8ab094e5
Turbopack: fix hiding node_modules warnings in error overlay. (#54022)
This regressed in vercel/turbo#5661 when `context` was renamed `file_path`.
2023-08-14 21:38:52 +00:00
Dima Voytenko
88ad471e33
Concept: test mode for Playwright and similar integration tools (#52520)
An experimental test mode that enables integration tests to mock server-side fetch requests in Playwright tests.

For explanation on how this works, see the [`next-playwright/README.md`](https://github.com/vercel/next.js/pull/52520/files#diff-3b8da7782c16f015df5afafe0ac11247f5b8e5a1c0dbede341ca2b5124dfd924).
2023-08-14 18:45:50 +00:00
vercel-release-bot
6306ec1c1d v13.4.15 2023-08-14 16:40:09 +00:00
vercel-release-bot
242cdca8e0 v13.4.15-canary.0 2023-08-14 16:01:53 +00:00
Jiachi Liu
3f83743a6e
Make next a devDependency of @next/third-parties package (#53996)
ensure `next` is the dependency of third-parties package so turbo will
build next first then `@next/third-parties` to avoid type failing

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2023-08-14 08:55:57 -07:00
vercel-release-bot
4ee4458d46 v13.4.14 2023-08-14 10:46:46 +00:00
vercel-release-bot
e53f3af934 v13.4.14-canary.5 2023-08-14 07:58:37 +00:00
vercel-release-bot
df6ec96ab2 v13.4.14-canary.4 2023-08-14 04:47:55 +00:00
JJ Kasper
9a6ae144a9
Update swc runners config (#53939)
This fixes unexpected cache hits occurring causing latest next-swc
changes to not be built for the docker based builds. Noticed in our
turbo run summaries for these builds that no input files were detected
most likely due to older Node.js/pnpm versions being used from the old
Docker image.

This also updates to leverage new runner labels for better build perf
cutting build times down from over an hour down to around 20 min.

Fixes build issue on aarch64-linux-musl due to `TurboMalloc` not being
able to resolve. Test build done here
https://github.com/vercel/next.js/actions/runs/5850893681/job/15860929304

x-ref:
https://github.com/vercel/next.js/actions/runs/5843580924/job/15845848384

x-ref:
https://github.com/vercel/next.js/actions/runs/5837652747/job/15833506858
x-ref:
https://github.com/vercel/next.js/actions/runs/5837652747/job/15833506925
x-ref:
https://github.com/vercel/next.js/actions/runs/5837652747/job/15833507067
x-ref:
https://github.com/vercel/next.js/actions/runs/5837652747/job/15833507135
2023-08-13 19:02:48 -07:00
vercel-release-bot
261db496f7 v13.4.14-canary.3 2023-08-12 21:41:13 +00:00
Josh Story
2b38118ea0
Update React ot latest canary (#53881)
Updated React from cb3404a0c to f359f9b41.

### React upstream changes

- https://github.com/facebook/react/pull/27191
- https://github.com/facebook/react/pull/27209
- https://github.com/facebook/react/pull/27199
- https://github.com/facebook/react/pull/27218
- https://github.com/facebook/react/pull/27217
- https://github.com/facebook/react/pull/27212
2023-08-12 17:20:14 +00:00
Dima Voytenko
4c14482553
[chore] Upgrade playwright to 1.35.1 (#53875) 2023-08-11 23:25:01 +00:00
Leah
ddc8f50d24
enable @vercel/og support for turbopack (#53917)
### What?

Now that we have wasm support (and support for `?module`) `@vercel/og` should be supported

### Turbopack updates

* https://github.com/vercel/turbo/pull/5677 
* https://github.com/vercel/turbo/pull/5660 

Closes WEB-138
2023-08-11 22:16:41 +00:00
vercel-release-bot
9229f74b86 v13.4.14-canary.2 2023-08-11 12:02:35 +00:00
Tobias Koppers
45576ae752
Turbopack: more tests and bugfixes for next.rs api (#53809)
### What?

* adds more HMR test cases
* fixes bugs found

### Why?

### Turbopack changes

* https://github.com/vercel/turbo/pull/5668 <!-- OJ Kwon - ci(test):
temporarily increase test timeout -->
* https://github.com/vercel/turbo/pull/5696 <!-- Tobias Koppers -
Cleanup minify -->
2023-08-11 10:29:36 +02:00
Josh Story
f0dab3a8da
update vendored React packages to the the latest canary (#53742)
Updated React from 9377e1010 to cb3404a0c.

### React upstream changes

- https://github.com/facebook/react/pull/27190
- https://github.com/facebook/react/pull/27189
- https://github.com/facebook/react/pull/27201
- https://github.com/facebook/react/pull/27147
- https://github.com/facebook/react/pull/26949
- https://github.com/facebook/react/pull/27058
- https://github.com/facebook/react/pull/27142
- https://github.com/facebook/react/pull/27133
- https://github.com/facebook/react/pull/27130
- https://github.com/facebook/react/pull/27105
- https://github.com/facebook/react/pull/27117
- https://github.com/facebook/react/pull/27057
2023-08-08 20:16:24 +00:00
Tobias Koppers
9d1b3f43a1
Turbopack: add hmr test case and fix bugs (#53719)
### What?

test case for HMR

### Turbopack Changes

* https://github.com/vercel/turbo/pull/5686 <!-- Tobias Koppers - remove
error in update -->
2023-08-08 17:07:24 +02:00
vercel-release-bot
d7405b0c28 v13.4.14-canary.1 2023-08-08 14:11:47 +00:00
Alex Kirszenberg
589150184e
Turbopack: Hide Turbo Engine internals (#53007)
See https://github.com/vercel/turbo/pull/5584
2023-08-07 14:55:13 +00:00
vercel-release-bot
5ea372d642 v13.4.14-canary.0 2023-08-07 12:49:08 +00:00
vercel-release-bot
498692b698 v13.4.13 2023-08-07 06:57:47 +00:00
vercel-release-bot
1e02a92a94 v13.4.13-canary.18 2023-08-07 01:06:01 +00:00
JJ Kasper
6483903372
Add update fonts workflow (#53645)
This adds a workflow to auto update our fonts data so we can stay up to date easier. 

Closes: https://github.com/vercel/next.js/pull/53246
Closes: https://github.com/vercel/next.js/pull/53510
2023-08-07 00:11:03 +00:00