Commit graph

1097 commits

Author SHA1 Message Date
Jiachi Liu
a141366ff6
Error for missing dynamic generated id and refactor metadata image url (#48953)
### What?

In #48928 we decided to error for the missing `id` from `generateImageMetadata` and `generateSitemaps` for better dev DX. This PR also refactors the metadata image urls generation that assumbling the utils together
2023-04-28 14:06:07 +00:00
Jan Kaifer
cc2bcece63
Start recommending gRPC with otel (#48915) 2023-04-28 11:43:28 +00:00
Jiachi Liu
44dc4efad2
Fix dynamic routes for generateImageMetadata (#48928)
* Fix the `generateImageMetadata` for non dynamic routes and related
`param` matching (Found during development)
* Fix dynamic routes with number suffix `(\d)` (Fixes #48689)
2023-04-28 12:27:21 +02:00
Balázs Orbán
88a033fa1f
chore: expose globalThis.crypto when not available (#48941)
### What?

Exposing `globalThis.crypto`, based on [Node.js' WebCrypto
API](https://nodejs.org/api/globals.html#crypto_1)

### Why?

Similar to `fetch`, `crypto` is a popular API that is currently not
available on `globalThis` in all active Node.js versions yet.

This can help library authors to create runtime-agnostic packages.

### How?

Node.js already has the WebCrypto API that can be imported, we just
expose it on `globalThis` in Node.js versions where this is not
available.

Closes NEXT-1063

[Slack
thread](https://vercel.slack.com/archives/C03KAR5DCKC/p1681821510191059)
2023-04-28 11:18:55 +02:00
sagarpreet-xflowpay
0918ebd69a
fixes #48794 : When using pageExtensions like "page.jsx", global css import not working (#48795)
fixes #48794 


<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation or adding/fixing Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md



## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

---------

Co-authored-by: Jimmy Lai <laijimmy0@gmail.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2023-04-28 10:23:00 +02:00
Josh Story
7a5ef27b5e
Preload css (#48840)
This PR implements preloading of CSS from RSC.

1. The underlying Flight protocol was extended in
https://github.com/facebook/react/pull/26502 to allow sending hints from
RSC to SSR and Client runtimes. React was updated to include these
changes.
2. We now call `ReactDOM.preload()` for each stylesheet used in a
layout/page layer

There are a few implementation details to take note of
1. we were previously using the `.browser` variant of a few React
packages. This was a holdover from when there was just browser and node
and we wanted to use the browser variant b/c we wanted the same code to
work in edge/node runtimes. React now publishes a `.edge` variant which
is like `.browser` but expects to be server only. This is necessary to
get the opt-in for `AsyncLocalStorage`.
2. Even with the above change, AsyncLocalStorage was not patched on the
global scope until after React was loaded. I moved this into a module
which is loaded first
3. The component passed to RSC's `renderToReadableStream` is not
actually part of the RSC module graph. If I tried to call
`ReactDOM.preload()` inside that function or any other function defined
inside `app-render.tsx` file it would actually see the wrong instance of
`react-dom`. I added a new export on the RSC top level export which
exposes a `preloadStyle(...)` function which just delegates to
`ReactDOM.preload(...)`. This makes the preload run in the right module
graph


~There are a couple of bugs in React that this work uncovered that I
will upstream. We may want to delay merging until they are addressed.
I'll update this comment when that is complete.~
1. ~React, during SSR, can emit a preload for a style twice in some
circumstances because late discovered stylesheets don't consider whether
a preload has already been flushed when preparing to reveal a boundary
they are within~
2. ~React, during RSC updates on the client, can preload a style that is
already in the document because it currently only looks for existing
preload links and does not consider if there is a stylesheet link with
the same href.~

~both of these issues will not break functionality, they just make the
network tab look at bit more noisy. We would expect network deduping to
prevent multiple actual loads~

The above React bugs were fixed and included now in the React update in
this PR

---------

Co-authored-by: Shu Ding <g@shud.in>
2023-04-27 12:51:52 +02:00
Tim Neutkens
d9850940ad
Fix scrolling when invisible element is targeted (#48874)
### What?

Mux reported they're experiencing a specific case where scroll wasn't
applied. I've found a bug when the first element in a layout or page,
the one that React will return from `findDOMNode`, is display: hidden.
At that point the rect is is `0` `0` `0` `0` and the current logic
assumes that means it's in the viewport as it's top `0`.

In order to fix this I've looked at a few ways:

- Scrolling to top when the element is not visible
- Scrolling to the parent element that is visible
- **Scrolling to the closest sibling (nextSibling) of the element that
is visible**

Eventually I landed on the third option after looking at the Mux case,
my reproduction, and the way vercel.com's pages leveraging App Router
are structured.

### How?

Used a while loop to check if the domNode is visible, if not we continue
to the next sibling until one that is visible is found. If none are
found we bail on resolving further.

While looking into this it highlighted that we should add a global
scroll handler in app-router too for the case where none of the
layout-routers apply scroll. With this fix that is less urgent though so
I've added a todo.


Fixes NEXT-1056

<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation or adding/fixing Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md



## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->
2023-04-27 10:00:51 +02:00
Jiachi Liu
98e0c4a51c
External vercel og for nodejs runtime (#48844)
### Why

Default font file of `@vercel/og` is not loaded, because the og package is bundled by webpack and we should external it so that `fs.readFileSync` is bundled and manged that can't be traced by nft.


### How
This PR externals `@vercel/og` so that they don't need to be bundled and files can be properly traced

Closes NEXT-1047
Fixes #48704
2023-04-26 23:36:42 +00:00
Jiachi Liu
7c1ee055ce
test: disable client cache flaky test (#48890)
x-ref: https://github.com/vercel/next.js/actions/runs/4813019532/jobs/8569073395?pr=48844
2023-04-26 21:44:50 +00:00
Jiachi Liu
a4d63092e8
Support generate dynamic sitemaps for dynamic routes (#48867)
### What

For dynamic routes you might have different sitemap for different params

* Unloack using `sitemap.[ext]` in your app everywhere
* Support `generateSitemaps()` to create multiple sitemaps at the same time

### How

* Change the metadata regex to allow use sitemap in every routes
* Similar approach to `generateImageMetadata`, we make `sitemap.js` under dynamic routes to a catch all routes, and it can have multiple routes

Closes NEXT-1054
2023-04-26 20:41:37 +00:00
Shu Ding
b6e0c350ed
Update the mutableCookies class to accept extra options (#48877)
This PR changes `mutableCookies` from `RequestCookies` to a
`ResponseCookies` instance, and it now accepts extra options for each
cookie. Take a look at the tests for more details.

cc @styfle

---------

Co-authored-by: Steven <steven@ceriously.com>
2023-04-26 19:13:03 +00:00
Shu Ding
b21fd96606
Implement MutableRequestCookies in server entries (#48847)
Similar to #47922 but based off the latest server implementation and #48626:

> This PR implements the MutableRequestCookies instance for cookies() based on the current async context, so we can allow setting cookies in certain places such as Server Functions and Route handlers. Note that to support Route Handlers, we need to also implement the logic of merging Response's Set-Cookie header and the cookies() mutations, hence it's not included in this PR.
>
> fix [NEXT-942](https://linear.app/vercel/issue/NEXT-942)

This PR also adds the same support for Custom Routes.

cc @styfle.

fix NEXT-942, fix NEXT-941.
2023-04-26 13:19:01 +00:00
Jiachi Liu
5b609e264f
Error on legacy runtime config under app dir (#48774)
When you're using `config` object with `runtime` we'll show a warning and recomment you to move to `export const runtime = ...` for runtime property as it's documented as recommended. This PR adds a error for `next build` to avoid logs are truncated during multi-workers build and you're aware of the config which doesn't take effect with seeing the error

Follow up for #48630
link [NEXT-426](https://linear.app/vercel/issue/NEXT-426)
2023-04-24 18:33:29 +00:00
Shu Ding
03f34625e5
Polyfill FormData for Node.js < 18 (#48783)
We currently use `URLSearchParams` to represent `FormData` but it's not really the same thing. And in Node.js 16 there's no `FormData` available so we can polyfill it via Undici.
2023-04-24 15:48:10 +00:00
Jan Kaifer
8460373c26
Fix issue with instrumentation in a standalone build (#48615) 2023-04-24 13:49:46 +00:00
Jan Kaifer
db764c35e6
Add support for async instrumentation register (#48575) 2023-04-24 11:43:50 +00:00
Chris
2679ab672d
Update naming for Next.js Analytics (#48618)
Updates the name of Next.js Analytics to Next.js Speed Insights

closes ALY-579

---------

Co-authored-by: Steven <steven@ceriously.com>
Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
2023-04-24 12:14:45 +02:00
Jiachi Liu
7de1a4070d
Reland "app-router: new client-side cache semantics" (#48695)
Reverts vercel/next.js#48688
fix NEXT-1011
2023-04-22 10:41:08 +00:00
Shu Ding
490dc864c6
Add test case for #48506 (#48696)
Closes NEXT-228
Closes NEXT-227
2023-04-21 22:59:08 +00:00
Jiachi Liu
8089d0a3bb
Revert "Reland app-router: new client-side cache semantics" (#48688)
Reverts vercel/next.js#48685

Temporary Revert again to investigate the hang job
fix NEXT-1011
2023-04-21 22:36:28 +02:00
Jiachi Liu
b61305afcc
Reland app-router: new client-side cache semantics (#48685)
Reland vercel/next.js#48383
fix NEXT-1011
2023-04-21 19:39:06 +00:00
Jiachi Liu
52fcc59717
Revert "app-router: new client-side cache semantics" (#48678)
Reverts vercel/next.js#48383
fix NEXT-1011

revert and re-land later
2023-04-21 17:21:58 +00:00
Jimmy Lai
abbf352643
misc: fix flaky prefetch test (#48666)
<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation or adding/fixing Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md



## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->
2023-04-21 16:59:55 +02:00
Jimmy Lai
658c600534
app-router: new client-side cache semantics (#48383)
This PR implements new cache semantics for the app router on the client.

## Context

Currently, on the App Router, every Link navigation is prefetched and
kept forever in the cache. This means that once you visit it, you will
always see the same version of the page for the duration of your
navigation.

## This PR

This PR introduces new semantics for how the App Router will cache
during navigations. Here's a TL;DR of the changes:
- all navigations (prefetched/unprefetched) are cached for a maximum of
30s from the time it was last accessed or created (in this order).
- in addition to this, the App Router will cache differently depending
on the `prefetch` prop passed to a `<Link>` component:
  - `prefetch={undefined}`/default behaviour:
- the router will prefetch the full page for static pages/partially for
dynamic pages
    - if accessed within 30s, it will use the cache
- after that, if accessed within 5 mins, it will re-fetch and suspend
below the nearest loading.js
- after those 5 mins, it will re-fetch the full content (with a new
loading.js boundary)
  - `prefetch={false}`:
    - the router will not prefetch anything
    - if accessed within 30s again, it will re-use the page
    - after that, it will re-fetch fully
  - `prefetch={true}`
- this will prefetch the full content of your page, dynamic or static
    - if accessed within 5 mins, it will re-use the page

## Follow ups

- we may add another API to control the cache TTL at the page level
- a way to opt-in for prefetch on hover even with prefetch={false}


<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation or adding/fixing Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md



## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

link NEXT-1011
2023-04-21 14:29:39 +02:00
Jiachi Liu
cc684d02bc
Add export runtime test for pages and fully remove experimental.runtime (#48630)
### What 

`export const runtime = 'experimental-edge'` also work for pages. This
PR add tests for that.

Closes NEXT-426

Follow up for #46631 that to fully remove all related code of the
`experimental.runtime`
2023-04-20 22:37:38 +00:00
Shu Ding
ebddbf1b00
Add test case for #48583 and ignore hot-update scripts (#48587)
Add a test case for #48583.
2023-04-20 14:32:31 +00:00
Tim Neutkens
925bb3b025
Upgrade React (#48589)
Second try for #48561

<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation or adding/fixing Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md



## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

---------

Co-authored-by: Sophie Alpert <git@sophiebits.com>
Co-authored-by: Shu Ding <g@shud.in>
2023-04-20 02:05:49 +02:00
JJ Kasper
864f065392
Add updated app dir cache handling (#48516)
This adds the discussed updated cache handling for app dir for more fine
grained control over the cached values. Also adds initial
`revalidateTag` and `revalidatePath` exports from `next/server` although
export location may change.

Continuation of https://github.com/vercel/next.js/pull/47720

x-ref: [slack
thread](https://vercel.slack.com/archives/C042LHPJ1NX/p1681404363048459)
2023-04-19 18:12:21 -04:00
Shu Ding
191acdf8cb
Remove expired link resources via MutationObserver during development (#48578)
Closes NEXT-684, closes #43396.

This PR implements a temporary workaround to address the issue that some
browsers are always caching CSS resources during the lifetime of a
session. We re-introduce the versioning query to the resource to avoid
that, and then use Mutation Observer to do GC manually on the client.
Once Float handles that by itself, we can probably remove this.

Note that correctly handling GC here is **required** for correctness,
not an optimization. That's why it took us a while to address this (even
this PR is still a temporary workaround). Imagine that if you have:

```css
h1 {
  color: red;
}
```

and then you changed it to:

```css
h1 {
  font-size: 300px;
}
```

During HMR, if we don't remove the old resources but only insert the new
one, both will be applied and you will still see the `<h1>` in red,
which is wrong.

Here's a recording of this PR working correctly in Firefox:


https://user-images.githubusercontent.com/3676859/233132831-b88e4d8d-aec9-48c4-9aa7-7c7a149b377d.mp4
2023-04-19 16:38:52 +00:00
Jiachi Liu
0a04ab65b6
Fallback to deployment vercel url if metadataBase is not set on prod (#48570)
x-ref:
https://github.com/vercel/next.js/pull/48556#discussion_r1171163992

For production deployment, we still fallback to deployment URL if
`metadataBase` is not set.
2023-04-19 13:45:51 +00:00
Jiachi Liu
6f30c911d6
Prefer to use deployment url for metadata routes on production (#48556)
Use should only need to configure one `metadataBase` as fixed domain or
url but metadata image routes can still work properly with `VERCEL_URL`
in preview deployments

If you configured `new URL('https://mydomain.com')`, it will work for
canonical url all the time since it's for SEO.
For preview deployments metadata image routes will work with deployment
url as they're always bound with deployment.
For production deployments metadata images routes can be alias to the
configured `metadataBase` as they could be the expected exposed domain

Follow up for #47910

link NEXT-887
2023-04-19 10:26:08 +00:00
Jiachi Liu
96923ed894
Fix static opt of routes generation for static metadata files (#48528)
x-ref: [slack
thread](https://vercel.slack.com/archives/C03KAR5DCKC/p1681781435607369)

For static metadata files, we should always generate static routes
instead of generate dynamic routes, so that they won't be deployed as
serverless functions which executing file reading in deployment
2023-04-18 12:13:55 +00:00
Maia Teegarden
43d09ce2fd
Update swc_core to v0.75.23 (#48098)
Depends on https://github.com/vercel/turbo/pull/4470

---

 - Closes https://github.com/vercel/next.js/issues/46989
 - Fixes WEB-879
 - Fixes WEB-813

---------

Co-authored-by: OJ Kwon <1210596+kwonoj@users.noreply.github.com>
Co-authored-by: Donny/강동윤 <kdy1997.dev@gmail.com>
Co-authored-by: Shu Ding <g@shud.in>
2023-04-18 08:59:52 +02:00
Shu Ding
d9e3803e64
Fix server references handling in the edge runtime (#48502)
Currently POST requests to `"use server"` entries are not correctly
handled, and this PR partially fixes the behavior. Note that the
`isMultipartAction` case is still missing as we can't simply use
`busboy`. Later we'll unify the implementation here to always use
FormData via Undici.

Fixes NEXT-1026.
2023-04-18 00:36:23 +02:00
Jiachi Liu
1c67740676
Drop object config export support for app dir (#48489)
We've supported `export const config = { ... }` to sepecify `runtime`
etc. configs for pages under `app/` for a while. This PR is going to
drop it and only support `export const [config name] = [config value]`
per config

Add a warning if the legacy usage is detectd

Closes NEXT-1016
2023-04-17 20:02:32 +00:00
Shu Ding
f6604d4afe
Revert "Re-land "Vendor react@experimental under an experimentalReact flag"" (#48478)
Reverts vercel/next.js#48041
fix NEXT-926
2023-04-17 15:00:02 +02:00
Shu Ding
2a61253f72
Fix misordered CSS resources (#48244)
### What?

This PR fixes misordered CSS `<link>` tags. CSS imports in inner layers
(e.g. a page) should always take precedence over outer layers (e.g. root
layout), but currently it's reversed.

### Why?

In layouts we usually define more general styles like globals, resets,
and layout specific things. And in inner layers and pages, things need
to be more detailed and override upper layers if there're any conflicts.

Previously we defined the component segment as

```tsx
<>
  <Component {...props} />
  {assets}
</>
```

which is necessary because of `findDOMNode` - if we put `assets` before
the component, we can't find the correct scrolling DOM and position for
that layer.

However, with `assets` being the last Float will receive the reversed
order of resources.

### How?

I changed the `createComponentTree` function to return a `Component` and
`assets` pair, so in the Layout Router they're no longer passed to the
scroll wrapper altogether but separately.

Closes NEXT-983
Fixes #47585, fixes #46347.

fix NEXT-656

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2023-04-17 14:11:47 +02:00
Jimmy Lai
9f67638999
parallel routes: fix incorrect optimistic tree when there are multiple parallel routes (#48449)
This PR fixes parallel routes navigation with `prefetch={false}`. This
was broken because the optimistic tree created when navigating with
prefetching disabled resulted in a state where the router tree was
expecting an incorrect node to be rendered and suspended until the
imaginary data arrived.

The fix consists of updating the method that creates the optimistic tree
in order to bailout of the optimistic tree creation when there are
multiple parallel routes for the current node.

<!-- 

## For Contributors

### Improving Documentation or adding/fixing Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md



## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

fix #48122
link NEXT-1020

---------

Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
2023-04-17 10:12:46 +02:00
Jimmy Lai
ea8c4274b8
interception routes: fix production rewrites (#48451)
This PR fixes a bug with interception where the rewritten path passed an
incorrect segment data on production, resulting in a 404.

The fix consists of moving the rewrite pre-processing step that rewrites
the dynamic segment from the originating path to when we actually
generate the rewrite. This is needed because that step does not run on
production. Now it does and signals correctly to the app-render that the
value for the segment can be determined from the path.

Also enables prod testing, which I had forgotten to enable.

<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation or adding/fixing Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md



## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

fix #48406
link NEXT-1017
2023-04-17 10:08:25 +02:00
Jimmy Lai
612c8cb2bf
interception routes: support middleware rewrites (#48450)
This PR fixes an edge case when using interception routes and rewrites.
The issue was that the default state of the router tree incorrectly
assumed that the base pathname would be the referrer URL for the
interception but it turns out the tree/what we want to intercept can be
different in the case of a rewrite.

The fix consists of using the same method that we use to extract the
pathname from the current tree so that we can get the correct referrer
pathname.

## For Contributors

### Improving Documentation or adding/fixing Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md



## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

fix #48396
link NEXT-1018
2023-04-17 10:07:31 +02:00
Jimmy Lai
0741016023
parallel routes: fix next-provided default.js not being resolved if the config doesn't specify .js (#48446)
This PR fixes an edge case when the next config has `pageExtensions`
specified. When resolving the default parallel route, we use that
config. If it does not specify `.js` then it wouldn't be able to resolve
the default from Next.js

## For Contributors

### Improving Documentation or adding/fixing Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md



## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

fix #48431
link NEXT-1021
2023-04-17 10:06:50 +02:00
Jimmy Lai
2eb821ad19
parallel routes: fix catch-all routes taking precedence in dev (#48424)
This PR fixes a bug in dev with parallel routes when the given
conditions were met:
- you have a catch-all route and a more specific route
- you navigated to a catch-all route
- you navigate to the specific route that should take priority over the
catch-all

in this case, the route renderer would try to match with an incorrect
slot path and fallback to the catch all path

the fix makes the route renderer use the correct path, aka the last path
of the appPaths arrays for a given route

## For Contributors

### Improving Documentation or adding/fixing Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md



## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

link NEXT-1019
2023-04-17 10:06:30 +02:00
Jiachi Liu
7aba242b75
feat: generate image metadata (#48362)
### What?

* Support `generateMetadata(props)` to dynamically generate multiple
metadata images at the same time

```js
// /app/opengraph-image.tsx
import { ImageResponse } from 'next/server';

export async function generateImageMetadata({params}) {
  const images = await ...;
  return images.map((img, idx) => ({
    size: { width: 1200, height: 600 },
    alt: img.text,
    contentType: 'image/png',
    id: idx,
  }));
}

export default async function ({params, id}) {
  const text = await getTextFor(id);
  return new ImageResponse(
    (
      <div
        style={{...}}>
        {text}
      </div>),
    { width: 1200, height: 600 },
  );
}
```

### How?

Use `<metadata image>/[[...__metadata_id__]]/route.js` to catch all
metadata images id, and then use this `params.__metadata_id__` as id
argument for dynamic generate image.

If there's param, then we create `<metadata image>/<id>`, if there's
only 1 static image without dynamic `generateImageMetadata` then we keep
use `<metadata image>`

Closes NEXT-896
2023-04-14 20:52:31 +00:00
JJ Kasper
26a35a4798
Add test coverage for pages edge API routes (#48370)
Ensures we have coverage for edge API routes in pages so we don't
regress.

Closes: https://github.com/vercel/next.js/issues/48263
2023-04-13 22:07:54 -07:00
JJ Kasper
557084a331
Fix fetch cache body handling and update edge-runtime deps (#48365)
This ensures we don't fail to return the full body when storing to
fetch-cache in edge-runtime. Also ensures the fetch cache tests are
running for Node.js v16 correctly.

Fetch handling was also failing on Node.js v16 due to react's use of
`res.clone()` being broken with undici which is fixed in the latest
version of edge-runtime so this bumps that.

x-ref: [slack
thread](https://vercel.slack.com/archives/C03S8ED1DKM/p1681310566927429)
2023-04-13 22:00:20 -07:00
Andrew Gadzik
d598fa1847
Ensure we handle 204 responses in fetch (#48354)
Ensure we handle the use-case where a React Server Component using
`fetch` encounters a `204` response.

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2023-04-13 18:47:45 -07:00
Tim Neutkens
37f709eeb7
Investigate redirect getting stuck (#48343)
### What?

Fixes a bug where `fetch()` to a page that calls `redirect()` would hang
infinitely.

### How?

The `Location` header was missing. The reason this wasn't surfaced
before is that we also inject the `<meta>` tag to redirect which the
browser would pick up to redirect too.

Fixes NEXT-997

<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation or adding/fixing Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md



## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->
2023-04-13 16:17:15 -07:00
Jimmy Lai
0faf8bc900
interception routes: fix support for route groups (#48351)
fixes #48104 

This PR fixes route groups breaking interception routes. I hadn't
realised that route groups were actually part of the tree router, so we
were not stripping them out in the interception matcher. Fixed now.

<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation or adding/fixing Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md



## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->
2023-04-13 21:00:32 +00:00
Jimmy Lai
00b1c49c2b
app router: fix scrolling behaviour for parallel routes (#48346)
This PR fixes issues where rendering a new parallel route would reset
the scroll state of the page. This would be very apparent if you
scrolled down the page and opened a modal in a parallel route.

After a bit of investigating, I found out that the scroll behaviour
worked like this:
- after a navigation, we say to the router that we should auto-scroll if
possible
- but we don't specify which node of the tree should scroll
- so what happened is that the first router node to run the auto-scroll
effect would steal the auto-scroll, even though it might have been
destined for another node

The fix consists of
- when we received the flight patch, we compute all new segment paths
that will be rendered and add them to the scroll ref
- when the router says that we should autoscroll, the autoscroll
components will now read those paths and compare them with their segment
path and if yes, they will autoscroll


<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation or adding/fixing Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md



## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

link NEXT-974
2023-04-13 22:03:02 +02:00
Jiachi Liu
d569b83819
Auto collect custom manifest into metadata (#48310)
when custom manifest is found, collect it as metadata and insert into
head

Closes NEXT-988
2023-04-13 00:47:19 +00:00
Jiachi Liu
1d300456c0
Fix missing favicon when other icon exist (#48311)
When collecting static icons we need both collect the one from layout
and page, but for root level route `/` we missed the `favicon.ico`
before so when other icon existed, the root page's collected icons will
cover root layout collected ones, which resulted into favicon missing

Fixes #48147
Closes NEXT-976
2023-04-12 21:07:47 +00:00
Jiachi Liu
848e6fbfaa
Support alt.txt for static metadata og image (#48290)
### What

Support `opengraph-image.alt.txt` and `twitter-image.alt.txt` for static
og/tw metadata image when they need to specify alt txt.

Closes NEXT-990

### Why

for og/tw images, you could have multiple images, so it's tricky to set
alt in metadata exports with alt text. For static case we want it can
work with static files, `.alt.txt` files will be the type to provide alt
text content
2023-04-12 19:44:02 +00:00
Jimmy Lai
ccaa7d6482
parallel route: fix payload not being sent on refetch (#48294)
This PR fixes a bug introduced in #48253 where I inadvertently didn't
return the refetch payloads anymore

<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation or adding/fixing Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md



## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->
2023-04-12 17:37:37 +02:00
Yamagishi Kazutoshi
958150d15b
Add suffix to static metadata images (#48202)
### What?

The change in #47985 breaks the URLs of static image files like
`/(group)/opengraph-image.png` to `/opengraph-image.png-012345`.
References from `/` are also broken.

### Why?

This is because only `opengraph-image.ts` and `opengraph-image.tsx` are
considered.

### How?

In this Pull Request, we are trying to solve the problem by including
similar support for `opengraph-image.png` and `opengraph-image.jpeg`.

---------

Co-authored-by: Jiachi Liu <inbox@huozhi.im>
2023-04-12 14:30:31 +00:00
Jimmy Lai
92ddc4a27d
parallel routes: remove the per-route default 404 handler (#48286)
This PR fixes an issue where throwing a notFound error in a parallel
route at the top level at the root level would trigger a notfound
boundary at the parallel route level, which meant in practice that you
could still see the other slots being rendered below.

This behaviour is undesirable and was caused by the fact that we were
inserting a default one at each top-level parallel route. This is not
longer needed as we have a global one in `app-router.tsx`


<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation or adding/fixing Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md



## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->
fixes NEXT-968
2023-04-12 13:27:25 +02:00
Jimmy Lai
5977121e5e
interception routes: add new sibling matcher marker + validation (#48276)
This PR adds a new marker for intercepting siblings routes + adds some
validation to intercepting routes ( you shouldn't use (..) at the top
level!)

also fixes a bug with any interception from `/` when navigating from a
child route

the new marker, `(.)`, makes it easier to model cases like 
```
/profile/[id]
/profile/[id]/photos/[id]/
```

With the current syntax available, you’d need to do:
```with (..):
/profile/[id]/(..)[id]/photos/[id]

with (...):
/profile/[id]/(...)profile/[id]/photos/[id]

with (..)(..):
/profile/[id]/(..)(..)profile/[id]/photos/[id]
```

now, with (.)
```
/profile/[id]/(.)photos/[id]
```

<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation or adding/fixing Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md



## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

link NEXT-935
also fixes NEXT-970
fixes NEXT-973
2023-04-12 11:50:01 +02:00
Jimmy Lai
17e44d2907
app-router: add batching support for RSC router payloads (#48253)
This PR basically adds support for processing multiple router payloads.
Previously we were only handling one payload at a time but now that we
introduced parallel routes, we need to be able to render and return
separate parts of the layout separately.

Before, the single payload was generated in a DFS manner: we traversed
the router state and rendered the first segment of the tree that we
found needed rendering. In practice, this meant that we could miss
adjacent segments that might need to be re-rendered as well.

Now, we iterate all branches of the tree and return an array of flight
patches to be applied on the client correctly.

fixes NEXT-971

<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation or adding/fixing Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md



## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->
2023-04-12 09:53:13 +02:00
Shu Ding
c11bce5989
Opt-into worker mode when appDir is enabled (#47857)
This unblocks further optimization opportunities as well as fixes for
systematic problems such as NEXT-227. After this PR, only production
mode of non-app projects will be running on the legacy main process
mode.

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2023-04-11 22:26:49 +02:00
Jiachi Liu
83e05e6ee9
Remove warning for metadataBase fallback (#48196)
[slack
thread](https://vercel.slack.com/archives/C03KAR5DCKC/p1681079578508909)

Remove the warning for metadataBase when it fallback to default value,
as it's already clarified in
[docs](https://beta.nextjs.org/docs/api-reference/metadata#metadatabase)
2023-04-11 15:19:40 +02:00
Shu Ding
772f3e7509
Add experimental React related warning (#47986)
For now, this isn't a strong requirement as normal `fetch` requests will
still work with `react@next`. But in the future, form related props e.g.
`action=` and `formAction=` requires the experimental build.

Fixes NEXT-954.
2023-04-10 14:37:23 +02:00
Shu Ding
9c0e520896
Re-land "Vendor react@experimental under an experimentalReact flag" (#48041)
Reverts vercel/next.js#48038

fix NEXT-926

---

The root cause was that when copying the package.json, I removed all
fields except for a few (such as `exports`) but missed the `browser`
field. That caused the client bundle to resolve to the Node.js version
of React DOM, and then we had the `async_hooks` error. Added it back in
99c9b9e51f8b0d4e4503ece9d07bce09161f3341.

I reproduced the error with next-site earlier and confirmed that this
fix is good.
2023-04-08 17:16:24 +02:00
JJ Kasper
4e3f135fd6
Update flakey tests (#48113)
x-ref:
https://github.com/vercel/next.js/actions/runs/4642101338/jobs/8215704290
x-ref:
https://github.com/vercel/next.js/actions/runs/4641810347/jobs/8215208356
x-ref:
https://github.com/vercel/next.js/actions/runs/4640288495/jobs/8212579666
x-ref:
https://github.com/vercel/next.js/actions/runs/4640288495/jobs/8212653308
2023-04-07 17:54:17 -07:00
Jiachi Liu
71a29a17b8
Support og image with edge (#48086)
Fixing edge runtime doesn't work with exports from dynamic metaddata
image routes. If there's a match, don't do extra matching.

Fixes NEXT-866
2023-04-07 16:27:32 -07:00
Shu Ding
6b9af3e0d1
Fix fallback detection logic when multiple generateStaticParams are needed (#47982)
### What?

Our current logic of detecting if a route allows dynamic params or not
(`fallback`) is flawed, and this PR fixes it.

### Why?

Right now, if no `generateStaticParams` is specified we return
`fallback: undefined` during dev. However, for an app with multiple
params, it may have multiple `generateStaticParams` defined in different
levels. If some level isn't covered by any `generateStaticParams`, we
still can't determine the fallback value.

### How?

I added a naive implementation to check if all params are covered by
`generateStaticParams` in the current or inner layers.

Closes NEXT-946
2023-04-07 19:56:40 +02:00
Jimmy Lai
a71227a40f
parallel routes: fix layout not re-rendering (#48066)
### What?

This PR makes the parent layout of parallel routes re-render when the
parallel route segments are different or when either of them has a
refetch marker.

Example:
```
.
└── app/
    ├── page.ts
    ├── layout.ts
    ├── foo/
    │   └── page.ts
    └── @modal/
        ├── default.js
        └── foo/
            └── page.ts
```

Here if you navigated to `/foo` from `/`, `@modal/foo/page` would never
get re-rendered because the tree would only re-render from
`foo/page.ts`.

This PR adds a check that checks the router state on navigation to see
if the parallel route segments diverge on navigation. Here we would be
checking that `@modal/default` is different from `@modal/page` so we
would re-render.

Also added some logic to make sure that refetch routes are processed
first when handling parallel routes.

### Why?

See example

Closes NEXT-966
Fixes #


<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation or adding/fixing Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md



## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->
2023-04-07 15:23:08 +02:00
JJ Kasper
40687daed2
Update query param prefix to reduce length (#48051)
With the addition of the query prefix we can hit the max length for PCRE
named matches so this reduces the prefix length and ensures we go
through the param name validation still

x-ref: https://twitter.com/simonecervini/status/1644123851003928579
2023-04-06 17:52:24 -07:00
Jiachi Liu
1e81af047d
Change metadata routes suffix to number and chars (#48026)
Follow up of #47985 

Change `-\d{6}` to `-[a-z0-9]{6}` which reduces the chance of hash
collision
2023-04-06 16:38:02 -07:00
Wyatt Johnson
045ad0d133
Replaced Reflect with ReflectAdapter (#48000)
On some runtimes, `Reflect` is not available. This creates a new "naive"
implementation.
2023-04-06 21:18:42 +02:00
JJ Kasper
9448913149
Revert "Vendor react@experimental under an experimentalReact flag" (#48038)
x-ref: [slack
thread](https://vercel.slack.com/archives/C04DUD7EB1B/p1680804950611789?thread_ts=1680791613.468109&cid=C04DUD7EB1B)

Reverts vercel/next.js#47759
fix NEXT-926
2023-04-06 11:48:09 -07:00
Nabeel Sulieman
76ad58b0c8
Only cache successful fetches (#48033)
### What?

Change the caching logic for fetch-cache to only cache successful
responses.

### Why?

Currently fetch-cache will cache any response, without checking the http
status code. But situations like 500 and 304 and others should not be
cached, because we want to re-fetch from the origin.

### How?

Add an extra check before deciding to call `incrementalCache.set()`

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2023-04-06 11:41:15 -07:00
Jimmy Lai
946424efb3
parallel routes: return a 404 when a parallel route does not have a default page/do not match (#47872)
<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation or adding/fixing Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md



## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

fix NEXT-918

---------

Co-authored-by: Wyatt Johnson <accounts+github@wyattjoh.ca>
2023-04-06 19:19:35 +02:00
Jimmy Lai
1cf1198cab
interception routes: re-implementation (#48027)
The first implementation had limitation wrt to static routes so this is
a "simpler" approach to making interception work. This also fixes a few
bugs.

In this PR:
- changed the computation of the referrer route to now live on the
client state, since it's the only place where you can accurately keep
track of that. One router state was not sufficient, we needed a delta of
two states to guess which route had changed when having parallel routes
in the tree.
- uses rewrites as the basis for interception now instead of route
handlers, this means that we have to do some sketchy logic to make the
rules work since they only handle regexes whereas we have
`path/like/[this]`
- dev server now reloads rewrites as well when needed

<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation or adding/fixing Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md



## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->
2023-04-06 15:59:45 +00:00
Jiachi Liu
e4e5c1674a
Fix css applying for root not found (#47992)
### What

This issue is introduced in #47688, we need to do the same work for
rendering single component which collecting the assets and then render
with root layout + root not found

Fix #47970
Related #47862 (partially fix the css issue but not link issue)

### How

This PR encapsulates the preload and stylesheets assets collection and
rendering process, and move them into a helper, and share between the
component rendering and the root not found rendering
2023-04-06 13:37:55 +02:00
Jiachi Liu
c0751e8c81
Create unique route path for og under group routes (#47985)
### What

When using dynamic metadata image rouets (such as `opengraph-image.js`)
under group routes, the generated urls were still normalized. In this
case it might have conflicts with those ones not under group routes. For
instance `app/(post)/opengraph-image.js` could have same url with
`/app/opengraph-image.js`. In reality we want them to be different
route, unlike layout or pages.

### How

So when we found `()` or `@` signs from the metadata image urls, we'll
generate a unqiue suffix (`-\d{6}`) and append to the generated url. So
they can be isolated from the ones are not under special convention
routes.

Closes NEXT-937
2023-04-05 22:40:17 +00:00
Jiachi Liu
7af9c43911
Fix metadata nested twitter props rendering (#47972)
For twitter and og image nested properties we should render them as
snake case according to [og spec](https://ogp.me/) and [twitter card
docs](https://developer.twitter.com/en/docs/twitter-for-websites/cards/guides/getting-started).
For typing we keep them as camel case and then convert them to snake
case during render

This issue is reported in #47960 that user thinks the types are
incorrect, but turns out twitter metadata didn't render it correctly

Closes #47960
2023-04-05 22:15:10 +00:00
Tim Neutkens
a94de4c7d0
Check for null before reading value in useParams (#47875)
Ensures the `null` value is checked instead of destructuring the value
as it caused an error.
Also added a test to check for `useParams` in `pages`.

<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation or adding/fixing Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md



## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2023-04-05 21:51:52 +00:00
JJ Kasper
e3e22f5bed
Update search params/route params handling on deploy (#47930)
This ensures we prefix the dynamic route params in the query so that
they can be kept separate from actual query params from the initial
request.

Fixes: https://github.com/vercel/next.js/issues/43139
2023-04-05 14:14:40 -07:00
Wyatt Johnson
1fbbba6ffe
Unify Request types (#47884)
This serves to start the transition of replacing the following:

- Replace `BaseNextRequest`, `WebNextRequest`, and `NodeNextRequest`
with `NextRequest`
- Replace `BaseNextResponse`, `WebNextResponse`, and `NodeNextResponse`
with `Response`

This will currently only apply to app routes, enabling the following:

```ts
////////////////////////////////////////////////////////////////////////////////
// Use `Request` and `Response`
////////////////////////////////////////////////////////////////////////////////

import { NextRequest, NextResponse } from 'next/server'

export function GET(request: Request): Response {
  return new Response(
    JSON.stringify({
      hello: request.headers.get('user-agent'),
    }),
    { headers: { 'content-type': 'application/json' } }
  )
}

////////////////////////////////////////////////////////////////////////////////
// Use `NextRequest` and `NextResponse`
////////////////////////////////////////////////////////////////////////////////

import { NextRequest, NextResponse } from 'next/server'

export function GET(request: NextRequest): NextResponse {
  return NextResponse.json({ hello: request.headers.get('user-agent') })
}

////////////////////////////////////////////////////////////////////////////////
// Use `NextRequest` and `Response`
////////////////////////////////////////////////////////////////////////////////

import { NextRequest, NextResponse } from 'next/server'

// `NextRequest` extends `Request`.
export function GET(request: NextRequest): Response {
  return new Response(
    JSON.stringify({ hello: request.headers.get('user-agent') }),
    { headers: { 'content-type': 'application/json' } }
  )
}

////////////////////////////////////////////////////////////////////////////////
// Use `NextRequest`, `NextResponse`, and `Response`
////////////////////////////////////////////////////////////////////////////////

import { NextRequest, NextResponse } from 'next/server'

export function GET(request: NextRequest): Response {
  // `NextResponse` extends `Response`.
  return NextResponse.json({ hello: request.headers.get('user-agent') })
}

////////////////////////////////////////////////////////////////////////////////
// Use `Request` and `NextResponse`
////////////////////////////////////////////////////////////////////////////////

import { NextRequest, NextResponse } from 'next/server'

export function GET(request: Request): NextResponse {
  return NextResponse.json({ hello: request.headers.get('user-agent') })
}

```

fix NEXT-713
2023-04-05 18:24:08 +00:00
JJ Kasper
af694f6602
Fix app metadata in edge runtime (#47941)
Seems edge runtime started failing for app paths from `path` being added
in https://github.com/vercel/next.js/pull/47829 so this updates to use
the isomorphic version instead and adds a regression test.

Fixes NEXT-866
2023-04-05 17:32:42 +00:00
Jiachi Liu
3f75387bf1
Fallback to localhost for metadataBase when it's used and missing (#47910)
[slack
thread](https://vercel.slack.com/archives/C04G5LHAVAR/p1680106437791819?thread_ts=1680013412.588999&cid=C04G5LHAVAR)

When `metadataBase` is missing and used for resolving og/tw image urls,
we'll fallback to localhost for it to always safely resolve the url
instead of erroring. Instead, we give a warning in console for which url
is resolved but with fallback `metadataBase`.

Once they found the warning and it's not expected, they need to update
the `metadataBase` to a proper URL for giving the right domain.

Another minor change is always resolve canonical with current pathname
if it's a URL instance.
Remove `resolveStringUrl` as it's not required anymore, the default
`pathname` for `resolveUrl` is '', so no trailing slash needs to be
removed
2023-04-05 15:39:29 +00:00
Shu Ding
89b4605f1a
Vendor react@experimental under an experimentalReact flag (#47759)
Next.js includes various feature sets that depend on specific release
channels of React. However, our current setup only includes the `next`
channel of React, which restricts our ability to integrate with features
available on the `experimental` channel.

To address this limitation, this pull request introduces the following
changes:
- Vendors the `react@experimental` version, along with the corresponding
`react-dom` and `scheduler` packages.
- Modifies the `sync-react` script to also update the `experimental`
channel and removes `--version` as they're always synced to the latest
now.
- Retains the default behavior of using the `next` channel in the
`appDir` directory.
- Adds an option to switch to the `experimental` channel by setting
`experimental.experimentalReact: true` in the configuration.

fix NEXT-926 ([link](https://linear.app/vercel/issue/NEXT-926))
2023-04-05 14:05:47 +00:00
Tim Neutkens
d32ee25bfb
Add dynamic parameter marker to router cache key (#47957)
### What?

Took a bit to investigate this one, eventually found that the case where
it broke is this one:

```
app
├── [slug] // This matches `/blog`
│   └── page.js
└── blog
    └── [name] // This matches `/blog/a-post`
        └── page.js
```

The router cache key is based on the "static key" / "dynamic parameter
value" in the tree. This means that the cache key for `/blog` that
matches `/[slug]` would be the same as the static segment `blog`. This
caused the cache to become intertwined between those paths, it's
accidental that the router got stuck in that case, main reason it got
stuck is that the fetch for the RSC payload returned a deeper value than
expected. In `walkAddRefetch` we bailed because that walked the
`segmentPath` didn't match up.

The underlying problem with this was that the render would override the
cache nodes incorrectly. This would also cause wrong behavior, even
though that wasn't reported. E.g. `app/[slug]/layout.js` would apply on
`app/blog/[name]/page.js` because they'd share the `blog` cache node.

### How?

This PR changes the cache key to include the dynamic parameter name and
type, e.g. the dynamic segment `['slug', 'blog', 'd']` previously turned
into `'blog'` as the cache key, with these changes it turns into
`'slug|blog|d'`. For static segments like `blog` in `app/blog/[name]`
the key is still just `'blog'`.

I've also refactored the cases where we read the segment as the code was
duplicated in a few places.


Closes NEXT-877
Fixes #47297

<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation or adding/fixing Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md



## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

fix NEXT-877
2023-04-05 15:40:28 +02:00
JJ Kasper
199aa3c8f5
Add strict next head handling (#47938)
This adds an `experimental.strictNextHead` flag to allow updating head
tags tracking for pages to resolve the issue with runtime scripts being
appended to the head element breaking the head tracking.

Fixes: https://github.com/vercel/next.js/issues/11012
Fixes: https://github.com/vercel/next.js/issues/20682
x-ref: [slack
thread](https://vercel.slack.com/archives/C051B8JAPQ9/p1680156608831939)
2023-04-05 08:29:36 +00:00
Jiachi Liu
dcc0ef8e47
Hide not ENOENT errors for not found in ipc server (#47854)
Not to log not found errors created from on demand handlers in ipc
server

Remove the not found error trace for dev
```
event - compiled client and server successfully in 57 ms (265 modules)
/Users/huozhi/workspace/next.js/packages/next/src/server/dev/on-demand-entry-handler.ts:450
    throw new PageNotFoundError(normalizedPagePath)
          ^

Error: Cannot find module for page: /not-found
    at findPagePathData (/Users/huozhi/workspace/next.js/packages/next/src/server/dev/on-demand-entry-handler.ts:450:11)
    at Object.ensurePage (/Users/huozhi/workspace/next.js/packages/next/src/server/dev/on-demand-entry-handler.ts:701:30)
    at Server.<anonymous> (/Users/huozhi/workspace/next.js/packages/next/src/server/lib/server-ipc.ts:29:24) {
  code: 'ENOENT'
}
```
2023-04-04 11:46:49 -07:00
Shu Ding
2eeb0c7f49
Add missing module.hot.accept call to server CSS modules (#47913)
Since we compile global server CSS imports into a special module with a
checksum of the original content, it should always accept HMR updates.
This fixes `Fast Refresh had to perform a full reload` errors.
2023-04-04 18:56:54 +02:00
Jan Kaifer
a3acbf4f55
Add documentation on OTEL support (#47194)
Added docs that mention:
- important code-snippets from example
- links to official OTEL docs
- document NEXT_VERBOSE_OTEL
- explain what we provide out of the box
- what we don’t
- explain how you can add tracing yourself
- explain how instrumentation.js works
- it can be used for different types of instrumentation that don't use
OTEL. It's just a hook called when starting up a new node environment.

- list of all spans we instrument by default
 
fix NEXT-799 ([link](https://linear.app/vercel/issue/NEXT-799))

---------

Co-authored-by: S3Prototype <liuqahs15@gmail.com>
2023-04-04 14:24:46 +00:00
Jimmy Lai
eba1626b45
router: implement route interceptions (#47565)
This PR implements the route intercepting feature from [the layouts
RFC](https://nextjs.org/blog/layouts-rfc#intercepting-routes).

You can use route interception by adding these special markers,
`(..),(...) or (..)(..)` to your segment definition, i.e. by creating a
page with this path: `/foo/bar/(..)baz/page.ts`.

Changes in this PR:
- added a new kind of route handlers to support intercepting routes
- added a "referrer" concept that is derived from the client router
state on navigation, where we try to guess which URL you were on before
- added some units tests
- updated the renderer to allow for overrides when the path params don't
include the current dynamic param, so we rely on the passed router state
to create it

<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation or adding/fixing Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md



## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

fix NEXT-749 ([link](https://linear.app/vercel/issue/NEXT-749))

---------

Co-authored-by: Wyatt Johnson <accounts+github@wyattjoh.ca>
2023-04-04 14:06:24 +02:00
Jan Kaifer
aeec6b5d0f
Hide internal fetches OTel traces in dev mode and assert duplicate OTel spans are present only in dev mode (#47822) 2023-04-03 16:56:29 +00:00
Jiachi Liu
43b0043192
Polish metadata warnings (#47853)
- Add links to the error warning
- Log with warning prefix for every url that missing `metadataBase`, so users can easily locate where it's from

Closes NEXT-931
2023-04-03 14:02:48 +00:00
Jiachi Liu
68f328f920
Fix: fill route params for dynamic route metadata images url (#47829)
Should fill dynamic routes url with params when generate the metadata
image urls.

For `/(group)`, we need to normalize the path first;
For dynamic routes `/[slug]`, we need to fill the params.

Change the image module from `() => image` to `(prop) => image(proop)`
so we can fill the runtime `params` into url

Closes NEXT-932

---------
2023-04-02 23:42:33 -07:00
JJ Kasper
de97a94d5f
Update set-cookies deploy test (#47836)
x-ref:
https://github.com/vercel/next.js/actions/runs/4587341207/jobs/8100910706#step:6:704
2023-04-02 22:18:40 -07:00
JJ Kasper
808a27ca36
Update render IPC handling (#47835)
This removes usage of fetch for render IPC calls as it introduces issues
across Node.js versions, IPC error handling is also updated here to
correctly handle instanceof check on `PageNotFoundError`.

x-ref:
https://github.com/vercel/next.js/actions/runs/4590201858/jobs/8106478191
x-ref:
https://github.com/vercel/next.js/actions/runs/4590160716/jobs/8105898749
x-ref:
https://github.com/vercel/next.js/actions/runs/4590160716/jobs/8105898965
x-ref:
https://github.com/vercel/next.js/actions/runs/4590160716/jobs/8105900628
2023-04-02 21:56:46 -07:00
JJ Kasper
fdacca8abc
Add initial separated route resolving (#47208)
This updates to have a separate routing process and separate rendering
processes for `pages` and `app` so that we can properly isolate the two
since they rely on different react versions.

Besides allowing the above mentioned isolation this also helps us
control recovering from process crashes easier as pieces are more
isolated from one another e.g. an infinite loop during rendering will no
longer block the compiler and can be stopped/restarted as needed.

In follow-up PRs we will continue to separate out the routing logic from
the rendering logic so that each process only loads what is relevant to
it helping simplify the flow for requests regardless of type.

---------

Co-authored-by: Shu Ding <g@shud.in>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2023-04-02 15:17:15 +02:00
Tim Neutkens
9c99d79209
Fix prefetch only being applied once (#47797)
### What / why?

Currently there is a bug because the `subTreeData` can only be applied
once, however, we reuse the same response when a url was prefetched.
During the first render of the response we apply the cacheNodes and then
these should be reused for subsequent navigations. There's currently a
bug because `fillLazyItemsTillLeafWithHead` creates `LAZY_INITIALIZED`
cache nodes that don't copy the previous cache node `parallelRoutes` and
`subTreeData` value, causing the cache nodes below where the
`subTreeData` is applied to be deleted from the cache, even when they're
not affected by the navigation.

### How?

This PR adds copying of the cache node when it exists already, I've
added a marker for `wasPrefetched` to trigger that behavior but in
talking to @feedthejim about this it seems we can swap to this behavior
always when applying the server response, that needs to be discussed
further though, this is temporary implementation with the fix for routes
that were prefetched.

Fixes NEXT-402

<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation or adding/fixing Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md



## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2023-04-01 23:12:49 -07:00
JJ Kasper
8c7e4f9bc4
Fix fetchCache config and On-Demand Revalidate handling (#47803)
This ensures we properly honor the `export const fetchCache` config and
also ensures we properly bypass fetch-cache when an On-Demand
Revalidation is occurring.

The `export const dynamic` handling is not changed here as that was
behaving correctly and should not influence fetch cache handling only
whether a page is prerendered fully or treated as SSR.

Fixes: https://github.com/vercel/next.js/issues/47273
x-ref: [slack
thread](https://vercel.slack.com/archives/C042LHPJ1NX/p1679078572123979)
2023-04-01 21:15:13 -07:00
Jiachi Liu
5c6b8ac3f2
Fix flaky css test and remove unused tests deps (#47806)
* use `check` to wait for css change
* remove unused swr deps and update them to latest
* remove swr esm test in `app-dir/app/` since it's already covered in
`app-dir/app-external/`

---------
2023-04-01 16:58:32 -07:00
Jiachi Liu
2a5c558963
Skip favicon.js for metadata (#47790)
For backward compatibility, we only handle `favicon.ico` file to
generate `/favicon.ico` route and link tag. If you want to use other
extension such as `png`, use `icon(\d)?.[ext]`
2023-04-02 01:35:24 +02:00
JJ Kasper
fb98b7382f
Update metadata e2e test on deploy (#47776)
x-ref:
https://github.com/vercel/next.js/actions/runs/4579107074/jobs/8087256711
2023-03-31 20:17:32 -07:00
Shu Ding
0e5fb49600
Add test to ensure image generation works in the Node.js runtime (#47719)
Check the test case for more details.
2023-03-31 18:36:10 -07:00
JJ Kasper
7f0638869c
Fix skipMiddlewareUrlNormalize with i18n (#47773)
This ensures we don't normalize locales in the URL with the
skipMiddlewareUrlNormalize flag enabled so that casing redirects can be
applied correctly for locales.
2023-03-31 18:24:20 -07:00
JJ Kasper
53e4627ce5
Update app router filter handling (#47761)
This ensures we check if a path is `appRouter` during prefetching so
that we can trigger hard navigations quicker when routing from pages ->
app. An additional config is also exposed to allow configuring the
potential false positive rate for the client filter.

x-ref: [slack
thread](https://vercel.slack.com/archives/C017QMYC5FB/p1680225393243459)
2023-03-31 12:19:47 -07:00
Jiachi Liu
04bfb314e0
Support relative path for metadata alternates urls (#47743)
Allow to use relative paths which starting with dot (e.g. `./[paths]`) for urls under `metadata.alternates`.
This allow user to simplify setting `canonical` or other such like `languages` once in root layout with `metadataBase` and a simple relative path, then next.js will resolve it with current pathname of the page.

For example
```js
export const metadata = {
  metadataBase: new URL('https://mydomain.com'),
  alternates: {
    canonical: './'
  }
}
```
Then:
for page `/` it will generate `https://mydomain.com`;
for page `/about` it will generate `https://mydomain.com/about`

as your cononical url

Closes NEXT-897

### Minor changes

- always remove trailing slash for `URL.href`
2023-03-31 15:44:39 +00:00
Wyatt Johnson
e1a397d750
fix: correctly handle Set-Cookie headers (#47718)
## What

This fix serves to address issues where multiple `Set-Cookie` headers
were combined in some runtimes.

## Why

This is because `set-cookie` behaves differently than other headers in
some cases.

Eg. when iterating on a `Headers` instance, multiple set-cookie headers
are folded. To set them correctly, we need to split them. But it'd not
be enough to naively split on the first occurrence, because `,` is a
valid cookie value when for example it's used in `Expires` in a date
string.

So we use a method to correctly detect where to split the cookie.

This should fix all runtimes.

Note, the spec now has `Headers#getSetCookie` which should be preferred
if it's present. https://github.com/whatwg/fetch/pull/1346. We are using
the [`edge-runtime`](https://github.com/vercel/edge-runtime), so this
should be fixed upstream and then reused in Next.js in the future.

## How

Wherever we can, we reuse the `fromNodeHeaders` and `toNodeHeaders`
methods that have the correct implementation. This should be preferred
in the future in other parts of the codebase. We fixed some related TS
issues as well.

Fixes #46579, supersedes #40579
fix NEXT-735 ([link](https://linear.app/vercel/issue/NEXT-735))

---------

Co-authored-by: Balázs Orbán <info@balazsorban.com>
2023-03-31 16:35:47 +02:00
Shu Ding
a52ebf4089
Add tests for Suspensey CSS (#47708)
This PR adds a test to confirm that the component will be committed
after the stylesheet is loaded, by delaying the CSS request in
middleware and then check the active style in `useEffect` (technically
it should be `useLayoutEffect`). Since our current timeout for that is
set to 500ms, I also added a test with 1000ms delay to rule out false
negative cases.
2023-03-31 10:06:17 +02:00
Jiachi Liu
d71cbe9116
Vendor @vercel/og and expose ImageResponse (#47715)
- Reverts #47711 
- Disable image response for turbopack
2023-03-31 02:29:10 +00:00
Jiachi Liu
2d796ed594
Fix duplicated default metadata tags (#47690)
Adding default metadata before causes duplicated metadata tags when
adding server inserted html. Remove the ones in the not found boundary
Now we use same way to render metadata to render the default metadata in
error html

Fixes the issue introduced in #47404

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2023-03-30 17:17:52 -07:00
Jiachi Liu
6dbb6318a1
Provide default metadataBase for local and vercel deployment (#47568)
### What?

- Provide a default `metadataBase` 
- Always resolve urls that could be resolved as absolute with
`metadataBase`, e.g. tw/og urls, canonical urls
- Give a warning in dev mode if user doesn't provide one in dev
- Error if you don't have it but it's required in production

On production it will leverage `VERCEL_URL` if users expose it to the
deployment

### Why?

OG image urls are required to be absolute urls instead of relative urls.
For metadata image conventions we let users don't have to provide
`metadataBase` explicitly when they expect it should be the origin of
their next app.

### How?

Closes NEXT-887

---------
2023-03-30 16:27:24 -07:00
Jiachi Liu
35cf930572
Update MetadataRoute to namespace (#47674)
### What?

Followup for #47630 , use ts namespace to group MetadataRoute.

`MetadataRoute['xxx']` -> `MetadataRoute.xxx`

### Why?

namespace is convenient to write for these grouped types such as
`MetadataRoute.Robots`. And `MetadataRoute` itself is not actually a
type. So it can be conveniently typed by ts users.

### How?

Closes NEXT-912

---------
2023-03-30 15:27:44 -07:00
Jiachi Liu
0616f1b432
Add not found boundary and move head cache to app router (#47688)
### What?

- Add not found boundary to app router
- Move `head` cache back to app router

### Why?

We want the head to be rendered separately from body, previously to be
able to use `redirect()` and `notFound()` in `generateMetadata` we move
the head cache into layout-router to be wrapped by not found and
redirect boundaries. Since redirect boudary is already moved to
app-router, so we only need to add not found boundary and move head
cache to app router.

Notice: there's a limitation that we can't find the corresponding not
found of page if you throw notFound in generateMetadata, the root layout
+ root/default not found will be used to generate the 404 page

### How?

Closes NEXT-864
Fixes #46738

fix NEXT-888 ([link](https://linear.app/vercel/issue/NEXT-888))

---------
2023-03-30 14:08:37 -07:00
JJ Kasper
2ac022391c
Revert "Vendor @vercel/og and expose ImageResponse (#47657" (#47711)
Reverts vercel/next.js#47657
2023-03-30 12:24:02 -07:00
Jan Kaifer
80ebfad19d
Handle async require when importing ESM in instrumentation.ts (#47658)
Fixed issue where `require` will return a Promise if (and only if) there
is an ESM module imported in `instrumentation.ts`:
61cd219f15/packages/next/src/server/next-server.ts (L212)

Had to move stuff to async function from constructor, but luckily we
already have `prepare`.
2023-03-30 16:05:26 +00:00
Jiachi Liu
16badb40c1
test: disable the flaky test for parallel-routes-and-interception (#47694)
x-ref: https://github.com/vercel/next.js/actions/runs/4548265038/jobs/8019160929?pr=47630
2023-03-30 15:25:51 +00:00
Jiachi Liu
99cdb36663
Vendor @vercel/og and expose ImageResponse (#47657
### What?

This PR vendors @vercel/og and export `ImageResponse` from
`next/server`. When you render a opengraph image the below code snippets
will be legit:

```tsx
import { ImageResponse } from 'next/server'

export default function og() {
  return new ImageResponse(<div style={{ width: '100%', height: '100%' }}>hello</div>)
}
```

### Why?

To make development more easier, user can directly use `@vercel/og`
Image Response with nextjs instead of install it and use it. This makes
building metadata icons, og or twitter images more convenient.

### How?

Closes NEXT-899
2023-03-30 13:06:30 +02:00
Wyatt Johnson
aca83d2a09
Move App Route handler logic into bundle (#47633)
Previously the app route handler was included in the server bundle, and called into user code to execute the underlying handler logic. This PR serves to move the handler code into the bundle so that the Node.js environment more closely matches the Edge environment.

This also updates the Rust code for the new loader.
fix NEXT-712 ([link](https://linear.app/vercel/issue/NEXT-712))
2023-03-29 19:31:30 +00:00
Jiachi Liu
facea99f0e
Expose metadata types (#47630)
### What?

- Besides existing `Metadata` type, expose `ResolvingMetadata` and `ResolvedMetadata` to `'next'`.
- Group `Robots` / `Sitemap` / `Manifest` these dynamic data routes types as `MetadataRoute` type and expose to `'next'`

### Why?

Allow users to type the more API easily, and grouping them to avoid type conflicts (e.g. we have `Robots` in metadata interface field, `MetadataRoute.Robots` can avoid conflicts)

### How?

Closes NEXT-908
2023-03-29 11:16:47 +00:00
Shu Ding
54fce53dd9
Make sure the global not found route doesn't conflict with existing /not-found route (#47619)
In #47328 we made the root level `/not-found.js` a special entry, to
override the page 404 during builds. However, it's possible that the
user has a valid `/not-found/page.js` route that might conflict with
this special entry. This PR changes the entry to be `/_not-found` so it
will never conflict with existing valid entries.
2023-03-28 21:54:58 +02:00
JJ Kasper
4d0f5a0503
Revert "Move App Route handler logic into bundle" (#47614)
Reverts vercel/next.js#47582

This breaks turbopack support so we should address that before landing.
Potentially we can re-use the same loader for both which would eliminate
this issue.

x-ref:
https://github.com/vercel/next.js/actions/runs/4544370605/jobs/8010399819
x-ref:
https://github.com/vercel/next.js/actions/runs/4545240650/jobs/8012475072?pr=47611
fix NEXT-712 ([link](https://linear.app/vercel/issue/NEXT-712))
2023-03-28 10:12:03 -07:00
Wyatt Johnson
5dc31354b9
Move App Route handler logic into bundle (#47582)
Previously the app route handler was included in the server bundle, and
called into user code to execute the underlying handler logic. This PR
serves to move the handler code into the bundle so that the Node.js
environment more closely matches the Edge environment.
fix NEXT-712 ([link](https://linear.app/vercel/issue/NEXT-712))
2023-03-28 16:38:17 +02:00
Wyatt Johnson
bf52c25497
Underscore Handling Fixes (#47581)
Previously to this PR, if an absolute path contained an `_` it would
ignore all app files. If for example the Next.js app was in a folder
named `/some/_directory` then today:

```
/some/_directory/app/page.js <- should 200, currently 404
/some/_directory/app/route.js <- should 200, currently 404
/some/_directory/app/_internal/route.js <- should 404, currently 200 in development
```

This also enables the same `_` functionality for app routes in
development. After this PR, we get:


```
/some/_directory/app/page.js <- 200
/some/_directory/app/route.js <- 200
/some/_directory/app/_internal/route.js <- 404
```
2023-03-28 12:19:01 +02:00
Jan Kaifer
54a08ebe77
Fix instrumentation not being called on edge in some cases (#47495)
- Modified tests to catch issue with instrumentation not being invoked
for edge api calls
- Add tests for middleware
- Add instrumentation into middleware bundle

<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation or adding/fixing Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md



## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->
2023-03-27 20:54:43 +00:00
JJ Kasper
4a2df3c375
Fix fetch cache config and fetch revalidates (#47573)
This ensures we properly honor config and fetch based revalidate on the
same page in fetch cache.

Fixes:
https://github.com/vercel/next.js/actions/runs/4529647521/jobs/7978177827
2023-03-27 13:08:23 -07:00
Shu Ding
b28cd21ee5
Improve client boundary source type detection (#47532)Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Currently in a client boundary file, we only explicitly export
individual fields in ESM (`export foo`) when the source type is
`module`. However in most of the time SWC gives the `auto` source type.
This PR improves the type detection a bit so if it's `auto` and we do
see ESM exports collected, we assume it's ESM and re-export these
fields.

Fixes #41940, fix NEXT-796
([link](https://linear.app/vercel/issue/NEXT-796)).

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2023-03-27 19:16:23 +02:00
Jan Kaifer
1cea1c22bc
Remove unneeded waiting in otel tests (#47431)
- wip
- remove waiting for otel before tests
- remove useless timeout in test



fix NEXT-815 ([link](https://linear.app/vercel/issue/NEXT-815))
2023-03-27 10:50:06 +00:00
JJ Kasper
ac84542fda
Update some flakey test cases (#47556)
x-ref:
https://github.com/vercel/next.js/actions/runs/4529093785/jobs/7976512430
x-ref:
https://github.com/vercel/next.js/actions/runs/4529093785/jobs/7976517246
x-ref:
https://github.com/vercel/next.js/actions/runs/4528686011/jobs/7976058968
2023-03-26 23:41:15 -07:00
JJ Kasper
d34ba2b0ff
Update failing i18n e2e deploy test (#47555)
Temporarily skips a failing test case on e2e deploy mode for i18n-hybrid
test suite.

x-ref:
https://github.com/vercel/next.js/actions/runs/4520873270/jobs/7962318031
2023-03-26 22:40:32 -07:00
Janicklas Ralph
83c2a3f09c
Integrating capsize latest (#47428)
Integrating capsize latest

<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation or adding/fixing Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md



## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2023-03-26 20:29:28 -07:00
Ngô Đức Anh
c748b16555
Feat(next-types-plugin): added support for Route Handlers (#47185)
Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation or adding/fixing Examples

- The "examples guidelines" are followed from our contributing doc https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See: https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. (A discussion must be opened, see https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added (https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md



## For Maintainers

- Minimal description (aim for explaining to someone not on the team to understand the PR)
- When linking to a Slack thread, you might want to share details of the conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic behind a change

### What?

This PR adds next-types-plugin's support for Route Handlers.

### Why?

Since `route.js` is somewhat like `page.js` and `layout.js`, I find it to be necessary that we also enable TS checks for these files as well.

### How?

Just changing the `createTypeGuardFile` function a bit and adding a few new tests, yeah.
2023-03-26 23:34:54 +00:00
Tim Neutkens
a058b8569e
Remove head.js (#47507)
### What?

Removes `head.js` file convention in favor of built-in SEO support through `metadata`: https://beta.nextjs.org/docs/guides/seo

### Why?

The `head.js` convention was superseded by the built-in SEO support which is designed specifically for Server Components.

### How?

Removed the `head.js` handling in app-loader and the tests for it.

fix NEXT-812 ([link](https://linear.app/vercel/issue/NEXT-812))
2023-03-25 01:40:30 +00:00
JJ Kasper
4b4dd8b33a
Fix other case for useSelectedLayoutSegments (#47511)
Follow-up to https://github.com/vercel/next.js/pull/47492 this ensures
we properly check for `__PAGE_` elsewhere and re-enables some other
tests now that it's passing.
2023-03-24 16:06:17 -07:00
JJ Kasper
318642a1d9
Update flakey app dev tests (#47504)
x-ref:
https://github.com/vercel/next.js/actions/runs/4513582756/jobs/7948722605
x-ref:
https://github.com/vercel/next.js/actions/runs/4513582756/jobs/7948722818
x-ref:
https://github.com/vercel/next.js/actions/runs/4513366262/jobs/7949059763
2023-03-24 15:44:44 -07:00
Jan Kaifer
adf8c7f6e7
Add http.route into root otel span (#47392)
Co-authored-by: Steven <steven@ceriously.com>
2023-03-24 17:52:28 +00:00
Jimmy Lai
de8e4e999e
parallel routes: implement default route + fix bugs on navigation (#47436)
### What?

This PR is another part of making parallel routes viable!

- enables some of the tests, partially only in dev (build fails because
the intersection routes are not implemented)
- introduces a new type of special file: a `default` file that can be
added to any segment, next to `page` etc, that will act as the
default/placeholder when a layout does not match
- this also fixes bugs when navigating within parallel routes

### Why?

### How?

<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation or adding/fixing Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md



## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

fix NEXT-748 ([link](https://linear.app/vercel/issue/NEXT-748))

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2023-03-24 18:01:41 +01:00
JJ Kasper
ba9b94d5fb
Fix failing og api e2e test (#47500)
x-ref: https://github.com/vercel/next.js/actions/runs/4508438652/jobs/7937409460
2023-03-24 15:59:45 +00:00
Tim Neutkens
68abad58ed
Fix useSelectedLayoutSegments including __PAGE__ (#47492)
### What?

Excludes `__PAGE__` elements from `useSelectedLayoutSegment` as it's not
a public api.
This ensures the exclude still applies when there are searchParams part
of the key.

<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation or adding/fixing Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md



## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->
2023-03-24 16:13:22 +01:00
Wyatt Johnson
b8d785d286
Locale fixes for App Directory (#47429)
Fixes issue with app directory that caused problems with `i18n` was
enabled. Previously, when you accessed a URL like `/blog/first-issue`,
you would expect it to hit the app route at `/app/blog/[slug]/page.tsx`,
but instead it internally attempted to access
`/app/{defaultLocale}/blog/[slug]/page.tsx` (where `{defaultLocale}` is
set in `next.config.js` via `i18n.defaultLocale`). This is because while
the path did not assume the locale, the domain/default was enough to
suggest it, causing the mismatch.

This adds a new internal parameter for tracking this _default_
assignment so it can be handled by the matcher correctly.

Fixes #46814
Fixes #46841
fix NEXT-777 ([link](https://linear.app/vercel/issue/NEXT-777))
fix NEXT-834 ([link](https://linear.app/vercel/issue/NEXT-834))

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2023-03-24 13:06:27 +01:00
Shu Ding
9fff7e321c
Finalize HOC support with server entries and add encodeReply & decodeReply (#47438)
Revert some code in #47379 and finalize HOC support. We should require
the HOC to return a "use server" function, so there's no need to compile
the function call specially now.

To make that wrapping logic work, we need to allow passing a server
reference to another server reference. This usually happens in the
function closure in the HOC case, but ideally it's also allowed to
directly pass it as an argument. This requires adding React server DOM's
`encodeReply` and `decodeReply` and other corresponding changes,
including adding `busboy` (can probably be vendored?) as we need to
parse the multipart body now.

fix NEXT-808 ([link](https://linear.app/vercel/issue/NEXT-808))
([link](https://linear.app/vercel/issue/NEXT-808))
2023-03-24 13:01:10 +01:00
Tim Neutkens
b9be75df03
Ignore folders prefixed by underscore (_) in App Router (#47439)
### What?

In `app` all directories starting with `_` are now considered private
and won't be routed.

E.g. `app/_components/page.js` -> does not route

If you want to have a route starting with an underscore like
`/_settings` you can use `%5F` which is the url encode version of `_`:
`app/%5Fsettings/page.js`-> does route

### Why?

Ensures that you can create directories that will never conflict with
Next.js internal naming. E.g. when additional conventions are added for
file names.

### How?

It's a bit more involved than you might expected:
- build
- While resolving entries by traversing `app` parts with `_` are ignored
	- While normalizing entires `%5F` is replaced with `_`
- I've changed one case that was relying on the entry name for resolving
to use the full path to the file instead.
- dev
- Ignored paths with underscore from being generated as part of the
initial scan of the filesystem
- Updated development and production the route matcher to replace `%5F`
with `_` so that it matches the right path.

fix NEXT-798 ([link](https://linear.app/vercel/issue/NEXT-798))
([link](https://linear.app/vercel/issue/NEXT-798))

<!-- 
## For Contributors

### Improving Documentation or adding/fixing Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md



## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2023-03-24 12:53:11 +01:00
Islam Shehata
b39a03f4e3
add useReportWebVitals that makes use of web-vitals package (#47319)
### What?
introduce a new hook `useReportWebVitals` that would register a function to handle web-vitals metrics. 

### Why?
next.js users who use [Axiom](https://axiom.co) has been [asking](https://github.com/axiomhq/next-axiom/issues/109) for this feature for nextjs 13, as it was working for nextjs 12.
2023-03-24 10:13:50 +00:00
JJ Kasper
9f7318a8f9
Update failing i18n e2e deploy test (#47462)
This tests is currently not expected to work in the deploy mode so this
temporarily skips it for now

x-ref:
https://github.com/vercel/next.js/actions/runs/4504603973/jobs/7929514077
2023-03-23 15:53:14 -07:00
JJ Kasper
a01ea2335d
Update failing e2e deploy test (#47453)
Temporarily skips failing test in deploy mode

x-ref:
https://github.com/vercel/next.js/actions/runs/4474556375/jobs/7863295708
x-ref:
https://github.com/vercel/next.js/actions/runs/4495220910/jobs/7909314612
2023-03-23 12:29:51 -07:00
Jiachi Liu
d187c36503
Add content hash for dynamic og image routes (#47440)
* Add `contenthash` as query (`?<hash>`) for dynamic image and icon
routes as well.
* Merge the metadata image info extration into 1 single loader, dynamic
and static image route will all pass through
`next-metadata-image-loader` to extract the image info such as size,
content type, etc.
* Applying same cache header from `@vercel/og`, for development we use
"no cache" header, for production, we use "long cache" header

Closes NEXT-882
2023-03-23 17:38:42 +01:00
Shu Ding
ae71ff6eb7
Error during dev if returning Response in pages API routes in Node.js runtime (#47442)
This avoids the case that one can accidentally return a `Response` object in the Node.js runtime in `pages/api/`, that causes the request to hang forever.
2023-03-23 15:54:23 +00:00
Shu Ding
38cddd902b
Add test for force-dynamic and catch-all routes (#47418
fix NEXT-640 ([link](https://linear.app/vercel/issue/NEXT-640))
([link](https://linear.app/vercel/issue/NEXT-640)). Fix #45603.

https://github.com/vercel/next.js/issues/45603#issuecomment-1480195089
2023-03-23 15:53:51 +01:00
Jiachi Liu
b2ca7a3bf8
Fix twitter metadata info merging (#47433)
* Fix rest of twitter metadata when merging with static metadata images,
should include title/description/etc. properties
* rename `opengraph` to `openGraph` property

Related to NEXT-266
Follow up for #47425 

Fixing the twitter metadata are missing found while testing
<img width="583" alt="image"
src="https://user-images.githubusercontent.com/4800338/227190635-60867873-d3b5-4bdc-ab5a-24abdded8faa.png">
2023-03-23 13:04:26 +01:00
Jimmy Lai
0416bd559d v13.2.5-canary.14 2023-03-23 10:15:46 +01:00
Jiachi Liu
9150620993
Support dynamic routes for social images and icons (#47425)
Redo #47372 , basically revert #47416 and upgrade og (https://github.com/vercel/og/pull/60)

Closes NEXT-264
Closes NEXT-266
2023-03-23 00:12:22 +00:00
JJ Kasper
76f8e41113
Update failing e2e checks (#47423)
x-ref:
https://github.com/vercel/next.js/actions/runs/4484749964/jobs/7885622738
x-ref:
https://github.com/vercel/next.js/actions/runs/4484749964/jobs/7885622985
x-ref:
https://github.com/vercel/next.js/actions/runs/4484749964/jobs/7885704581
2023-03-22 15:32:06 -07:00
Shu Ding
783d7d589c
Extend not-found.js to catch all unmatched routes (#47328)
This PR continues the work of #45867, that treats the root-level `not-found.js` file inside app dir as the global 404 page, if it exists. Previously, it fallbacks to the /404 route inside pages (and the default one if `404.js` isn't specified).

In the implementation, we include `/not-found` in `appPaths` during the build, and treat it as the special `/404` path during pre-rendering. In the renderer, if the `/404` pathname is being handled, we always render the not found boundary.

And finally inside the server, we check if `/not-found` exists before picking up the `/404` component.

A deployed example: https://not-found-shuding1.vercel.app/balasdkjfaklsdf

fix NEXT-463 ([link](https://linear.app/vercel/issue/NEXT-463))
2023-03-22 22:16:50 +00:00
Jiachi Liu
de92781145
Add default meta tags to error page (#47404)
Default tags of `charset` and `viewport` should also be rendered in app
router error pages like not found pages.

Closes NEXT-869

This PR:
* Extract not found boundary to single component
* Add the default tags to `NotFoundErrorBoundary` rendering
* Fix duplicated `noindex` tag for streaming error rendering
2023-03-22 22:44:45 +01:00
Steven
7060b8c9ef
Revert "Support dynamic routes for social images and icons" (#47416
Reverts vercel/next.js#47372

```
Error occurred prerendering page "/apple-icon". Read more: https://nextjs.org/docs/messages/prerender-error
Error: The `ImageResponse` API is not supported in this runtime, use the `unstable_createNodejsStream` API instead or switch to the Vercel Edge Runtime.
    at new ImageResponse (/tmp/next-install-db63e2a2f25e9feda48affa69456fcbdde8d89bf94645e42abd2aa522224f432/.next/server/chunks/558.js:26416:19)
    at appleIcon (/tmp/next-install-db63e2a2f25e9feda48affa69456fcbdde8d89bf94645e42abd2aa522224f432/.next/server/app/apple-icon/route.js:127:12)
```


https://github.com/vercel/next.js/actions/runs/4490842502/jobs/7899302486#step:6:305
2023-03-22 20:24:09 +01:00
Jiachi Liu
bbd79ac997
Support dynamic routes for social images and icons (#47372)
Allow image responses returning from dynamic image routes for og/twitter
images, and icon/apple-icon images. This PR supports the basic
functionalities for nodejs runtime of image routes. `@vercel/og` is able
to be leveraged for generating dynamic image responses.

Close NEXT-264
Close NEXT-266

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2023-03-22 15:19:50 +01:00
Shu Ding
e6a3bab489
Support HOC cases in server entries (#47379)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2023-03-22 15:15:08 +01:00
Jan Kaifer
c04ca8df84
Add more spans into OTEL instrumentation to wrap all user defined functions (#47368)
- Move span wrapping rendering closer to the user code and don't add
span when we have cache-hit
- Add `getStaticProps` span
- Add spans around API handlers (pages and app)
- Add `generateMetadata` span
- Clarify naming that we use `page` for entrypoints like
`/path/[param]/page` or `/path/[param]/layout`. And `route` for
`/path/[param]`

fix NEXT-857 ([link](https://linear.app/vercel/issue/NEXT-857))
2023-03-22 12:01:33 +00:00
Tim Neutkens
f029023a3c
Add useParams() (#47373)
### What?

Adds `useParams` to read the canonical parameters.

```tsx
'use client'

import { useParams } from 'next/navigation'

export default function Page() {
  const { id } = useParams()
  return (
    <div>
      <div id="param-id">{id}</div>
    </div>
  )
}
```

### Why?

Allows for accessing segment parameters for the entire page.

### How?

It uses a similar resolving of `useSelectedLayoutSegments` which resolve `children` and if `children` is not available the first available parallel route instead.

Closes NEXT-99
2023-03-22 09:26:19 +00:00
Tim Neutkens
48948022c7
Catch redirect() in root layout (#47345)
### What?

Adds the error boundary used to catch `redirect()` above the root
layout.

### Why?

Currently calling `redirect()` in the root layout causes `NEXT_REDIRECT`
to bubble up to the error boundary because we didn't have a
redirect-boundary above the place where the root layout is rendered
client-side.

### How?

- Moved redirect-boundary into a separate file
- Added redirect-boundary around the `cache.subTreeData` in app-router
(around the root layout)

fix NEXT-315 ([link](https://linear.app/vercel/issue/NEXT-315))
Fixes #42556


I've verified the reproduction shown in #42556 has been fixed earlier,
there was another report about calling `redirect()` in the root layout
and that's what this PR fixes.

Since that issue has many comments here's some additional context:
- `redirect()` can only be called during React component rendering.
- This means you can't run `redirect()` in `onClick` or `useEffect()`
handlers.
- Calling `redirect()` in a server component or during prerendering of
client components it will add the right meta tag to trigger a redirect
	- `<meta httpEquiv="refresh" content={`0;url=${redirectUrl}`}>`
- Because of streaming rendering by the time your code runs the browser
will have already received the start of the stream and headers will have
been sent, as such you can't modify the headers, hence why the meta tag
is used instead of `location`.
- Calling `redirect()` in client components is supported while
rendering, e.g. if you have a condition:
	 ```tsx
	'use client'
    import { useState } from 'react'
    import { redirect } from 'next/navigation'
	export function ClientComponent() {
		const [clicked, setClicked] = useState()
		if(clicked) {
			redirect('/another-page')
		}

		return <>
			<button onClick={() => setClicked(true)}>Click to redirect</button>
		</>
	}
	``` 


<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation or adding/fixing Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md



## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2023-03-22 09:34:50 +01:00
Wyatt Johnson
c14c83a299
Marks app paths in dev as supporting dynamic html (#46848)
This marks all pages in development as supporting dynamic HTML. Detection for runtime violations of dynamic generation is completed during the production build.

Fixes #46356
fix NEXT-644 ([link](https://linear.app/vercel/issue/NEXT-644))

Co-authored-by: Tim Neutkens <6324199+timneutkens@users.noreply.github.com>
Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2023-03-21 20:55:04 +00:00
Jiachi Liu
75c6b10009
Fix: only apply metadata dynamic image routes convention for app dir (#47367)
We shouldn't detect icon/og/etc. metadata image convention as image dynamic routes under `pages/` dir, they should be only apply in `app/` dir. This PR changed the normalization rule that we only apply them when page is from `app/`. So when you're using `icon.js` under `pages/` it won't get effected.
2023-03-21 18:25:20 +00:00
JJ Kasper
86bf30a448
Fix POST fetch request cache heuristic in POST route handler (#47333)
This ensures we properly bail from caching POST requests when a route is
dynamic e.g. a POST route handler
2023-03-21 10:24:21 -07:00
Jiachi Liu
93152db9b1
Fix bad route path for custom metadata routes (#47286)
We introduced static route `robots.txt` and dynamic route `robots.js` for metadata, it should still allow users to create their own customized version. This issue is caused by a route conflicts. Only append `/route` to page path when there's not ending with `/route`


Fixes #47198
Closes NEXT-850
2023-03-21 15:55:32 +00:00
JJ Kasper
4575faa649
Update failing e2e deploy test (#47325)
The custom handler version of this test isn't expected to handle this
accurately.

x-ref:
https://github.com/vercel/next.js/actions/runs/4472912191/jobs/7859898279
2023-03-20 14:58:39 -07:00
Wyatt Johnson
0be4db325e
Warn about default exports with App Routes (#47263)
When a user exports a default function from a `route.ts` file, they may
think that this would be handled in the same way that our `pages/api/`
routes handled it. App Routes require an exported function for each HTTP
method instead.

This adds warnings to the development console when a user provides a
default export (or no HTTP method at all).

Future ideas:

- Error during production build when these conditions are met
fix #46375
fix NEXT-660 ([link](https://linear.app/vercel/issue/NEXT-660))

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2023-03-20 14:52:41 -07:00
Tim Neutkens
8a4e8059ed
Add searchParams to leaf cache key (#47312)
### What?

Makes searchParams part of the cache key for dynamic rendering
responses.

### Why?

Current the cache key only includes the pathname and not the
searchParams. This causes issues in a few cases:
- Navigation to `/dashboard` then clicking a link to
`/dashboard?sort=asc` works, but then when navigating back the cache
node for `/dashboard?sort=asc` is used instead of the content for
`/dashboard`.
- Navigation between different searchParams always had to be a hard
navigation as reusing a cache node would result in the wrong result.

### How?

Changed the leaf node's name from `''` to `'__PAGE__'` so that it can be
distinguished. Then used that `__PAGE__` marker to include the
searchParams into the cache key for that leaf node in all places it's
used.

Ideally the `__PAGE__` key becomes something that can't be addressed in
the pathname, since it still has to be serializable I'm thinking a
number would be best.

Given that the server just provides the cache key and the client only
reasons about rendering the tree the current approach of stringifying
the searchParams and making that part of the cache key could be replaced
with a hash of the stringified result instead.

fix NEXT-685 ([link](https://linear.app/vercel/issue/NEXT-685))
Fixes #45026
Fixes NEXT-688
Fixes #46503
2023-03-20 19:57:29 +01:00
Jan Kaifer
46201e1644
Improve OTEL spans naming (#47209)
Adds bunch of default attributes and span names as discussed in https://github.com/vercel/next.js/pull/47066

Also discovered a few issues with our test setup.
It's actually quite handy to use jest snapshots for this, thanks for the tip @feedthejim 

Currently we have following spans:
- root span with name `GET /app/rsc-fetch` (both API calls and page requests)
  - `SERVER` span	
  - attributes:
    -  `"http.method": "GET"`
    -  `"http.status_code": 200`
    -  `"http.target": "/app/rsc-fetch"`
    -  `"next.span_name": "GET /app/rsc-fetch"`
    -  `"next.span_type": "BaseServer.handleRequest"`
- fetch span `fetch GET https://vercel.com/`
  - `CLIENT` span	
  - attributes:
    -  `"http.method": "GET"`
    -  `"http.url": "https://vercel.com/"`
    -  `"net.peer.name": "vercel.com"`
    -  `"next.span_name": "fetch GET https://vercel.com/"`
    -  `"next.span_type": "AppRender.fetch"`

- rendering of page `rendering /app/rsc-fetch`
  - attributes:
    -  `"next.pathname": "/app/rsc-fetch"`
    -  `"next.span_name": "rendering /app/rsc-fetch"`
    -  `"next.span_type": "BaseServer.renderToResponse"`
    
- finding the right page component `resolving route /app/rsc-fetch/page`
  - attributes
    -  `"next.route": "/app/rsc-fetch/page"`
    -  `"next.span_name": "resolving route /app/rsc-fetch/page"`
    -  `"next.span_type": "NextNodeServer.findPageComponents"`
    
- getServerSideProps `getServerSideProps /pages/getServerSideProps`
  - attributes
    -  `"next.span_name": "getServerSideProps /pages/getServerSideProps"`
    -  `"next.span_type": "Render.getServerSideProps"`
    

fix NEXT-829 ([link](https://linear.app/vercel/issue/NEXT-829))
2023-03-20 17:17:23 +00:00
Gal Schlezinger
6b09bc86a8
[edge] limit the api surface of util (#47292)
This makes sure that what works locally will work in production.
2023-03-20 10:29:00 +01:00
JJ Kasper
ad223c816c
Ensure config and fetch revalidate are honored (#47255)
This ensures revalidate can be fetch specific instead of cache key
specific and adds a test case to ensure config based revalidate isn't
overridden by fetch based revalidate.
2023-03-17 14:00:07 -07:00
Jiachi Liu
e601a3b532
Support manifest.json static and dynamic route (#47240)
* Add `manifest.webmanifest` and `manifest.(j|t)xs?` support for
manifest.json route
* Add `Manifest` type for it for autocomplete purpose.

Remove the exports for `SitemapFile` and `RobotsFile` globally, will
discuss how to re-export them with better naming later

Small fix for `Robots` typing, should allow `string | string[]` for user
agent of single Robots

Closes NEXT-839

---------
2023-03-17 12:11:34 -07:00
Wyatt Johnson
e29bd49d87
i18n Improvements (#47174)
This serves to correct a specific issue related to multiple locales being specified in the pathname as well as some general i18n improvements.

- Multiple locales are now parsed correctly (only taking the first locale, treating the rest of the string as the pathname)
- `LocaleRouteNormalizer` has been split into `I18NProvider` and `LocaleRouteNormalizer` (tests added)
- Adjusted the `I18NProvider.analyze` method (previously `LocaleRouteNormalizer.match`) to require the `defaultLocale: string | undefined` to ensure consistent behaviour
- Added more comments around i18n
2023-03-17 18:48:09 +00:00
Shu Ding
8b44085b70
Fix CSS not being bundled in app dir (#45787)
Currently all import CSS resources, including CSS modules, are imported lazily. This means that they can't be chunked as by definition of "lazy" they can be loaded separately.

This PR changes it to always use "eager" so if they're in the same entry, these CSS resources can be chunked together and reduce the total amount of requests. However the downside will be tree shaking, as not all modules in a chunk are used by one entry. Two entries can only share a part of it.

Since CSS modules won't have side effects this should be a good trade off.

## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] [e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)


Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2023-03-17 17:38:19 +00:00
Shu Ding
51b1fe3d2f
Emit late streaming meta tags (#47207)
Currently if `notFound()` or `redirect()` is called when the shell was already sent out, we can no longer change the status code and head tags. In that case we inject these specific meta tags into the HTML stream so specific agents can read them.

fix NEXT-220 ([link](https://linear.app/vercel/issue/NEXT-220))
2023-03-17 14:37:00 +00:00
Jiachi Liu
694e7f9e80
Generate metadata images generation with app routes (#47225)
Generated metadata icons through api routes instead of using webpack
emitting file. Each metadata image file will go through
`next-metadata-image-loader` to get the image basic info, and then it
will go through `next-metadata-route-loader` to be converted as a
routes.

Related to NEXT-264
Closes NEXT-810
2023-03-17 13:41:56 +01:00
Gal Schlezinger
524bcd563b
[edge] support Node.js core modules in edge runtime (#47191)
This PR enables Node.js core modules in edge runtime by leaving a
`require` statement in the output source as externals

- [x] buffer
- [ ] async_hooks
- [ ] util 
- [ ] assert
- [ ] events
2023-03-17 13:29:31 +01:00
Shu Ding
922b5de06f
Support passing both closure arguments and parameters (#47212)
When calling the server (via `callServer`), we concat all closure values
(`$$bound`) and arguments of the function call into one array on the
client. Hence on the server, we will have to compile the function
differently to support that.

With this change, the compiled function will have a `$$with_bound` flag
to indicate that if it accepts closure values. If so, the only argument
passed will be an array like `[...bound_values, ...fn_args]`, and we
compile the function parameters to `(closure, arg1 = closure[N], arg2 =
closure[N + 1], ...)` where `N` is the number of the closure
identifiers. This way we can still fill these arguments by only pass an
"bound + args" array. If it doesn't accept closure values, it will be
directly called with `...fn_args` so no compilation change needed.

The reason that we use `arg1 = closure[N]` is that this can support
complex patterns in parameters such as `f(closure, {a} = closure[1], [b]
= closure[2])`.

fix NEXT-487 ([link](https://linear.app/vercel/issue/NEXT-487))
2023-03-16 19:11:13 -07:00
JJ Kasper
c7534092c7
Fix failing CI checks (#47223)
x-ref:
https://github.com/vercel/next.js/actions/runs/4441543036/jobs/7796929887
x-ref:
https://github.com/vercel/next.js/actions/runs/4441543036/jobs/7796930146
2023-03-16 18:59:52 -07:00
Shu Ding
45fe26f596
Fix missing option in createFromFetch (#47216)
This PR makes sure that `callServer` is specified in all Flight response creation calls. Added a test to cover HMR.

https://vercel.slack.com/archives/C03KAR5DCKC/p1678997184339409
2023-03-17 00:46:21 +00:00
Tim Neutkens
cc0da4bd29
Opt-in to dynamic rendering when reading searchParams (#46205)
Ensures that using `searchParams` opts into dynamic rendering.

Fixes #43077 
fix NEXT-601 ([link](https://linear.app/vercel/issue/NEXT-601))

<!--
Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:
-->

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the
feature request has been accepted for implementation before opening a
PR.
- [ ] Related issues linked using `fixes #number`
- [ ]
[e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
2023-03-16 21:46:35 +01:00
Shu Uesugi
723626cf48
Handle defaultLocale on client router filter (#47180)
x-ref: [slack
thread](https://vercel.slack.com/archives/C03S8ED1DKM/p1678838567947919)

Follow-up to https://github.com/vercel/next.js/pull/46317. The issue is
that, if:

- `experimental.clientRouterFilter` is enabled
- `i18n` is enabled with `defaultLocale` set
- Next.js router navigates to a path that (1) is the same as
`defaultLocale` and (2) will be redirected,

then:

- **Expected:** Should hard-navigate to this path without any locale
prefix (and then redirect occurs)
- **Actual:** Hard-navigates to this path with `defaultLocale` prefix,
even though it's not needed (and then redirect occurrs)

### Solution

This PR fixes the above issue by adding `defaultLocale` to `addLocale`
which is passed to `handleHardNavigation`. [`addLocale` skips adding the
locale if `locale` is equal to
`defaultLocale`](02125cf3b1/packages/next/src/shared/lib/router/utils/add-locale.ts (L17)).

### Fixing a bug

- [x] Related issues linked using `fixes #number`
- [x] Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2023-03-16 11:58:02 -07:00
Jan Kaifer
53f29cd633
Add OTEL tests (#47149) 2023-03-16 16:35:07 +00:00
Shu Ding
4c3f59f88d
Implement server entry creation in client layer (#47127
In short, this PR adds a 3rd layer to the server compiler. This extra
layer is for marking the modules when re-entering the server layer from
a client component. It is almost identical to the existing server layer
and it should have all the same bundling and runtime behaviors, but it's
still special because it's not allowed to enter the client layer again
from there.

Because of that, we create the extra entry for that new layer when the
client layer compilation finishes in the `finishModules` phase. The new
entry is handled normally as it's in the server layer. But the original
module in the client layer will be compiled specially as special no-op
exports, and will then be connected via the `callServer` wrapper.

fix NEXT-809 ([link](https://linear.app/vercel/issue/NEXT-809)).
2023-03-15 23:58:18 +01:00
Tim Neutkens
e6bca73d87
Add support for scrolling to hash fragment (#46995)
Adds support for scrolling based on the [hash
fragment](https://en.wikipedia.org/wiki/URI_fragment) in client-side
navigations for the App Router, mirroring browser behavior.

- `#main-content` → scrolls to `id="main-content"` or
`name="main-content"` property
- `#top` → scrolls to the top of the page, this is a special case in
browsers.
- no hash → default scroll behavior, layout that changed

Fixes NEXT-658

<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation or adding/fixing Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md



## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

fixes #44295

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2023-03-14 13:17:10 +01:00
Talha Zekeriya Durmuş
16131e2d49
Fix #46621 - include status code in cache (#47096)
Fixes #46621

As explained here https://github.com/vercel/next.js/issues/46621,

> Using fetch to retrieve data inside a page on server side, the
response status code is incorrect when simply loading/reloading the
page. It looks like nextjs is caching the response without taking into
account the status code.

In following code we do not add status code information to the cache. 

https://github.com/vercel/next.js/blob/canary/packages/next/src/server/lib/patch-fetch.ts#L189-L206

However we are accessing this status code in 

https://github.com/vercel/next.js/blob/canary/packages/next/src/server/lib/patch-fetch.ts#L247-L250

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2023-03-13 21:37:22 -07:00
Shu Ding
b4be6eb290
Continue page rendering after handling server requests (#47089)
This moves the position of action handling so it can continue page
rendering afterwards. And a `asNotFound` option is added to
`LayoutRouter` to indicate the router to opt into the root not-found
boundary, so not found pages can be programmatically rendered instead of
relying on route mismatching (this is also needed by NEXT-463 later).

Fixes NEXT-467.
2023-03-13 21:07:44 -07:00
Jiachi Liu
bfd6c3ea2e
Dynamic routes for toplevel robots and sitemap (#47091)
Support top-level `robots.[ext]` and `sitemap.[ext]` with dynamic api
routes

* Use isAppRoute to determine api routes and metadata routes as metadata
routes are normalized as `<metadata>/route`
* Normalize path to auto append extension to pathname for sitemap.js and
robots.js
* Add typings `SitemapFile` and `RobotsFile`
* move the normalize logic together, reuse the `absolutePathToPage`.
Changes less when touching both dev-server/hot-reloader and next-server,
use the same utils to handle paths

Closes NEXT-262

---------
2023-03-13 18:04:31 -07:00
Hannes Bornö
cb729c1087
Remove experimental fontLoaders option from next.config.js (#46886)
Currently there's an experimental option in `next.config.js` that lets you define default subset(s) to preload for all your fonts. [docs](https://nextjs.org/docs/basic-features/font-optimization#specifying-a-subset)

Over time we haven't seen much use of this option, and we are defining the subsets in the font function call in all our examples/docs. Imo it would be fine to drop this option.

This PR removes that experimental option. If you happen to use it you'll get a build error with [a link](f67af163cd/errors/google-fonts-missing-subsets.md).

Next step (breaking change for next major) would probably be to remove the preload and subsets properties from `next/font/google` calls, and just have something like [`preloadSubsets´](https://vercel.slack.com/archives/C8EAN8A94/p1674868993169559?thread_ts=1674707555.461809&cid=C8EAN8A94) that is required.
2023-03-13 21:34:43 +00:00
Shu Ding
9b40be8e44
Implement route announcer for app dir (#47018)
This PR implements the route announcer for app directory. It almost uses
the same logic as the route announcer inside pages, with one notable
difference that the inner content node is now inside a shadow root. This
makes sure that it does as little impact as possible, to the
application. This is important as we no longer have the `__next`
wrapper.

Another thing worth mentioning is that the announced title is a global
singleton of the website. It shouldn't be affected by the concept of
layouts, but should be triggered when the router state (not just URL)
changes.

Closes NEXT-208.

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2023-03-13 13:09:22 -07:00
JJ Kasper
76f7645ce6
Update app route handler proxy handling (#47088)
This ensures our Proxy wrapping request fields works properly in the
edge-runtime by explicitly binding to the correct request instance.

x-ref: [slack
thread](https://vercel.slack.com/archives/C03UR7US95F/p1678730563467089?thread_ts=1678662292.695769&cid=C03UR7US95F)
2023-03-13 11:34:22 -07:00
Shu Ding
baa22255da
Initial support of redirection in server handlers (#46944
This is an initial implementation of POST-driven redirection handling:
https://vercel.slack.com/archives/C035J346QQL/p1678321389089839. Highly
experimental.

Fixes NEXT-803, fixes NEXT-804.
2023-03-13 14:20:27 +01:00
JJ Kasper
acb174455f
Fix generateStaticParams check in app dir (#47051)
This ensures our `params` checking works properly with `app` dir. 

x-ref: [slack thread](https://vercel.slack.com/archives/C03KAR5DCKC/p1678659475821299)
2023-03-13 00:05:35 +00:00
Jiachi Liu
fdfd9beb5f
Add /route subpath to metadata static routes (#47030)
Set the output bundle file path to `/<metadata route>/route.js` to align with other custom app routes, in order to make it easier being handled by app routes in both nextjs and vercel
2023-03-11 19:22:01 +00:00
Jiachi Liu
fd6b93d46e
Generate fixed route path for favicon.ico (#46997)
Generate `/favicon.ico` route when favicon.ico is placed into `app/`.

Still collect favicon metadata image information through
metadata-image-loader but don't emit the file to static dist anymore.
Also collect favicon through metadata routes, and render it as static
routes. Also remove the `hash` we generated before, not needed anymore.

Change metadata static routes rendering process: collect static metadata
assets, read the buffer of the file data and return it in the response.

Closes NEXT-791
2023-03-10 17:12:44 +01:00
Shu Ding
10f2268f4e
Add Zod and router state validation (#46962)
This PR adds Zod to the precompiled libraries, and use it to create schemas for the router state tree for validation. In other planned features/changes, Zod will also be used to do run-time data validation.

Fixes NEXT-135.
2023-03-10 13:37:45 +00:00
Jiachi Liu
36ca1598d5
Support static file robots.txt and sitemap.xml as metadata route (#46963)
Support top level static `robots.txt` and `sitemap.xml` as metadata
route in app directory. When those files are placed in top root
directory

Refactored a bit the page files matching logic, to reuse it between dev
server and build

Closes NEXT-267
2023-03-09 11:10:18 -08:00
Hannes Bornö
02eb34db01
Use https_proxy environment variable in next/font/google (#46822)
When fetching CSS or font files from Google Fonts, it won't work if
you're required to use a proxy. This change makes it look for the
`http(s)_proxy` environment variable, and if it's defined it creates a
fetch agent using
[https-proxy-agent](https://github.com/TooTallNate/node-https-proxy-agent).

Also fixes fetch errors not being properly logged.

Fixes #45034
Closes NEXT-690

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the
feature request has been accepted for implementation before opening a
PR.
- [ ] Related issues linked using `fixes #number`
- [ ]
[e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
2023-03-08 12:23:32 -08:00
Jiachi Liu
292f65f6d3
Fix unexpected hoist meta tags by react in app dir (#46917)
### Bug Fix

Update vendor react to fix the unexpected hoist tags issue

x-ref: https://github.com/facebook/react/pull/26256

* Fixes #42648
* Closes NEXT-655
* tests added
2023-03-08 11:34:51 +00:00
JJ Kasper
bfc3849b1f
Update generateStaticParams handling with fetch cache (#46906)
This ensures we leverage the fetch cache when calling
`generateStaticParams` and also ensures paths with
`generateStaticParams` without `dynamicParams = false` don't error when
only partial params are provided.

x-ref: [slack
thread](https://vercel.slack.com/archives/C035J346QQL/p1678149362238089)
2023-03-07 22:59:06 -08:00
JJ Kasper
9c36a3204a
Update app-static e2e test (#46900)
This ensures we properly check for the none cached content correctly

x-ref:
https://github.com/vercel/next.js/actions/runs/4351711739/jobs/7603961011
2023-03-07 12:51:37 -08:00
Jiachi Liu
030fd1d684
Fix conflict dev entry key between app and pages (#46832)
Add unique identifier `@app@` / `@pages@` / `@root@` for entry key of on
demand entries, so that they'll be unique for each path when the page
key is similar bewteen app and pages like (`"app/page"` and
`"pages/page"` will both end up with `/page`)


## Bug

Follow up for #46736
Closes NEXT-472

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

---------
2023-03-07 12:27:10 -08:00
Shu Ding
4b8240b842
Support unnamed default export expression (#46888
This PR adds the support for unnamed default export expression support
`export default async function () {}` in a "use server" entry, with
corresponding test.

Also fixed an existing bug that the default exported action's name
should be aligned with the export name, which is `"default"`.

Closes NEXT-769.
2023-03-07 19:16:45 +01:00
JJ Kasper
e0e627cf2a
Ensure chained middleware rewrites work properly (#46866)
Follow-up to https://github.com/vercel/next.js/pull/45772 this ensures
the rewrite header can be correctly set when a chained middleware
rewrite is occurring.

x-ref: [slack
thread](https://vercel.slack.com/archives/C01RGMANU9Y/p1678074803731489)

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)
2023-03-06 23:21:42 -08:00
JJ Kasper
8f5ffed72e
Update fetch cache handling with POST requests (#46856)
This updates to no longer skip caching POST or authed requests with the
fetch cache and instead we bail when `cookies()` or `headers()` is used
prior which is a better heuristic to signal user specific data would be
related to the fetch request.

x-ref: [slack
thread](https://vercel.slack.com/archives/C042LHPJ1NX/p1678130069138849)

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)
2023-03-06 21:30:29 -08:00
Will Binns-Smith
a9be890292
next/font tests: support Turbopack css module format (#46658)
Turbopack uses a different format for its css module classnames [0].
This adds and uses a helper function to the next-font tests to assert
against these classnames when testing with Turbopack. Ideally these
tests could be more behavioral (e.g. asserting on rendered dimensions),
but these can't capture things like fallback fonts.

[0] https://github.com/vercel/turbo/pull/3437
2023-03-06 15:06:36 +01:00
Shu Ding
088c19f709
Correct server reference manifest in prod build (#46683)
Since we have 2 server compilers (node and edge), the `serverActions`
object will always get overridden by the second compilation during `next
build`. Like the client reference manifest, we need to have 2 objects
for each compiler and merge them when outputting the asset.

Besides that, to avoid `export default` being tree-shaken as unused
export, I changed the loader to use CJS `module.exports` instead. Can't
easily figure out a proper way for now but we plan to create separate
worker for the action endpoint and this will be gone then.

Fixes NEXT-759, read NEXT-761 for the full future plan.

## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the
feature request has been accepted for implementation before opening a
PR.
- [ ] Related issues linked using `fixes #number`
- [ ]
[e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
2023-03-05 10:00:48 -08:00
JJ Kasper
9dd24a5931
Fix middleware 404 prefetch case (#46782)
Ensures we properly generate the 404 page when a path is being prefetched with middleware configured. 

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

Closes: https://github.com/vercel/next.js/issues/38239#issuecomment-1454928413
2023-03-05 02:32:53 +00:00
JJ Kasper
3e9a99c8b0
Fix middleware notFound: true handling (#46759)
This ensures we properly handle rendering the `404` page when `notFound:
true` is returned and middleware is present.

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

Fixes: https://github.com/vercel/next.js/issues/38239
x-ref: https://github.com/vercel/next.js/issues/43772

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2023-03-04 21:35:45 +01:00
Jiachi Liu
9a768d5e62
test: refactor metadata tests to test multi matches easier (#46746)
Use some utils to match multiple dom nodes together

#### Match multiple props for single DOM node
```tsx
const matchDom = createDomMatcher(browser)
await matchDom('meta', 'name="description"', { content: 'description' })
```

#### Match multiple same pattern DOM nodes in html
```tsx
const $ = await next.render$('html')
const matchHtml = createHtmlMatcher($)
await matchHtml('meta', 'name', 'property', {
  description: 'description',
  og: 'og:description'
})
```

#### Match same pattern DOM nodes in browser after hydration
```tsx
const matchMultiDom = createMultiDomMatcher(browser)
  await matchMultiDom('meta', 'property', 'content', {
  description: 'description',
  'og:title': 'title',
  'twitter:title': 'title'
})
```
2023-03-04 17:20:47 +00:00
JJ Kasper
8303c5648a
Pass through original matcher source in manifest (#46753)
This ensures we pass through the original matcher source in the
middleware manifest for posterity.
2023-03-03 16:55:41 -08:00
Shu Ding
ef685e8fb1
Adjust API route loader (#46726
Similar to #46328 but with `hasServerComponents: false` for the compiler
so RSC syntax constrains don't apply here.

Note that since we don’t bundle external modules in API routes, we can't
resolve to `react-server` so that one will be tricky.

Fixes NEXT-625

## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the
feature request has been accepted for implementation before opening a
PR.
- [ ] Related issues linked using `fixes #number`
- [ ]
[e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
2023-03-04 01:18:07 +01:00
JJ Kasper
33827ede54
Update client router filter to separate redirects handling (#46752)
x-ref: [slack
thread](https://vercel.slack.com/archives/C017QMYC5FB/p1677875647422339)
x-ref: [slack
thread](https://vercel.slack.com/archives/C049YV4U2F6/p1677875992732789)

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)
2023-03-03 16:02:02 -08:00
JJ Kasper
35d8e8379e
Ensure app chunk URLs are encoded properly (#46749
This ensures we properly encode chunks for app dir the same we do for
pages.

## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

x-ref: https://github.com/vercel/next.js/pull/8435
2023-03-03 14:17:07 -08:00
Jiachi Liu
bca80141d1
Fix require cache conflict between app and pages (#46736)
Related NEXT-472

When you have `app/page.js` and `pages/page.js`, the `pagePath` are the
same, which is `/page`. This will result require cache conflicts. When
you visit the `app/` page first, then the `pages/` page, the 2nd request
will still get the app dir page module, which result in server error.

Solution: use different cache key of pagePathCache for pages/ and app/ 

<!--
Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:
-->

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)
2023-03-03 12:24:09 -08:00
Wyatt Johnson
45492eacc0
Fix originalRequest not available for edge requests (#46741)
For requests made via the edge runtime, they will not contain the
`originalRequest` object used by the request storage to enable
headers/cookie access. This uses the request object passed when in the
edge runtime.
2023-03-03 18:14:49 +00:00
Jiachi Liu
4e54429369
Support multi title for alternates (#46700)
This allows to have different titles for alternates urls, but for canonical, you can only have one.

Closes NEXT-624

## Feature

- [x] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [x] Related issues linked using `fixes #number`
- [x] [e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
2023-03-02 22:42:10 +00:00
Wyatt Johnson
3229ed79a6
Support force-static on App Routes (#46693)
Supports `export const dynamic = 'force-static'` on App Routes. This strips pieces of information from the request object to ensure subsequent requests don't accidentally cache user specific data:

- Removes `searchParams`
- Removes `headers`
- Removes `cookies`
- Removes `host`
- Removes `port`
- Removes `protocol`

[NEXT-682](https://linear.app/vercel/issue/NEXT-682/force-static-doesnt-work-with-app-routes)
2023-03-02 19:28:37 +00:00
JJ Kasper
e7ee310f32
Add build worker exit tracking and enable tests (#46698)
Ensures we properly log when a compilation worker unexpectedly exits and ensures we enable the flag for some test suites to ensure it's covered. 

x-ref: https://github.com/vercel/next.js/pull/46666
x-ref: [slack thread](https://vercel.slack.com/archives/C04S835KUC9/p1677777414887749?thread_ts=1677775341.172509&cid=C04S835KUC9)
2023-03-02 18:33:20 +00:00
JJ Kasper
ed51bd870b
Fix static to dynamic on revalidate (#46668)
Since it's perfectly valid to do an authorized request during revalidate we shouldn't consider this a reason to throw the static to dynamic error during runtime. If an authorized request is done during build and caching isn't enabled for a path it will still bail from being turned into a Prerender. 

x-ref: [slack thread](https://vercel.slack.com/archives/C03KAR5DCKC/p1677734108126679)

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)
2023-03-02 10:14:56 +00:00
Jiachi Liu
63d81de6bc
test: add preconnect tests and move error tests (#46652)
* Add tests for `ReactDOM.preconnect | prefetchDNS | preload` usage
* Move mutate erroring tests to rsc-build-errors test suite
2023-03-01 23:09:16 +00:00
Shu Ding
dd2a1c693a
Add request callback in Flight client (#46650)
Adding the `callServer` option to Flight client with a naive implementation.

Fixes NEXT-393.

## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] [e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
2023-03-01 20:28:01 +00:00
JJ Kasper
68a1d54465
Update app-static test page (#46645
x-ref: https://github.com/vercel/next.js/pull/46522/files#r1120671063
2023-03-01 11:12:00 -08:00
Shu Ding
1717fd2dbc
Fix IntelliSense for generateMetadata (#46624)
Related to #46431, this makes sure the IntelliSense for both sync and async `generateMetadata` is correct.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] [e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
2023-03-01 17:25:25 +00:00
Hannes Bornö
b0b5cd8dc0
Add page path to repeated slashes in href error (#46557)
Currently if you find this error in your logs it's difficult to know
where it occurred. This adds the page pathname to the error message.

Before

![image](https://user-images.githubusercontent.com/25056922/221892504-383c0d31-5cc4-4e32-b317-9ebc42696151.png)

After

![image](https://user-images.githubusercontent.com/25056922/221892431-1dd2c3e5-b6aa-46a2-8ca9-3be266fee76f.png)

Ref:
[slack](https://vercel.slack.com/archives/C03KAR5DCKC/p1677527238287849?thread_ts=1677521794.667229&cid=C03KAR5DCKC)


## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the
feature request has been accepted for implementation before opening a
PR.
- [ ] Related issues linked using `fixes #number`
- [ ]
[e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
2023-03-01 00:10:11 -08:00
JJ Kasper
abf8a42326
Fix static to dynamic error in dev (#46597)
This corrects the static to dynamic error incorrectly showing in
development since we don't have enough information to accurately know if
this error should be thrown or not unless a build has been done.

Fixes: https://github.com/vercel/next.js/issues/46436
x-ref: [slack
thread](https://vercel.slack.com/archives/C03KAR5DCKC/p1677637140906959)

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)
2023-02-28 23:37:12 -08:00
JJ Kasper
076844e59f
Ensure URL can be passed to fetch correctly (#46592
Fixes: 

![CleanShot 2023-02-28 at 22 35
57@2x](https://user-images.githubusercontent.com/22380829/222042856-ee6dc3c4-c143-49f2-8023-5def749d6a64.png)


## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)
2023-02-28 21:32:28 -08:00
Jiachi Liu
b5f92c444b
Fix: canonical should allow relative urls (#46584)
alternate urls should allow string type for relative paths

## Bug

Fixes #45824

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

---------
2023-02-28 16:17:08 -08:00
Jiachi Liu
4b705a5473
Use og:image instead of og:image:url (#46570)
x-ref: https://github.com/vercel/next.js/discussions/46545

In the open graph protocol spec, `og:image` and `og:image:url` are identical. But some platform might don't have full support for it.

We change it back to render `og:image` as it's the most common and compatible format, also easy to align with the code docs
2023-02-28 21:46:15 +00:00
Shu Ding
9edf2d3d1f
Fix CSS imports not included in entries with a custom extension (#46571)
`entryName` will contain the extension if it's not a normal JS entry, this causes CSS being missing in pages with a custom extension in app dir (e.g. MDX). Here we add a `.replace(/\.[^\\/.]+$/, '')` to the entry name.

Fixes NEXT-709

## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] [e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
2023-02-28 18:53:48 +00:00
JJ Kasper
d49c700d0d
Fix shared entries/invalidators module scope (#46533)
This ensures we don't keep `entries` and `invalidator` in module scope
directly and nest it under a key specific to each compilation so
multiple `next` instances in the same process don't override one and
another.

## Bug

- [x] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

Closes: https://github.com/vercel/next.js/pull/46432
Fixes: https://github.com/vercel/next.js/issues/45852
2023-02-28 10:17:28 -08:00
Jimmy Lai
886dc9f30f
feat: add support for the src folder for the instrumentation hook (#46529) 2023-02-28 12:08:30 +01:00
Shu Ding
877f2f5996
Upgrade precompiled react packages (#46365)
Co-authored-by: Jiachi Liu <inbox@huozhi.im>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2023-02-28 10:13:02 +01:00
JJ Kasper
4ac4b757d4
Update fetch cache internal handling (#46522)
x-ref:
https://github.com/vercel/next.js/actions/runs/4288511720/jobs/7470646795
x-ref:
https://github.com/vercel/next.js/actions/runs/4288511720/jobs/7470647108
x-ref:
https://github.com/vercel/next.js/actions/runs/4288511720/jobs/7470647255
2023-02-27 21:39:11 -08:00
JJ Kasper
82f4fd3e8c
Update router filter to be less sensitive (#46515)
This skips including dynamic redirects in the client router filter as it
causes extra unexpected hard navigations.

x-ref: [slack
thread](https://vercel.slack.com/archives/C04MEB9L9RQ/p1677521159911179?thread_ts=1677255545.574209&cid=C04MEB9L9RQ)

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)
2023-02-27 17:07:26 -08:00
RTrace
9ad1f321b7
Add interactive-widget optional property to Viewport type (#46506)
## Feature

- [x] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [x] [e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)



Co-authored-by: Jiachi Liu <4800338+huozhi@users.noreply.github.com>
2023-02-27 23:12:56 +00:00
JJ Kasper
aa614635d6
Update fetch cache key (#46513
x-ref: [slack
thread](https://vercel.slack.com/archives/C042LHPJ1NX/p1677461963151879?thread_ts=1677360662.652689&cid=C042LHPJ1NX)

## Bug

- [x] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)
2023-02-27 14:14:14 -08:00
Shu Ding
9376a5afb2
Add image generation test to app route (#46449)
~~Currently blocked by #46448.~~
Closes https://github.com/vercel/satori/issues/410.

## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the
feature request has been accepted for implementation before opening a
PR.
- [ ] Related issues linked using `fixes #number`
- [ ]
[e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
2023-02-27 19:29:09 +01:00
Jiachi Liu
04547e8163
Add theme color media support for metadata (#46502)
x-ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta/name/theme-color

Resolves NEXT-525



## Feature

- [x] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [x] Related issues linked using `fixes #number`
- [x] [e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)
2023-02-27 18:22:05 +00:00
Hannes Bornö
bd9ad97c8e
Fix next/font/google config not being used (#46484)
Make sure both `@next/font/google` and `next/font/google` works when setting subsets in `next.config.js`.

Fixes NEXT-668

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] [e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
2023-02-27 12:18:19 +00:00
Seth Falco
adefdd2aaa
chore: show large data warning once per page on prod (#46323)
<!--
Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:
-->

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [x] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Related

* Closes https://github.com/vercel/next.js/pull/39146 - PR abandoned.

## Details

I was having the same issue at work, as a workaround, we've changed the
`largePageDataBytes` setting as advised but we'd like to keep the
warning ideally. It's something we need to address, but just don't want
to spam our log aggregators while the large data issue isn't resolved.

I believe I've more or less copied what was in the original PR, some
small differences:
* I use `Set` instead of `Map`, please let me know if there is an
advantage to using Map!
* Just to keep code a bit tidier (subjective) put an early return
instead of nesting all the code in an if.
* Added a test to verify only one log appears even when the page is
accessed twice [as requested
here](https://github.com/vercel/next.js/pull/39146#pullrequestreview-1064486985).
2023-02-25 12:29:59 -08:00
JJ Kasper
ebed7396f5
Ensure fetch fields are detected with RequestInit (#46398)
This ensures we properly detect fetch fields when a `new Request()` is passed to fetch instead of a separate `init` param. 

Fixes: [slack thread](https://vercel.slack.com/archives/C035J346QQL/p1677264109548949)
Closes: https://github.com/vercel/next.js/issues/46349

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)
2023-02-25 15:50:51 +00:00
JJ Kasper
725a4de0ef
Fix failing app-static deploy test (#46395)
x-ref:
https://github.com/vercel/next.js/actions/runs/4267518385/jobs/7429540548
2023-02-24 18:03:09 -08:00
JJ Kasper
c5336132c3
Fix fetch cache key inputs and encoding (#46392
This ensures we properly filter caching on uncachable request methods by
default and correct encoding handling in edge runtime.

Fixes: https://github.com/vercel/next.js/issues/46349
x-ref: [slack
thread](https://vercel.slack.com/archives/C042LHPJ1NX/p1677253242022489)

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)
2023-02-24 16:44:47 -08:00
JJ Kasper
51f9f5df2b
Apply filtering after rewrite as well (#46390
x-ref: [slack
thread](https://vercel.slack.com/archives/C04MEB9L9RQ/p1677279320253929?thread_ts=1677255545.574209&cid=C04MEB9L9RQ)

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)
2023-02-24 15:57:30 -08:00
JJ Kasper
de47336613
Revert "Support server-only inside pages/api" (#46388)
Looks like this is breaking when run against `vercel-site`, going to revert temporarily to allow investigating further without blocking canary. 

Reverts vercel/next.js#46328
2023-02-24 22:16:34 +00:00
OJ Kwon
dee944bb0f
test(next-script): teardown next-dev instance via jest hooks (#46383)
<!--
Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:
-->

Partially resolves WEB-628

This PR is minor improvement to the fixture setup for next-script test:
if one of test assertion using `finally` to teardown next instance
(next.destroy) times out, those clause won't be called so next instance
will leak, makes subsequent test fail. PR moves teardown to `afterEach`
hook instead. This relies on the assumption we run test in band
(serial), but internals of nextdevinstance already assumes it via its
own singleton.
2023-02-24 13:28:05 -08:00
Shu Ding
130ab594cd
Support server-only inside pages/api (#46328)
This can be a special case for the API layer.

## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the
feature request has been accepted for implementation before opening a
PR.
- [ ] Related issues linked using `fixes #number`
- [ ]
[e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)

---------
2023-02-24 12:44:12 -08:00
Hannes Bornö
18232f6e75
Dedupe next/font preload tags (#46354)
Just like https://github.com/vercel/next.js/pull/44938 did for CSS tags,
this makes sure `app-render` will only render one preload tag per font
file by keeping track of the rendered files in a set while building the
component tree.

Tested locally with react, react-dom and react-server-dom-webpack with
version `18.3.0-next-4fcc9184a-20230217`.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the
feature request has been accepted for implementation before opening a
PR.
- [ ] Related issues linked using `fixes #number`
- [ ]
[e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
2023-02-24 19:28:27 +01:00
JJ Kasper
66b82931a1
Handle same page reload case in filter (#46324)
Follow-up to https://github.com/vercel/next.js/pull/46317 this ensures
same page case is handled as well.

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)
2023-02-23 17:18:59 -08:00
Lee Robinson
4f0d76c40b
Migrate create-next-app and e2e tests to Metadata API. (#45819)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
Co-authored-by: Balázs Orbán <info@balazsorban.com>
2023-02-23 23:40:06 +00:00
JJ Kasper
8ff3d7ff57
Fix client filter case with redirects (#46317)
Follow-up to https://github.com/vercel/next.js/pull/46283 this ensures we properly handle redirects with matchers at the base and we don't use the normalized redirects when generating the filter as the breaks with i18n. 

x-ref: [slack thread](https://vercel.slack.com/archives/C040J1CGLHH/p1677028542232619)

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)
2023-02-23 20:14:57 +00:00
JJ Kasper
1bd84f5827
update test setup 2023-02-23 09:36:18 -08:00
JJ Kasper
99a7a34f96
Ensure generateStaticParams works in route (#46310)
x-ref: [slack
thread](https://vercel.slack.com/archives/C04DUD7EB1B/p1677165000745519)

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

---------

Co-authored-by: Jimmy Lai <laijimmy0@gmail.com>
2023-02-23 18:33:08 +01:00
Shu Ding
bcb20100db
Fix error on 404 page when middleware exists (#46303)
Closes #44293.

## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] [e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
2023-02-23 15:55:58 +00:00
JJ Kasper
5792533781
Update app cache handler loading (#46290
Follow-up to https://github.com/vercel/next.js/pull/46287 this updates
how we load the cache handler for the incremental cache so it's
compatible with edge and also adds regression testing with a custom
handler.
2023-02-23 01:19:59 -08:00