Commit graph

8122 commits

Author SHA1 Message Date
Corey Larson
42abfd694d
Ensures App Router Link respects scroll-behavior: smooth when only hash is changed. (#54243)
Fixes https://github.com/vercel/next.js/issues/54240

The Link component in App Router is not respecting `scroll-behavior: smooth` when only the hash changes.

It appears to be caused by `focusAndScrollRef.onlyHashChange = false` being set before `handleSmoothScroll` is called, causing `htmlElement.style.scrollBehavior` to be overridden to `auto` before `scrollIntoView` is called.

Moving `focusAndScrollRef.onlyHashChange = false` to after `handleSmoothScroll` invocation resolves the issue.
2023-08-18 20:58:45 +00:00
David Goguen
a0749a5103
feat(image): add support for custom loaderFile when loader: default (#53417)
Image Optimization API currently does not work if a custom loaderFile is specified in next.config.js, even if loader is explicitly set to 'default', because it is currently being overridden to 'custom' simply because a loaderFile is specified. This is unnecessary and causing the Image Optimization API routes not to be initialized since the change to the config happens before the routes are initialized.

[Sandbox Reproduction](https://codesandbox.io/p/sandbox/purple-pine-t7hhgl?file=%2Fimage-loader.js%3A8%2C1)

- Fixes #53415
2023-08-18 20:05:17 +00:00
Jiachi Liu
c305bf6afb
Add default not found to loader tree of group routes root layer (#54228)
For group routes, unlike normal routes, the root layout is located in the "group"'s segment instead of root layer.
To make it also able to leverage the default not found error component as root not found component, we need to determine if we're in the root group segment in the loader tree, and add the not-found boundary for it.


If you compre the loader tree visually they will look like this:

Normal route tree structure
```
['',
 { children: [segment, {...}, {...}]},
 { layout: ..., 'not-found': ... }
]
```

Group routes
```
[''
 { children: ['(group)', {...}, { layout, 'not-found': ... }]}
 {}
]
```

Comparing to normal case, we go 1 layer down in the tree for group routes, then insert the not-found boundary there

Fixes #52255
Closes NEXT-1532
2023-08-18 16:56:55 +00:00
Shu Ding
b906fdfbeb
Use createClientModuleProxy from Flight Server (#54232)
This PR removes our client module reference proxy implementation to directly use the one from the upstream Flight server, as it's added here: https://github.com/facebook/react/pull/27033.

Also updated the server reference creation code a bit to use `defineProperties` - we can't switch to the upstream `registerServerReference` API yet as our Server Actions compiler needs to change a bit to adapt that API since we might have existing `bound` and/or `originalAction` provided.
2023-08-18 15:31:25 +00:00
Shu Ding
b25407e4e4
Add Route and LinkProps stub generics (#54226)
Closes #53732. Closes #52929.

When using the statically typed routes feature, we might have code like:

```ts
export function Card<T extends string>({ href }: { href: Route<T> | URL })...
export function Card<T extends string>({ href }: LinkProps<T>)...
```

To statically check `<Card href={...}>` and make sure it's `href` is an existing route. However, in certain cases these route types are not generated (e.g. running `tsc` directly w/o a `next dev` or `next build`), which results in TS errors.

This PR adds stub generics to `Route` and `LinkProps` so even if that plugin isn't executed, these types will not block type checking.
2023-08-18 14:41:21 +00:00
Shu Ding
ec438418a4
Fix missing devPageFiles collection (#54224)
Closes #54168. This was accidentally removed from a code refactoring.
2023-08-18 14:16:11 +00:00
Zack Tanner
803bbe5c93
fix process.env not being available in standalone mode (#54203)
### What?
When running Next in standalone mode, `process.env` is not made
available to the render workers, making it impossible to access
environment variables that aren't provided in `.env` files.

### Why?
`initialEnv` is undefined in `createWorkers` when the server is started
in standalone mode.

### How?
This initializes the workers with `process.env` in case `initialEnv` is
unavailable, similar to the behavior of `loadEnvConfig()`

Closes NEXT-1508
Fixes #53367
2023-08-18 16:04:48 +02:00
Steven
cfa07f4f63
chore: remove unnecessary type cast in dev-build-watcher (#54221)
I accidentally left this type cast in from previous PR https://github.com/vercel/next.js/pull/54074 but it is unnecessary.
2023-08-18 13:39:55 +00:00
Kim In Seop
132d3e8f97
fix: invalid module transform for @headlessui/react (#54206)
occured since #54188

- `*`: use kebabcase instead of lowercase
- Transition: `components/transitions/transition`
- Tab: `components/tabs/tabs`

```plain
- wait compiling /not-found (client and server)...
- error ./node_modules/.pnpm/@headlessui+react@1.7.17_react-dom@18.2.0_react@18.2.0/node_modules/@headlessui/react/dist/headlessui.esm.js:2:0
Module not found: Can't resolve '/Projects/node_modules/.pnpm/@headlessui+react@1.7.17_react-dom@18.2.0_react@18.2.0/node_modules/@headlessui/react/dist/components/tab/tab'
```




Co-authored-by: Shu Ding <3676859+shuding@users.noreply.github.com>
2023-08-18 10:33:33 +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
Zack Tanner
c676f9357e
fix bfcache restoration behavior (#54198)
Follow up to https://github.com/vercel/next.js/pull/54081 -- this was
restoring the router tree improperly causing an error on bfcache hits

Had to override some default behaviors to prevent `forward` / `back` in
playwright from hanging indefinitely since no load event is firing in
these cases

Fixes #54184
Closes NEXT-1528
2023-08-18 00:05:26 +02:00
Malte Ubl
631018a674
Automatically modularizeImports for the popular @headlessui/react library (#54188)
`import { Listbox } from "@headlessui-float/react";` becomes
`import { Listbox } from "@headlessui/react/dist/components/listbox/listbox";`
2023-08-17 21:38:20 +00:00
Jiachi Liu
e20c8c824c
Assign default not-found boundary if custom not-found is not present for root layer only (#54185)
Fixes #54174 

We should only add default not-found boundary to loader tree components for root layout. It was accidently added for children routes before
2023-08-17 18:27:27 +00:00
Ben Brook
847c14ea15
Add size property to ReadonlySearchParams (#53144)
Closes #49774 (and my dupe https://github.com/vercel/next.js/issues/53141), where there's a type error when attempting to construct URLSearchParams from ReadonlyURLSearchParams, [as recommended in the Next docs here](https://nextjs.org/docs/app/api-reference/functions/use-search-params#updating-searchparams) and breaks `next build` on Node v18.16.0+, including on Vercel.


This is blocked by TS publishing the new `dom` types (https://github.com/microsoft/TypeScript/issues/54466). The [URL Standard](https://url.spec.whatwg.org/#dom-urlsearchparams-size) added the size property to URLSearchParams (https://github.com/whatwg/url/pull/734) and this now has wide [browser support](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams/size).
2023-08-17 18:15:45 +00:00
Steven
3fadba5aba
chore: improve ts types for position in dev-build-watcher (#54124)
- Follow up to https://github.com/vercel/next.js/pull/54074
2023-08-17 15:36:35 +00:00
Shu Ding
df1de76c5c
Remove unused variables (#54149)
These are not referenced anywhere in the codebase.
2023-08-17 11:56:56 +00:00
Jiachi Liu
bc87328609
refactor: remove edge condition for module proxy path (#54167)
For edge-runtime we always bundle, and all the mapping of internal ESM files are configured in webpack. Adding a new alias of "next/dist/build" so we don't have to manually check the mapping path for module proxy
2023-08-17 11:33:26 +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
Will Binns-Smith
bd5b715d18
Debug tracing: Include navigation through hydration timing (#54078)
This:
- Adds a simple, generic tracer in the client that can be subscribed to in order to report spans
- Reports client spans through the HMR socket in the dev server
- Receives these spans and includes them in `.next/trace`


Closes WEB-1387
2023-08-17 00:48:44 +00:00
Max Leiter
6767454b57
node-web-streams: remove tee shim, use ReadableStream.tee (#54079)
### What?
~The `setTimeout(() => {}, 0)` was used in place of `setImmediate` due to lack of support in the Edge Runtime. This is no longer a problem.~ Not working like I expected. 

`ReadableStream.tee` should be widely supported as well as of [Node 16.5](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/tee#browser_compatibility)

### Why?
Use the platform!

### How?
Use the built-in `ReadableStream.tee()`
2023-08-17 00:27:49 +00:00
vercel-release-bot
93259caac4 v13.4.17-canary.0 2023-08-16 21:11:24 +00:00
Zack Tanner
4f7fc05f9e
cleanup: remove unnecessary effect dep (#54134)
Accidentally left this in after making some changes in:

- https://github.com/vercel/next.js/pull/54081
2023-08-16 19:53:23 +00:00
Dima Voytenko
bdd0f545c2
OpenTel: remove the internal (ipc) fetched from traces in a non-verbose mode (#54083)
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">
2023-08-16 19:41:21 +00:00
Balázs Orbán
af97755e3c
fix(edge): override init when cloning with NextRequest (#54108)
### 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
2023-08-16 18:54:35 +00:00
Will Binns-Smith
96dd8ff4a5
Tracing: add opt-in flag to send a subset of development traces to url (#53880)
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.
2023-08-16 18:36:52 +00:00
Zack Tanner
0b3e366f32
fix routing bug when bfcache is hit following an mpa navigation (#54081)
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
2023-08-16 17:55:06 +00:00
Steven
86d2ead1fe
chore(image): remove apple silicon workaround for versions older than node@16.5.0 (#54125)
Since Next.js already requires [`node@16.8.0`](88b8d15f41/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
2023-08-16 17:35:02 +00:00
Jiachi Liu
73217b5696
Refactor layout router creation in app-render (#54126)
Merge the rendering of `<LayoutRouter>` component into one place, with different props in different branches.
2023-08-16 17:22:41 +00:00
Steven
f944e984bd
chore: refactor to use fs.promises.rm() (#54076)
Since Next.js already requires [`node@16.8.0`](88b8d15f41/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
2023-08-16 15:30:30 +00:00
Steven
9f3fd5d70a
chore: remove as any type cast (#54074)
This PR refactors some types to remove `as any`, but the runtime logic is the same.
2023-08-16 15:22:08 +00:00
Jiachi Liu
594f3d1fc0
Fix root not-found page tree loader structure (#54080)
### 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
2023-08-16 15:10:08 +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
stefanprobst
42227559c6
fix: don't add forceConsistentCasingInFileNames to tsconfig when ts version >= 5.0 (#51564)
Currently, Next.js enforces that `forceConsistentCasingInFileNames: true` is added to a user's `tsconfig.json`.

This PR removes that behavior for CNA templates, and when the typescript version is >= 5.0.0, because since ts 5.0 `forceConsistentCasingInFileNames` is `true` by default. See https://devblogs.microsoft.com/typescript/announcing-typescript-5-0/

related: https://github.com/vercel/next.js/issues/45617
2023-08-15 19:12:40 +00:00
OJ Kwon
47e6b180f4
fix(next-swc): coerce mdxrs default options (#54068)
### What?

wasm-bindgen's serde deserialization is more strict to not automatically coerce non-optionable default values for the mdx configurations. Since these are required options anyway, consolidate to construct default options.


Closes WEB-1384
2023-08-15 18:19:16 +00:00
Will Binns-Smith
36602e7fdd
Debug tracing: add updated modules and page to HMR span (#53698)
This adds tags for `updatedModules` (an array of relative paths to changed modules that caused the hmr update) and `page` (the path to the updated page) to the `client-hmr-latency` event.

Test Plan: Ran `next dev` in a test app, changed a source file, and observed that the `client-hmr-latency` span in `.next/trace` has correct `page` and `updatedModules` tags.
2023-08-15 17:20:13 +00:00
Zack Tanner
cb432eb42d
Fix scroll bailout logic when targeting fixed/sticky elements (#53873)
### What?
When navigating to a new page with fixed or sticky positioned element as the first element, we were bailing on scroll to top behavior, which often isn't expected.

### Why?
Currently, we decide to bail on scroll to top behavior on navigation if the content that is swapped into view is visible within the viewport. Since fixed/sticky positioned elements are often intended to be relative to the current viewport, it's most likely not the case that you'd want it to be considered in this heuristic. For example, if you were scrolled far down on a page, and you navigated to a page that makes use of a sticky header, you would not be scrolled to the top of the page because that sticky header is technically visible within the viewport. 

### How?
I've updated the previous implementation that was intended to skip targeting invisible elements to also skip over fixed or sticky elements. This should help by falling back to the next level of the layout tree to determine which element to scroll to.

I've deleted the `// TODO-APP` comments as I couldn't think of a scenario in which we'd need a global scrollTop handler -- if we've bailed on every element up the tree, it's likely the page wasn't scrollable.

Some additional considerations:
- Is the warning helpful or annoying?
- Is the parallel route trade-off an acceptable one? (ie, a parallel modal slot might not be considered in the content visibility check unless if it’s fixed positioned)

Closes NEXT-1393
Fixes #47475
2023-08-15 13:31:39 +00:00
Jiachi Liu
ec6d2c7825
Do not output pages 404 in tree view if app not-found is used (#54051)
### What?

Skip logging `/404` for pages routes in `next build` when app router root not-found is present

### Why?

When app router's root not-found is used it can cover all the not found cases, and for static rendering it can already replace the `404.html`. So in the tree view we don't need to log the pages `/404` when those cases are covered by app router.
2023-08-15 09:59:43 +00:00
Zack Tanner
e02397d264
fix: pages not visible in dev when named children (#54007)
`getEntryKey` had some logic to remove `children` if it was part of the entry (originally it was intended to fix an issue with parallel slots that were used in place of a page, but wasn't working as intended). However, this breaks pages that are named `children`.

Updating this again to implement what I think was the intended behavior in 4900fa21b0 which is to point to the correct entry when a parallel slot is used in place of a page component. 

- x-ref: #52362

Closes NEXT-1514
Fixes #53072
2023-08-15 03:50:37 +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
Matt Cowley
c1fa78bf6c
fix(next/image): empty blur image when animated (#54028)
Partial fix for #54012: do not generate a blur image in the image loader when the image is detected to be animated, rather than returning the *entire* animated image as the blur image.
2023-08-15 02:17:40 +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
Shu Ding
cd95fe4085
Adjust internal action proxy export (#54004)
This PR changes the internal `createActionProxy` util from a default
export to a named export, as the default export could be problematic if
it's built without the "esModuleInterop" step.

---------

Co-authored-by: Balázs Orbán <info@balazsorban.com>
2023-08-15 01:16:28 +02:00
vercel-release-bot
4d0aaafdef v13.4.16-canary.0 2023-08-14 22:26:27 +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