Commit graph

4047 commits

Author SHA1 Message Date
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
JJ Kasper
b3a7d9f030
Enable context caching for middleware/edge functions in dev (#47840)
As discussed this enables the context caching for the middleware/edge
functions sandbox in development which reduces execution time noticeably
as modules don't need to be re-processed for each request unless an HMR
event related to that context has occurred.

In a follow-up PR we can investigate spreading the middleware/edge
function invocations across workers/processes now that we have detached
rendering/invoke processes from the routing process.

<details>
	<summary>before</summary>

![CleanShot 2023-04-02 at 22 23
45@2x](https://user-images.githubusercontent.com/22380829/229419430-5eed36e9-2615-44be-9314-490cb7283e5b.png)

</details>

<details>
	<summary>after</summary>

![CleanShot 2023-04-02 at 22 24
41@2x](https://user-images.githubusercontent.com/22380829/229419472-822a2d16-7e0d-4ee8-99c2-b1211010ebcf.png)


</details>

x-ref: [slack
thread](https://vercel.slack.com/archives/C03KAR5DCKC/p1677431214936269)
Fixes: https://github.com/vercel/next.js/issues/43999
2023-04-02 23:51:25 -07: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
vinay
2601f55982
(Fix)(Tests)Fix typo in unit testing (#47644)
<!-- 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 Typo In Unit Testing
2023-04-01 22:23:15 -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
Steven
4c60b7b6ae
feat: bump minimum ts version to 4.5.2 (#47712)
Fixes an issue with newer app directory usage:

```
Failed to compile.
../../node_modules/next/dist/server/future/route-handlers/app-route-route-handler.d.ts:11:15
Type error: ',' expected.
```

---------
2023-03-31 11:37:09 -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
Steven
af49d5098b
chore(docs): update next export to output: 'export' (#47717)
fix NEXT-927 ([link](https://linear.app/vercel/issue/NEXT-927))
2023-03-31 02:04:23 +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
dbc4320035
test: remove unreliable font test (#47714)
x-ref:
https://github.com/vercel/next.js/pull/47674#issuecomment-1490914270

as discussed with @ijjk , we decided to remove the test as it's not
reailable due to random updates from google endpoint
2023-03-30 14:16:05 -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
Steven
b9d77321d2
fix: handle empty src prop on next/image (#47695)
Previously, `next start` was incorrectly trying to optimize an empty `src` prop.

This PR fixes the behavior so that empty `src` will automatically set `unoptimized` (same behavior as data urls).

fix NEXT-915 ([link](https://linear.app/vercel/issue/NEXT-915))
2023-03-30 20:02:47 +00: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
Steven
d19617e9c7
fix: image loaderFile with edge runtime (#47659)
- Fixes #47168 
- fix NEXT-909 ([link](https://linear.app/vercel/issue/NEXT-909))
2023-03-29 15:08:36 -07:00
Steven
b55633fe1c
fix: handle output: export with use client (#47635)
This PR removes usage of `appPaths` in favor of `hasAppDir` to avoid the
issue where export does not read app manifest.

Fixes the error:

```
TypeError: Cannot read properties of undefined (reading 'cssModules')
```

fix NEXT-885 ([link](https://linear.app/vercel/issue/NEXT-885))
2023-03-29 13:55:32 -07: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
28d56ec95f
Update test create-next-app running (#47611)
This re-enables running the CNA tests for all non-docs changes as it's now ensuring we don't regress on turbopack or our default templates. 

Also fixes the main repo's package.json files from being modified during tests.
2023-03-28 17:39:00 +00: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
OJ Kwon
73491e16c3
test(test-utils): correct --turbo error overlay lookup (#46901)
### Fixing a bug

Minor fix for https://github.com/vercel/next.js/pull/46589, forgot to
wrap in evaluate in result fail to ask to browser to lookup overlay in
--turbo tests.

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2023-03-26 21:30:16 -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
baae7b1f44
Clean up leftover loaders (#46801)
More cleanup flowing out of the removal of the `target` option.

<!--
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)

---------

Co-authored-by: Shu Ding <g@shud.in>
2023-03-25 10:21:27 +01: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
af89adbd61
Update fetch cache memory handling (#47465)
This ensures we only honor cache entries from the in memory cache for up
to 2 seconds so that revalidates can correctly propagate and also
increases max fetch cache entry size to 2 MB. The `fetchCache` export is
also being detected in this PR but not yet honored which will be done in
a follow-up.
2023-03-23 22:30:08 -07:00
Steven
26f8793e85
chore: add telemetry for output: export (#47464)
fix NEXT-870 ([link](https://linear.app/vercel/issue/NEXT-870))
2023-03-23 17:52:17 -07: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
Steven
4769407006
chore: run all tests for next/image against app dir (#47267)
These tests are copy/pasta from existing tests

- from `test/integration/next-image-new/default`
- to `test/integration/next-image-new/app-dir` 

There were a handful of changes need to migrate the fixture from `pages` to `app` but the test assertions are the same.

There is one test assertion for preload that wasn't working so its marked as "skip" until it can be fixed in a future PR.

fix NEXT-849 ([link](https://linear.app/vercel/issue/NEXT-849))
2023-03-23 22:02:40 +00: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
Steven
9791d1e608
feat: change next build to emit output with output: export (#47376)
This PR ensures the correct output is emitted during `next build` and
deprecates `next export`.

The `output: export` configuration tells it to emit exported html and
the `distDir: out` configures the output directory.

```js
module.exports = {
  output: 'export',
  distDir: 'out',
}
```

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

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2023-03-23 15:40:18 +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
Shu Ding
b1d2200770
Add optional match support of rewrites and redirects in typedRoutes (#47398)
This PR refactors the types plugin a bit and adds support for optional match groups in rewrites and redirects:

```js
source: '/redirect(/v1)?/guides/:param/page'
```

Which will be created as two rules:

```ts
| `/redirect/guides/${SafeSlug<T>}/page`
| `/redirect/v1/guides/${SafeSlug<T>}/page`
```

fix NEXT-875 ([link](https://linear.app/vercel/issue/NEXT-875))
2023-03-22 23:27:59 +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
JJ Kasper
84a416b5e1
Fix build spinner in TTY env (#47383)
This ensures the build spinner is correctly stopped in a TTY environment
and also adds regression tests for `app` and `pages` to ensure this
behaves as expected.

This updates our docker image to use the `jammy` tag instead of `focal`
to match the Ubuntu version to our CI.
2023-03-22 12:56:39 -07: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
Mark Ladyshau
054f786c8c
Skip warning if there is app directory for no-html-link-for-pages rule (#42516)
Skips pages directory warning if there is app directory in the root for `no-html-link-for-pages` lint rule.

Fixes #42448.

## Bug

- [x] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see `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`
- [ ] Integration 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`

## 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-22 02:15:52 +00:00
Steven
5eaaa3fbf7
fix: add pretty error for exportPathMap with app dir (#47371)
The `exportPathMap` feature has been unofficially deprecated for a long time since introducing `getStaticPaths()`.

For the `app` dir, the same can be accomplished with `generateStaticParams()`.

This PR adds a pretty error when using `exportPathMap` with `app` and updates documentation to reflect the current status.


fix NEXT-836 ([link](https://linear.app/vercel/issue/NEXT-836))
2023-03-21 22:22:34 +00: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
Balázs Orbán
5448c234d6
fix(cli): handle Tailwind CSS + src/ correctly (#47238)
### What?

- [x] fixes a bug in the CLI with the combination of `--tailwind` and
`--src-dir` flags.
- [x] fixes Tailwind CSS config when `--src-dir` is set
- [x] respect `NEXT_TEST_SKIP_CLEANUP` in test utils

### Why?

`pnpm create next-app@canary --tailwind --src-dir` should not fail.

### How?

We introduced the `app-tw` and `default-tw` templates, so we need to
respect them when working with files (in this case, the CLI was
erroneously assuming that if `template !== "app"` it must be a pages
template.)

I also noticed that the `tailwind.config.js` file need to also respect
`--src-dir` by prefixing the paths in `content`

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

Related: #46927, #47276

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2023-03-20 14:21:29 -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
Steven
7cc4159561
fix: handle different cases of React fetchPriority (#47302)
In React 18.3.0 or newer, we must user camelCase `fetchPriority` prop to avoid "Warning: Invalid DOM property".

In React 18.2.0 and older, we must use the lowercase `fetchpriority` prop to avoid "Warning: Invalid DOM property".

See https://github.com/facebook/react/pull/25927
2023-03-20 00:26:00 +00:00
meesvandongen
a76c929717
fix: typo in output:export error messages (#47252)
See changes
2023-03-19 19:58:56 +00:00
Shu Ding
e42a3d6d48
Fix loader rule with wrong matching conditions (#47261
This Webpack loader rule should have the exactly same conditions as


828fd5a162/packages/next/src/build/webpack-config.ts (L1940-L1951)

Except that it matches 2 special layers and an extra loader.
2023-03-17 23:35:02 +01:00
Steven
1aaae2998d
feat: add fetchPriority to next/image (#47222)
- Closes #43096 
- Available since Chrome 101:
https://chromestatus.com/feature/5273474901737472
- Coming to Safari: https://bugs.webkit.org/show_bug.cgi?id=252739
- Introduction blog: https://web.dev/priority-hints/


fix NEXT-319 ([link](https://linear.app/vercel/issue/NEXT-319))
2023-03-17 14:48:13 -07: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
Tobias Koppers
d760c00961
print reason for compilation (#47190)
### What?

add reason of compilation to the `updated in` message.


![image](https://user-images.githubusercontent.com/1365881/225526729-7ada5e84-78a0-4518-ad9c-48178fd4e7cb.png)

### Why?

the general update in message is confusing and didn't show what is
happening.

Sometimes people are confused why turbopack compiles something. The new
messages explain that turbopack timings measure request handing duration
in addition to pure compilation time.

### How?

depends on https://github.com/vercel/turbo/pull/4208

fixes WEB-722
2023-03-17 13:22:25 +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
Steven
bfed3985b1
fix: show error for api route handler with output: export (#47219)
In the case when the user configured `output: export` and used an API Route Handler that cannot be converted to static, Next.js must throw an error.

fix NEXT-823 ([link](https://linear.app/vercel/issue/NEXT-823))
2023-03-16 22:38:00 +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
Balázs Orbán
8c98a207f2
feat(cli): introduce --tailwind flag (#46927)
### What?

This PR introduces a new `--tailwind` flag to the `create-next-app` CLI,
to make it easier to bootstrap a Next.js app with Tailwind CSS
pre-configured. This is going to be the **default**. To opt-out of
Tailwind CSS, you can use the `--no-tailwind` flag.

### Why?

Tailwind CSS is one of the most popular styling solutions right now, and
we would like to make it easier to get started.

Currently, the closest you can come to this is by running `pnpm create
next-app -e with-tailwindcss` which will clone the
https://github.com/vercel/next.js/tree/canary/examples/with-tailwindcss
example. But that example is not configured for the App Router. This PR
will let you add Tailwind CSS to both `app/`, `pages/`, and start out
with TypeScript or JavaScript via the CLI prompts.

(Some community feedback
https://twitter.com/dev_jonaskaas/status/1632367991827443713,
https://twitter.com/samselikoff/status/1634662473331617794)

### How?

We are adding 4 new templates to the CLI bundle.

> Note: The styling is not pixel-perfect compared to the current
templates (using CSS modules) to require fewer overrides, but I tried to
match it as close as possible. Here are a few screenshots:

<details>
<summary><b>Current, light</b></summary>
<img
src="https://user-images.githubusercontent.com/18369201/224733372-9dba86fe-9191-471d-ad9f-ab904c47f544.png"/>
</details>

<details>
<summary><b>Tailwind (new), light</b></summary>
<img
src="https://user-images.githubusercontent.com/18369201/224733610-038d9d0f-634d-4b69-b5c2-a5056b56760c.png"/>
</details>

<details>
<summary><b>Current, dark, responsive</b></summary>
<img
src="https://user-images.githubusercontent.com/18369201/224733790-9b4d730c-0336-4dbe-bc10-1cae1d7fd145.png"/>
</details>

<details>
<summary><b>Tailwind (new), dark, responsive</b></summary>
<img
src="https://user-images.githubusercontent.com/18369201/224734375-28384bbc-2c3a-4125-8f29-c102f3b7aa1d.png"/>
</details>

#### For reviewers

This introduces 4 new templates, with a very similar code base to the
original ones. To keep the PR focused, I decided to copy over duplicate
code, but we could potentially create a shared folder for files that are
the same across templates to somewhat reduce the CLI size. Not sure if
it's worth it, let me know. Probably fine for now, but something to
consider if we are adding more permutations in the future.

---

~Work remaining:~

- [x] app+ts
	- [x] layout
	- [x] dark mode
	- [x] media queries
	- [x] animations
- [x] app+js
- [x] pages+ts
- [x] pages+js
- [x] prompt/config
- [x] deprecate Tailwind CSS example in favor of CLI
- [x] update docs
- [x] add test
- [x] add [Prettier
plugin](https://github.com/tailwindlabs/prettier-plugin-tailwindcss)
 
Closes NEXT-772
Related #45814, #44286
2023-03-16 16:06:27 +01:00
Jiachi Liu
f36a6d8964
Not apply image loader to metadata images (#47197)
Previously when we move to metadata images to custom app routes, when the image files get imported, it matches the `next-image-loader` rule which accidentally generate a static file into media.

This PR appends the metadata reource query to the imported rerource, and then skip in the `next-metadata-route-loader` so they won't get applied by image loader or emit any unexpected assets
2023-03-16 11:51:18 +00:00
Steven
9a89c4933d
fix: app dir with next dev and output: export (#47171)
This PR is a follow up to PR #47022 which broke `next dev`.

A test has been added to confirm `next dev` works as expected.

fix NEXT-825 ([link](https://linear.app/vercel/issue/NEXT-825)) ([NEXT-825](https://linear.app/vercel/issue/NEXT-825))
2023-03-16 00:36:08 +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
Steven
b590ec3961
feat: add output: export support for appDir (#47022)
We can now support `next export` for `appDir` because of the new config added in #46744.
fixes NEXT-775 ([NEXT-775](https://linear.app/vercel/issue/NEXT-775))
2023-03-14 20:43:46 +00: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
Johannes Obermair
82ed6a3b0d
Fix next/image config injection during static generation (#47007)
Fixes #39330.

I've not added a new test, but extended the existing test instead (and
re-enabled it).

It seems to me that a custom next/image config was not considered during
static generation (which itself uses `next export`?) before. Adding the
config to `renderOpts` in `packages/next/src/export/index.ts` resolves
the issue.
2023-03-13 10:47:05 -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
0bee9e6f92
test: update amp test to always check redbox (#47050) 2023-03-12 20:44:23 +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
Maksym Anisimov
74891fde18
Add auto-detection of image/x-icon content type (#47013)
Added auto-detection of image/x-icon content type by analyzing response buffer

fixes https://github.com/vercel/next.js/discussions/45998

Co-authored-by: Steven <229881+styfle@users.noreply.github.com>
2023-03-10 20:36:33 +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
Noemi
71dbcacf17
Do not re-assign process.env (#46914)
## Checklist

- [ ] Related issues linked using `fixes #number` 
  - no related issue exists, happy to open one if desired
- [x] Tests added
- not sure if specific tests are needed? there is an integration test
for environment variables, and Next.js relies a lot on passing
information through environment variables; i'd expect everything to
break if this change broke environment variable handling
- [x] Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md
  - no new errors, does not apply

### What?

Re-assigning `process.env` substitutes the "magic object" that sets
environment variables at the process level with an ordinary JavaScript
object. This causes environment variables that are set after
`process.env` is re-assigned to not be visible to native add-ons.

See [this Node.js issue][issue] and [this reproduction case][repro] for
details.

[issue]: https://github.com/nodejs/node/issues/46996
[repro]: https://github.com/unflxw/nodejs-process-env-addons-repro

### Why?

In general, paraphrasing the maintainer in the Node.js issue,
re-assigning `process.env` is not a thing you should do. More
specifically, I'm trying to use Next.js' experimental OpenTelemetry
support with AppSignal's Node.js integration, which also uses
OpenTelemetry.

The AppSignal Node.js package sets environment variables in order to
configure a long-running process, which is then launched through a
native add-on. Because of the re-assignment of `process.env` that occurs
early in Next.js' lifecycle process, by the time the AppSignal Node.js
package sets environment variables, it's setting them in an ordinary
JavaScript object that Next.js left in the global `process` object, not
in the magic one created by the Node.js runtime.

This means that these environment variables are not _actually_ being set
for the process at the OS level, and therefore they're also not set for
the native add-on, or for the long-running process it spawns.

### How?

A `replaceProcessEnv` function is implemented that takes an environment
object as an argument, and applies the difference between that
environment object and the current environment to the existing
`process.env` object. This function is used instead of re-assigning
`process.env`.

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2023-03-09 14:41:50 -08:00
Hannes Bornö
9a41ba9ac4
Improve RSC compiler error in external module (#46953)
When the RSC compiler error was caused by an external package, make the
error message display which import caused the error. Also don't show
node_module files in the import trace.

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

Before

![image](https://user-images.githubusercontent.com/25056922/224032476-6811a1d5-d690-48be-9602-781f459edc70.png)

After

![image](https://user-images.githubusercontent.com/25056922/224032177-2d0b2977-098f-46bd-8e30-9e6bc21b9153.png)

Updates the format of the files, from `app/page.js` to `./app/page.js`
to align it with other import traces.

![image](https://user-images.githubusercontent.com/25056922/224030420-1d3ff0ba-5747-4ed3-8b0b-9c4deace54ea.png)


Closes NEXT-523
2023-03-09 12:27:57 -08:00
Hannes Bornö
09d21d6e99
Move error overlay recovery tests to new file (#46965)
Move error overlay recovery tests in `ReactRefreshLogBox.test.ts` to a
new file. This is already done for the app router tests, but this does
it for the old router as well. Makes `ReactRefreshLogBox.test.ts` faster
to run.
2023-03-09 12:15:30 -08: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
Hannes Bornö
0e073366da
Reduce the number of hydration error tests (#46930)
`test/development/acceptance-app/hydration-error.test.ts` has a lot of tests because I ported all the tests in https://github.com/facebook/react/blob/main/packages/react-dom/src/__tests__/ReactDOMHydrationDiff-test.js. Running all those tests takes a lot of time, and to include all the different cases is overkill.

This PR removes most tests but keeps one test case per type of hydration error, and also one using suspense. This makes more sense, it should only test that all the different hydration error messages are picked up.
2023-03-08 16:41:21 +00: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
Jan Kaifer
8b50b80cde
eslint rule for script strategy should work properly in app/ (#46609)
fixes https://github.com/vercel/next.js/issues/46549

The docs are wrong for now, this limitation is just in `pages/`, you can
use it anywhere in `app/`.

Since `app/` is still not stable we will emit that warning in all files
outside of `app/`.
2023-03-08 11:28:52 +01: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
Shu Ding
105e5b0088
Add retry to the hmr acceptance test (#46902)
This one seems to be flaky ([example](https://github.com/vercel/next.js/actions/runs/4357945817/jobs/7618498044)) as the default `page.goto` timeout is set to 30s, while it already takes 15~20s to load locally on my laptop. So let's add some retries here.
2023-03-07 22:39:50 +00: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
Sukka
26768571ad
test(unit): add cases for cssnano simple (#46862)
Continues from #46380. The PR migrates the unit test cases from the original repo into the Next.js repo.
2023-03-07 06:28:53 +00: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
Hannes Bornö
d59aa9655e
Port error overlay hydration error to pages directory (#46677)
Co-authored-by: JJ Kasper <jj@jjsweb.site>
2023-03-06 19:40:25 -08:00
Hannes Bornö
533748d383
next/font refactoring and additional unit tests (#46731)
Currently all helper functions are exported from huge utils files. This
moves the helper functions to their own files, this approach aligns
better with the rest of the codebase.

The unit tests are split up and colocated with the function it tests.
Also added some missing tests.

Plus some overall cleanup, added comments and fixed types.

## 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-06 17:16:25 -08:00
Ngô Đức Anh
ceb028a469
Fix(typedRoutes): fixed type Route resolving to type any (#46679)
This PR makes `typedRoutes` stricter by constraining generics in  `Route` to type string. I've also made generating types for routes a bit more efficient by moving `redirects` and `rewrites`'s processing to the plugin's constructor since `rewrites` and `redirects` don't change in both dev and prod.

I've also been trying to fix a bug where route types doesn't generate all the routes (some appear, some don't), but I've got no clues since that doesn't seem easy to reproduce (perhaps it only happens in my case?)

## 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-07 00:05:39 +00: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
Steven
25efdfad36
Add support for output: export config (#46744)
## Background

In the early days, `next export` was created when Next.js was SSR-only in order to statically export your pages for self hosting where no server was available. However, around the time `getStaticProps()` and `getStaticPaths()` were introduced, Next.js began [automatically generating static pages](https://nextjs.org/docs/advanced-features/automatic-static-optimization) (SSG first and SSR opt-in) during `next build`. This meant there were very few reasons to use `next export` and it started to become a stale feature.

## Problem We Need To Solve

Users targeting `next export` currently have a really bad experience. They start a new project and use all the features Next.js has to offer because they all features work with `next dev`. Then when development is finished and it comes time to deploy, running `next build && next export` will fail with errors for [unsupported features](https://nextjs.org/docs/advanced-features/static-html-export#unsupported-features).

## Solution

This PR introduces a new configuration option, `output: 'export'`, to indicate that the user intends to run `next export`.

With this change, Next.js can fail fast during `next dev` if any [unsupported features](https://nextjs.org/docs/advanced-features/static-html-export#unsupported-features) are used, thereby improving developer experience with instant feedback.


```js
/**
 * @type {import('next').NextConfig}
 */
const nextConfig = {
  output: 'export',
}

module.exports = nextConfig
```
2023-03-04 00:46:20 +00: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
JJ Kasper
c62791294e
Ensure default config passes schema checks (#46656)
This ensures our config schema correctly validates with the default
config we provide.

Fixes: https://github.com/vercel/next.js/issues/46626

## 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-01 14:45:58 -08:00
Michael Novotny
5e112c062e
Updates next/image eslint message to denote that costs may be incurred. (#46640)
Changes ESLint warning message to still encourage usage of `next/image`
for the best experience, but also denoting that optimization could come
with incurred costs.

## Feature

- [x] Documentation added
- [x] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Documentation / Examples

- [x] Make sure the linting passes by running `pnpm build && pnpm lint`
- [x] 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: Steven Tey <stevensteel97@gmail.com>
Co-authored-by: Steven <steven@ceriously.com>
2023-03-01 14:28:09 -08:00
teobler
5cc9010277
fix: distDir in verifyTypeScriptSetup for nextLint (#46630)
fixes #46611 

this PR fixed customer dist type(`distDir` option in next.config.js) in
`tsconfig.json` will be a hard coded absolute path issue which is a bug
from PR #46249
since dist type only be added when user using app dir, to reproduce this
issue you need to make `app dir` toggle on and add a `distDir` option in
`next.config.js` file

## 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-01 14:01:45 -08: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
John Daly
725fbc29ce
[next/jest] Support path aliases from tsconfig/jsconfig (#45815)
<!--
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:
-->

# Description

fixes #31159
fixes #44553

Path aliases defined in `tsconfig.json` or `jsconfig.json` are not
automatically configured to work with Jest. This means that these
aliases have to be defined in multiple places.

This PR configures the SWC Jest transform to handle the `baseUrl` and
`paths`, so that users don't need to configure a `moduleNameMapper` for
Jest.

~This PR intends to make the experience more seamless by automatically
configuring Jest's `moduleNameMapper` and `moduleDirectories` based on
the settings in a project's `tsconfig`/`jsconfig`.~

~Users will be able to supply their own configuration for these fields,
if they have use-cases that require manual configuration.~

~The implementation is taken from the [`paths-to-module-name-mapper`
function in
`ts-jest`](5a0880add0/src/config/paths-to-module-name-mapper.ts).~

## 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.
- [x] 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 10:52:32 +01:00
OJ Kwon
5acabf00d8
test(utils): support turbopack-based overlay error text lookup (#46589
<!--
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:
-->

- closes WEB-672. 

Due to differences of error overlay layout between turbopack and normal
next-dev, test fixtures cannot lookup corresponding error text with same
data-* tag. Companion PR https://github.com/vercel/turbo/pull/4015 added
new tag for the turbopack specific, and this PR utilizes those if test
runs against --turbo.

## Bug

- [x] Related issues linked using `fixes #number`
2023-03-01 10:23:39 +01: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
Ngô Đức Anh
ff699471bf
Fix(typedRoutes): fixed Webpack crashing without redirects/rewrites (#46591)
<!--
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:
-->

This PR fixes some issue caused by PR 46327, which asserted that
`NextBuildContext.original(Rewrites|Redirects)` are defined although
`config._original(Redirects|Rewrites)` (which these two copied from) are
not actually defined when `config.redirects`/`config.rewrites` are not
as well (see `loadRedirects`/`loadRewrites`). So this PR fixes that by
removing those assertions and checking whether those are defined in
`createRouteDefinitions` before iterating them.

## 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-28 22:12:11 -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
Shu Ding
5532b6a93f
Fix app client child entry not being disposed when deleting the file (#46583)
Currently if a file or folder (that contains an entry) is renamed in app dir, the dev server will stop working because we never remove the old entry. Since all client entries in app dir are created as child entries programmatically via the RSC plugin, they're different and not handled by our existing hot reloader logic:

f0cbe84e4c/packages/next/src/server/dev/hot-reloader.ts (L666-L677)

This PR adds a file path to child entries as well (it can be layout, page and other entries) so in the entry generation step we can prune the invalid ones.

Fixes #46379, fixes NEXT-650.

## 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 23:32:03 +00: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
teobler
b6b7933377
fix: generate next-env.d.ts file during next lint command (#46249)
fixes #46104

## 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)

---------

Co-authored-by: Wyatt Johnson <accounts+github@wyattjoh.ca>
2023-02-28 11:51:22 -08:00
Steven
18dc09bf55
fix: should not warn when image unmounts (#46567)
- Fixes #40762

---------
2023-02-28 11:28:55 -08: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
JJ Kasper
619c76c0f9
Fix infinite invalidations loop in app dir (#46526)Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This fixes a case where depending on the timings of compilers being done
could cause an infinite invalidation loop.

**Before**


https://user-images.githubusercontent.com/22380829/221786587-1a4cc6ab-f273-4191-92af-a57e9fff1261.mp4

**After**


https://user-images.githubusercontent.com/22380829/221786611-f55c3da9-0201-40be-95a8-3ef1869d6a66.mp4

x-ref: [slack
thread](https://vercel.slack.com/archives/C03KAR5DCKC/p1677441845988529?thread_ts=1677429424.151329&cid=C03KAR5DCKC)

## 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)

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2023-02-28 11:07:29 +01:00
Shu Ding
5ff005f7b5
Refactor route types to include rewrites and redirects (#46327)
This PR refactors the implementation of `Route<T>` to be more compact
(2/3 fewer union types), and adds support for static rewrites and
redirects. Check the updated test for more details.

In the future I plan to continue to refactor this by extract static
routes out as unions (instead of always relying on type inference) for
better autocompletion. Maybe a dev-only feature?

## 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 10:18:47 +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