Commit graph

1181 commits

Author SHA1 Message Date
mPaella
d492b937e2
fix: Incorrect build size outputs for app dir (#50768)
### What?
Fixes https://github.com/vercel/next.js/issues/50129

### Why?
The current denormalization of app dir paths doesnt account for the
normalization done in `normalizeAppPath`, causing build log outputs for
certain paths such as anything under a route groups to be incorrect

### How?
There's 2 ways this could be fixed:

1.) Denormalize the app dir paths by reading the
`app-path-routes-manifest.json` and mapping back to the original file
path
2.) (what I chose to do) Normalize the keys of `appBuildManifest`

### Result

App dir paths, including route groups, now have their correct output
size

<img width="494" alt="image"
src="https://github.com/vercel/next.js/assets/93682696/0eee79b8-7d60-4c88-b07a-dfb750aa9592">

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2023-06-14 14:24:57 -07:00
Shu Ding
754c6480cb
Invalidate client cache when cookies have changed in Server Actions (#51290)
Similar to tags and paths, when `cookies().set()` is called we have to
invalidate the client router cache as well so routes with
`cookies().get()` will not holding the stale data. This is critical for
auth and other scenarios.

In the future we can have an optimization to only invalidate routes that
actually rely on cookies, similar to paths.
2023-06-14 17:26:27 +02:00
Jimmy Lai
c6c4a3d3eb
app router: fix double fetch on prefetch={false} (#51292)
This PR fixes a few reports that we were double fetching when navigating via a link that had prefetch false.

## Context

The bug was happening because we were inadvertently eagerly fetching even if we potentially bailed out of the optimistic navigation, which would then trigger another fetch from going through the regular navigation path.

There's potentially another bug here where we should potentially not bail out of optimistic navigation in the cases reported but we can fix that later.



fix #49844
link NEXT-1287
2023-06-14 13:42:14 +00:00
Tim Neutkens
dd937bde09
Remove edge functions tracking in dev server (#51122)
## What?

While looking at the CPU profile of booting up Vercel's site I noticed
that we call `getPageStaticInfo` a lot. Looking into this more it turns
out `getPageStaticInfo` is currently called for all routes, `pages` and
`app`, even though the data is only being used to keep track of which
routes are edge functions, however, this is already tracked as part of
the build output so this didn't make sense to me. First I tried
commenting out this entire block and all tests were passing, so I
removed it except for middleware as middleware can provide a `matcher`
which does need to be known before compiling the file as of right now.

After that change a different set of tests started failing, specifically
the one that checks if we warn correctly. Interestingly by fixing
`getPageStaticInfo` being called early and for all routes it also caused
these warnings to no longer trigger as there was a case in the manifest
plugin that called `getPageStaticInfo` with less information. Calling
`getPageStaticInfo` there was not needed either as we call
`getPageStaticInfo` at the beginning of the build for each entrypoint so
we already have the information required, it just had to be passed down
so that the manifest plugin could use it.

For Vercel's site this change improves booting the dev server by over 1
second.

Related to #48748

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

- Read the Docs Contribution Guide to ensure your contribution follows
the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

### Adding or Updating 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: Jiachi Liu <inbox@huozhi.im>
2023-06-14 13:17:16 +02:00
JJ Kasper
aa8400c2ca
Update flakey rsc streaming test (#51274)
This is checking for only alpha-numerical chars for the build_id value
although they can also contain dashes

x-ref:
https://github.com/vercel/next.js/actions/runs/5263773644/jobs/9514284188#step:25:454
2023-06-13 23:37:19 -07:00
Zack Tanner
3427d324d8
fix: app router hash scrolling should respect scroll-padding (#51268)
When navigating to a route with a hash parameter, the layout router
jumps to the element by scrolling to the node's `offsetTop` value.
However, this will ignore `scroll-padding`, which deviates from browser
behavior.

It looks like this isn't an issue in the pages router which currently
makes use of
[`scrollIntoView`](https://github.com/vercel/next.js/blob/canary/packages/next/src/shared/lib/router/router.ts#L2262).

Closes NEXT-1171
Fixes #49612

---------
2023-06-13 20:50:51 -07:00
Jiachi Liu
6e5169b17a
Add buildId into RSC payload (#50974)
Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
2023-06-13 17:58:07 +02:00
Jiachi Liu
9d0129c635
Fix standalone not found (#51172)
Fixes #50232

Passing down the private env into `'render-server'` module to pick up the proper react with require-hook in standalone server
fix NEXT-1260
2023-06-12 21:14:32 +00:00
Jiachi Liu
8a11835fbe
Strip _rsc query for navigation between app and page (#51195)
Fix a missing case from #50970

When navigating from app to page, the `_rsc` query should still be stripped
2023-06-12 20:36:36 +00:00
Jiachi Liu
74225d1945
Prefer module fields for RSC server layer (#51179)
Follow up for #50548 

There're some packages like `aws-sdk-js-v3` which doesn't have a exports field yet: 

```
  "main": "./dist-cjs/index.js",
  "types": "./dist-types/index.d.ts",
  "module": "./dist-es/index.js",
 ```
 
 This PR let u pick up by the js assets based on main fields, will prefer `"module"` field instead of `"main"`
 
 Closes NEXT-1286
2023-06-12 17:50:12 +00:00
Jiachi Liu
aa3e043bbf
Add unique search query for RSC requests to be cacable on CDN (#50970)
Adding a `_rsc` query for RSC payload requests so that they can be
differentiated on resources level for CDN cache for the ones that didn't
fully respect to VARY header.

Also stripped them for node/edge servers so that they won't show up in
the url

x-ref:
https://github.com/vercel/next.js/pull/49140#issuecomment-1549405009

Closes #49140
Closes NEXT-1268
2023-06-12 11:52:36 +02:00
Jiachi Liu
2bc1061609
Apply optimization to middleware when using babel (#51067)
Like how we handled RSC loader transform before, we also apply swc
loader to middleware to make sure the imports optimization is applied so
og package won't be bundled

Fixes #50492
2023-06-09 13:33:14 -07:00
Jiachi Liu
558632b5f2
Avoid server insertion react key warning (#51053)
Wrap server inseration children with react key to avoid react key
warning display
2023-06-09 10:18:19 -07:00
JJ Kasper
480df20086
Ensure headers instance is serialized (#51047)
This makes sure we properly include headers in the cache key when a
headers instance is used.

x-ref: [slack
thread](https://vercel.slack.com/archives/C042LHPJ1NX/p1686234796532989)
2023-06-09 09:35:45 -07:00
Michael Novotny
55b29fb351
Updates prettier to latest version. (#51000)
There are some incoming docs / MDX changes where prettier will throw an error when using the older version. Updating prettier before I bring in those changes.

Looks like the most notable change is adding parentheses around `typeof` checks in TypeScript. 

**Before**

```
export type Locale = typeof i18n['locales'][number]
```

**After**

```
export type Locale = (typeof i18n)['locales'][number]
```
2023-06-09 14:58:19 +00:00
Jiachi Liu
f19b31ad93
Fix rsc payload fetch failures due to state tree encoding (#51017)
Encode the state tree where the content could contain unicode when
request the RSC payload, to avoid the fetch failure due to bad encoding
for headers

Fixes #48728
fix NEXT-1258
2023-06-09 12:06:00 +02:00
JJ Kasper
cdd366fd97
Fix usage of router.refresh() with Draft Mode in App Router (#50941)
After enabling Draft Mode, `router.refresh()` was incorrectly causing the page to crash and do a full page refresh.

This PR fixes this case.

Co-authored-by: Steven <229881+styfle@users.noreply.github.com>
2023-06-09 00:15:55 +00:00
Shu Ding
b8e308f511
Add test for hidden form fields at the beginning of a Server Action form (#50978)
Fixes #50087. The root cause was fixed in upstream React and here's a
test to ensure it works end to end.
fix NEXT-1228
2023-06-08 19:25:56 +02:00
Steven
9a9d095b54
Bump to typescript@5.1 (#50557)
We need to upgrade TypeScript to land the following fixes:

- https://github.com/vercel/next.js/pull/50289
- https://github.com/vercel/next.js/pull/48018

And it should fix async components:
- https://twitter.com/sebsilbermann/status/1664356039876124672

Also see this related TS 5.0 issue:

- https://github.com/microsoft/TypeScript/issues/53402
2023-06-08 17:18:37 +00:00
Jiachi Liu
a035224dc3
Pick esm main fields and condition names first for RSC server layer (#50548)
For RSC server layer so far we bundle all dependencies, ESM format is the better one rather than CJS to analyze and tree-shake out the unused parts. This PR changes pick the condition names that are in ESM format first for server layer.

Also fixes the misorder of condition names of edge runtime, `conditionNames` should only contain either ESM or CJS, previously the main fields are mixed with conditon names which is not expected for webpack, we separate them now.

Since we're picking ESM instead CJS now, the error of require `exports * from` doesn't exist anymore, but if you're using a CJS dependency which require a ESM package, it will error. This is the existing behavior for our webpack configuration but could happen on server layer bundling

Other related changes:

* Imports are hoisted in ESM, so migrate`enhanceGlobals` to a imported module
* Use `...` to pick the proper imports by import expression, and prefer the `react-server` / `edge-light` condition names for corresponding cases
* Remove edge SSR duplicated `middleware` export checking
2023-06-08 16:24:03 +00:00
Shu Ding
b7d438cfc1
Invalidate prefetch cache when a tag or path has been revalidated on the server (#50848)
This makes sure that if `revalidateTag` is called in a Server Action, the client router cache and prefetch cache are invalidated correctly so following navigations won't reuse the cache that might hold stale data.

Similar case for `revalidatePath`. I left a TODO where we can't just invalidate the subtree under the revalidate paths because of current implementation limitations. To ensure correctness, we just do the same as `revalidateTag`.
2023-06-08 13:44:42 +00:00
Jiachi Liu
452d390ec0
Fill basic twitter metadata with opengraph when missing (#50854)
When twitter metadata is not provided but opengraph metadata is, fill the opengraph basic information for twitter metadata.
Twitter card can't be displayed if there's no information from twitter meta tags, at least the `twitter:card`. We fill the `title` `description` and `images` these 3 overlapped properties from opengraph image so they can be displayed properly

Closes NEXT-1111
2023-06-06 20:54:14 +00:00
Tim Neutkens
230641adfd
Bail out of 404 page when favicon.ico doesn't exist (#50795)
## What?

Anytime you open a Next.js application that doesn't have a `favicon.ico`
you'll notice `/_error` is being compiled because the browser requests
`favicon.ico`. This PR ensures the 404 page is not compiled in
development for that request. It helps a little with compilation speed.

<!-- 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-06-06 10:58:40 +02:00
JJ Kasper
8e9613fae5
Update fetch dynamic error handling (#50822)
Updates to not throw the dynamic server error inside of the patched
fetch as it's typical for fetch errors to be caught and handled and this
error is not meant to be caught by users. This instead throws it during
rendering so we can ensure we catch it instead of users.

x-ref:
https://github.com/vercel/next.js/actions/runs/5182384027/jobs/9339123096
2023-06-05 21:47:01 -07:00
Tim Neutkens
886b38916a
Add hello-world test for pages and app (#50780)
## What?

Recently I've been using these hello-world tests quite often to get the baseline traces out for `pages` and `app`.
Adding them to the repo so that I don't have to recreate / stash them all the time.
2023-06-05 12:05:58 +00:00
Steven
d13fe04f1e
fix: conditional cookies in draft mode (#50660)
fix NEXT-1246
2023-06-02 17:30:10 +00:00
Shu Ding
89a62ac4c8
Remove cssFiles field (#50610)
This field is no longer needed. Although removing it might cause
unnecessary styles being included that could be tree-shaken potentially,
it solves a more critical issue of missing CSS resources: since now CSS
import can be "hoisted" to its parent entry (e.g. a layout), we can't
simply get all used CSS resources from the "leaf entry" (e.g. a page).
2023-06-02 09:24:03 +02:00
Shu Ding
470e48c001
Fix CSS duplication related problems (#50406)
This PR fixes a couple of categories of CSS issues in App Router, that
come from the same root cause.

### 1. Duplicated styles being loaded in different layers

This issue has been described in
https://github.com/vanilla-extract-css/vanilla-extract/issues/1088#issuecomment-1563931144.
If a CSS module (or a global CSS) is referenced in multiple layers (e.g.
a layout and a page), it will be bundled into multiple CSS assets
because each layer is considered as a separate entry.

<img width="1141" alt="CleanShot-2023-05-26-GoB9Rhcs@2x"
src="https://github.com/vercel/next.js/assets/3676859/8e0f5346-ee64-4553-950a-7fb44f769efc">

As explained in that issue, we have to bundle all CSS modules into one
chunk to avoid a big number of requests.

### 2. CSS ordering issues (conflicts)

This is likely causing https://github.com/vercel/next.js/issues/48120.
When the layer-based bundling and ordering logic applies to CSS, it can
potentially cause non-deterministic order. In this example, button A in
the layout should be in blue. However when button B is imported by the
page, button A becomes red. This is an inconsistent experience and can
be hard to debug and fix.

<img width="1090" alt="CleanShot-2023-05-26-Ar4MN5rP@2x"
src="https://github.com/vercel/next.js/assets/3676859/4328d5d7-23af-4c42-bedf-30f8f062d96a">
2023-05-30 13:55:10 +02:00
Tobias Koppers
ffb68e95e5
disable test case for Turbopack (#50530)
### What?

This test case was never passing and accidentally enabled for Turbopack.

We could disable the whole test suite, but since only one test case is
affected we can also disable only that one.
2023-05-30 12:08:48 +02:00
Tim Neutkens
f85b45fb31
Optimize Next.js bootup compilation (#50379)
## What?

Currently we use the initial compile to add entrypoints that we know are
going to be used in the application. For example the Next.js runtime,
`react`, `react-dom`, and such. While this was the right default when
Next.js only had `pages`, it's no longer true when both `pages` and
`app` exist. E.g. when you're working on a page using App Router we'd
still compile `pages/_app`, `pages/_document`, and `pages/_error` even
though those would not be used. In case of larger applications (e.g.
Vercel's application) this would mean thousands of extra modules being
compiled even though you don't need them for the page you're looking at.
Similarly we'd compile the Next.js runtime for App Router even when
you're only using `pages`.

This PR changes the handling to only compile the entries that are needed
for the current set of visited pages (on-demand-entries). If that set
only includes `app` entrypoints then the `pages` related files will be
excluded. If the set contains both `app` and `pages` both will be
included. Similarly for `amp`, if you don't use `amp: true` / `amp:
hybrid` the development runtime will not be compiled.

📔 Note: This is specifically for webpack, Turbopack already compiles
everything needed lazily so it didn't have this limitation.

#### Before

```
- event compiled client and server successfully in 1079 ms (306 modules)
- event compiled client and server successfully in 155 ms (306 modules)
```

With opening `/`:

```
- event compiled client and server successfully in 1118 ms (306 modules)
- event compiled client and server successfully in 157 ms (306 modules)
- event compiled client and server successfully in 599 ms (486 modules)
```

Total: 1.874ms (Note: This number is much higher when `pages/_app`
imports many modules).

#### After

```
- event compiled client and server successfully in 118 ms (20 modules)
- event compiled client and server successfully in 65 ms (20 modules)
```

📔 Note: opening the page then causes the Next.js / React runtime to be
compiled ofcourse

```
- event compiled client and server successfully in 115 ms (20 modules)
- event compiled client and server successfully in 57 ms (20 modules)
- event compiled client and server successfully in 1137 ms (361 modules)
```

Total: 1.309ms (Note: This number is not affected by`pages/_app`
importing many modules).

## How?

We can only apply this optimization after we've looped over the list of
on-demand entries, as that has the required metadata. Hence why I went
with deleting the keys for each respective type of entrypoint (`pages`,
`app`, `amp`).

<!-- 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-05-30 12:03:24 +02:00
JJ Kasper
7adb273b02
Update flakey rsc manifest test (#50506)
x-ref:
https://github.com/vercel/next.js/actions/runs/5106369085/jobs/9182910605
x-ref:
https://github.com/vercel/next.js/actions/runs/5114050873/attempts/1
2023-05-29 11:47:00 -07:00
JJ Kasper
679d864c5f
Revert "land: Include charset=utf-8 with x-component Content-Type header" (#50472)
This change isn't necessary per
https://github.com/vercel/next.js/pull/50060#issuecomment-1562897282 and
doesn't alleviate the root issue that was attempting to be addressed
instead that is related to a different issue upstream which is being
investigated.

Reverts vercel/next.js#50314
2023-05-29 10:21:54 -07:00
JJ Kasper
29c2e89bd1
Break up large test suites (#50458)
This breaks up some of our longest running tests which allows more
parallelizing of the tests. This also moves turbopack tests filtering
back to an allow list as it is running a lot of unrelated tests
currently which isn't ideal. We should only be running against tests
that are explicitly testing turbopack e.g. build tests should not be
duplicated in the turbopack group.

```sh
test/integration/css/test/group-1.test.js: 762.655
test/integration/edge-runtime-module-errors/test/index.test.js: 695.309
test/integration/css/test/group-2.test.js: 671.848
test/integration/i18n-support/test/index.test.js: 518.173
test/integration/scss-modules/test/index.test.js: 451.704
test/integration/css-features/test/index.test.js: 417.318
test/integration/css-modules/test/index.test.js: 403.405
test/integration/eslint/test/index.test.js: 381.563
test/integration/500-page/test/index.test.js: 371.134
test/integration/telemetry/test/index.test.js: 367.691
test/development/acceptance-app/ReactRefreshLogBox.test.ts: 335.878
test/integration/create-next-app/templates.test.ts: 334.01
test/integration/scss/test/group-2.test.js: 327.255
test/integration/scss/test/group-1.test.js: 318.574
test/integration/edge-runtime-configurable-guards/test/index.test.js: 313.834
test/e2e/instrumentation-hook/instrumentation-hook.test.ts: 294.618
test/development/acceptance-app/error-recovery.test.ts: 283.355
test/e2e/app-dir/app/vercel-speed-insights.test.ts: 278.242
test/integration/create-next-app/index.test.ts: 272.442
```
2023-05-28 13:59:41 -07:00
Keyan Zhang
8e202610a4
App Router: fix relative query/hash handling in next/link and router push/replace (#49521)
## Problem
Relative hash/query handling in `next/link` (e.g. `<Link
href="#hello">`) is broken in App Router, especially if you're on a
nested route.

This wasn't a problem in `/pages` because the href always get fully
resolved in `<NextLink>`; i.e. if you have `<Link href="#hash" />` on
`/hello`, it'll resolve the href to `/hello#hash` and use that
everywhere.

However, in App Router, `<Link>` no longer uses the current location to
resolve the href:
5451564f36/packages/next/src/client/link.tsx (L450-L457)

Therefore navigating with `new URL(href, location.origin)` will skip the
current path and always apply the relative hash/query to the _root_
route:
5451564f36/packages/next/src/client/components/app-router.tsx (L208-L215)

## Solution
Not 100% sure if this is the best solution, but since `app-router` is
already reading `window.location`, I'm using `location.href` as the base
URL to resolve the href.

I grep'd for `location.origin` and checked other callsites; seems like
only `app-router` deals with user specified hrefs.

Fixes https://github.com/vercel/next.js/issues/42157 &
https://github.com/vercel/next.js/issues/44139, and potentially
https://github.com/vercel/next.js/issues/48554 and
https://github.com/vercel/next.js/issues/22838

## Test Plan
```
pnpm testheadless test/e2e/app-dir/navigation
```

---------
2023-05-28 10:29:00 -07:00
JJ Kasper
a3ab542630
Add new build and test workflow (#50436)
This adds new `build and test` and `build and deploy` workflows in favor
of the existing massive `build, test, and deploy` workflow. Since the
new workflows will use `pull_request_target` this waits to remove the
existing workflow until the new one is tested.

While testing this new workflow flakey behavior in tests have also been
addressed. Along with the new workflow we will also be leveraging new
runners which allow us to run tests against the production binary of
`next-swc` so this avoids slight differences in tests we've seen due to
running against the dev binary.

Furthermore we will have a new flow for allowing workflow runs on PRs
from external forks which will either require a comment be checking a
box approving the run after each change or a label added by the team.

The new flow also no longer relies on `actions/cache` or similar which
have proven to be pretty unreliable.

Tests runs with the new workflow can be seen here
https://github.com/vercel/next.js/actions/runs/5100673508/jobs/9169416949
2023-05-27 21:02:31 -07:00
Steven
68b34de96e
fix: edge runtime with next/legacy/image (#50343)
- Fixes https://github.com/vercel/next.js/issues/50307
- Related to https://github.com/vercel/next.js/pull/45601

fix #50307
fix NEXT-1237
2023-05-26 13:38:10 +02:00
Jiachi Liu
5831d0c124
Fix static metadata routes runtime when root layout is in edge runtime (#50351)
Since the static metadata routes should always be static that can be
optimized, they should be marked as default runtime (or basically no
runtime). This PR change the runtime detection, if it's a static
metadata route file, its runtime will be erased.

So that it won't be picked up by `edge-app-route-loader` and then by
`next-image-loader` which emits the unexpected static file

Fixes NEXT-1238
2023-05-25 15:39:57 -07:00
Shu Ding
592f592b07
Fix SWC loader options for files outside of RSC layers (#50341)
The React Server Component transform of SWC shouldn't be enabled for
files that are not part of "app layers", for example middleware.
2023-05-25 19:49:26 +02:00
Shu Ding
25ce787d76
Fix missing error when using Actions on the client layer without enabling the feature flag (#50257)
If using Server Actions on the client layer without enabling the
`serverActions` feature, the build should error. Add a test case to
ensure #50199 works.
2023-05-25 14:22:27 +02:00
Jiachi Liu
8725b6c376
Add missing react-dom/client alias (#50324)
Fixes #50312
fix NEXT-1235
2023-05-25 12:10:02 +00:00
JJ Kasper
3c67583405
Fix middleware e2e deploy test (#50317)
`default` isn't a valid `region` at this point so this removes that.

Fixes:
https://github.com/vercel/next.js/actions/runs/5076047750/jobs/9118043860#step:6:469
2023-05-24 23:50:06 -07:00
JJ Kasper
e09efd5e5c
land: Include charset=utf-8 with x-component Content-Type header (#50314)
Lands https://github.com/vercel/next.js/pull/50060 with lint fixes and
updated tests.

Closes: https://github.com/vercel/next.js/pull/50060

---------

Co-authored-by: Leah Lundqvist <leah@pigeon.sh>
2023-05-24 21:05:12 -07:00
JJ Kasper
027aa72f47
Fix catch-all edge app route (#50313)
This ensures we properly normalize app pages in the `web-server` so that
it doesn't fail to match/interpolate properly.

Fixes: https://github.com/vercel/next.js/issues/43384
2023-05-24 20:30:54 -07:00
Jiachi Liu
1079c10064
Alias next/server for edge runtime (#50268)
* For edge runtime, map `next/server` to esm assets to get benefit from
tree-shaking
* Mark process.turbo flag as `false` when running with webpack

Closes NEXT-1212

Compare with canary (13.4.4-canary.8)

#### Middleware

##### before vs after
<img width="319" alt="image"
src="https://github.com/vercel/next.js/assets/4800338/ffa3e744-8f14-4c61-9f5a-ccd04b8911f2">
<img width="317" alt="image"
src="https://github.com/vercel/next.js/assets/4800338/fc974a39-49f3-439a-966c-07af3c71db05">



#### Edge route

##### before vs after
<img width="313" alt="image"
src="https://github.com/vercel/next.js/assets/4800338/bea6e7bb-5875-4a6b-899f-94ad6a8df902">

<img width="314" alt="image"
src="https://github.com/vercel/next.js/assets/4800338/1783fb03-b473-496a-bb97-fa613fe58d7a">
2023-05-24 15:34:29 -07:00
Javi Velasco
aa91de56ce
Remove static analysis of process.env (#50260)
Since there is no longer a limitation that requires us to static analyze
`process.env`, this PR removes it from the build process and updates the
corresponding documentation.
2023-05-24 08:19:02 -07:00
Donny/강동윤
fcfd63065b
feat(next-swc): Add CJS optimizer again (#50249)
### What?

This reverts commit 6ebc725fe6 / #50247.

### Why?

#49972 is reverted due to bugs, and I'm retrying it.

### How?

Closes WEB-1072
Closes WEB-1097
Closes NEXT-1156 (as it's reopened by the revert PR)

fix #48469

---------

Co-authored-by: Shu Ding <g@shud.in>
2023-05-24 09:38:31 +02:00
JJ Kasper
20b19b5ef4
Fix metadata e2e deploy test (#50252)
x-ref:
https://github.com/vercel/next.js/actions/runs/5061340215/jobs/9085634641#step:6:368
2023-05-23 23:04:31 -07:00
JJ Kasper
6ebc725fe6
Revert "feat(next-swc): Implement CJS optimizer" (#50247)
This seems to be failing with the WASM builds so this reverts to allow
further investigation

x-ref:
https://github.com/vercel/next.js/actions/runs/5062818601/jobs/9088828339
x-ref:
https://github.com/vercel/next.js/actions/runs/5061364458/jobs/9085596546
x-ref:
https://github.com/vercel/next.js/actions/runs/5062868910/jobs/9092170727

Reverts vercel/next.js#49972
2023-05-23 21:45:37 -07:00
Jiachi Liu
130fe65bde
Fix alias for react-dom/server (#50238)
A bad alias was introduced in #50128

Fixes #50225
2023-05-23 16:00:59 -07:00
Donny/강동윤
ec8bf53907
feat(next-swc): Implement CJS optimizer (#49972)
### What?


Implement a CJS optimizer for next-swc


### Why?

x-ref: https://vercel.slack.com/archives/C02HY34AKME/p1684341093462309

Assuming most CJS files are transpiled from ESM, we can mimic
tree-shaking using an AST transform.

### How?

Closes WEB-1072
Fixes #48469


fix NEXT-1156

---------

Co-authored-by: Shu Ding <g@shud.in>
2023-05-23 21:38:07 +02:00
Tim Neutkens
eba9e39ea4
Ensure NEXT_DYNAMIC_NO_SSR_CODE has a unique name (#50219)
## What?

Ensures `NEXT_DYNAMIC_NO_SSR_CODE` has a unique error code value, this
accidentally had the value for dynamic server usage (e.g. calling
cookies()) which caused the warning to be shown as shown in #48442.

## How?

Changed the digest value to something unique.


Fixes NEXT-1125
Fixes #48442

<!-- 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-05-23 08:37:57 -07:00
Jiachi Liu
6f2e140037
Fix pages react alias (#50128)
Fix react and react-dom aliases are not properly set for `pages/`

* Remove alias react-dom internals to `{}` in edge runtime as we're using server rendering stub as alias
* Add `react$`, `react-dom$` missing aliases
* Only apply alias to builtin react/react-dom when it's app dir assets.
* Add `react|react-dom/package.json` resolving to require-hook
* Fix hmr issue that sometimes it will perform a reload when a hard navigation is triggered
2023-05-22 23:37:27 +00:00
JJ Kasper
f4bb4aa73c
Fix react fetch deduping without next cache (#50187)
This ensures we don't reference the wrong fetch global bypassing react's
patched fetch so that it can properly fallback to react's fetch deduping
when next cache is disabled for a specific fetch.

x-ref: [slack
thread](https://vercel.slack.com/archives/C042LHPJ1NX/p1684518670927189?thread_ts=1682974724.765039&cid=C042LHPJ1NX)
fixes: https://github.com/vercel/next.js/issues/50031
2023-05-22 16:13:02 -07:00
JJ Kasper
a1633948ad
Add warning for edge with force-static (#50182)
Currently the edge runtime does not support static generation so this adds a warning when `force-static` is leveraged with `edge-runtime` as it will cause unexpected behavior. Support is being investigated so this isn't a hard error at the moment. 

x-ref: [slack thread](https://vercel.slack.com/archives/C03S8ED1DKM/p1684783403551589)
2023-05-22 20:54:15 +00:00
Tim Neutkens
21e677e95b
Failing tests for 404 back/forward (#50047)
## What?

After landing #49855 I found a few more edge cases with not-found not
behaving as expected:
- When navigating directly to a not-found page (e.g. `/testabc`) the
error boundary would not reset as there were multiple levels being
triggered at the same time.
- When running in production navigating back/forward to the not found
page caused the page to become empty

Both issues are fixed by this PR. I've added tests for both.

## How?

- Ensures `asNotFound` is not set on the layout-router, it causes all
levels to trigger not-found, even though only app-router needs it
- Ensures navigations to 404 are always a mpaNavigation (browser
navigation) instead of trying to do a client-side navigation (mirrors
what we do in `pages`)

Fixes NEXT-1209
Fixes NEXT-1218
Fixes #49823

<!-- 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-05-22 17:04:36 +02:00
Jiachi Liu
7450ab41df
test: disable cache flaky test (#50064)
x-ref: https://github.com/vercel/next.js/actions/runs/5026701083/jobs/9015343205?pr=50059
x-ref: https://github.com/vercel/next.js/actions/runs/5018835183/jobs/8998764611?pr=49965#step:6:5579
2023-05-19 21:19:56 +00:00
Jiachi Liu
702eb17638
Fix client references extraction of CJS exports analysis (#50059)
client refs are not correctly extracted as we're using regex to get the exports names from cjs file. The regex was extracting some bad names from the code source, this PR fixes the regex to make sure they extract the correct content

Fixes NEXT-1213
2023-05-19 19:42:46 +00:00
Shu Ding
d381d581cf
Fix types of cookies() (#50052)
As explained in the comments, the `cookies()` API is a mix of request and response cookies. For `.get()` methods, we want to return the request cookie if it exists. For mutative methods like `.set()`, we return the response cookie type instead.
fix #50049
fix NEXT-1211
2023-05-19 19:02:16 +00:00
Shu Ding
26ea9c6333
Always defer close tags to be the suffix of body stream (#50056)
Currently the suffix logic is for pages so nothing happens in app dir. This PR changes it to **always** apply the `createSuffixStream(closeTag)` transform, to defer `</body></html>` to the end of the stream.
fix #48372
fix NEXT-1200
2023-05-19 18:25:04 +00:00
Jiachi Liu
f0d0811a42
Fix default metadata is missing in root not-found (#50044)
* Adding default metadata to root not found under root layout
* Refactor the tests a bit, previously it only checks if the text existed in html, it actually exisits in flight response

Fixes #49979
Closes NEXT-1207
2023-05-19 17:50:03 +00:00
Jiachi Liu
0800ea7eec
Error in next export when serverActions is enabled (#50039)
Reland #49959 as it was reverted in #50019

* Only error when runing `next export` or `output` is "export"
* Add e2e test


Closes NEXT-634
2023-05-19 17:53:21 +02:00
Shu Ding
771141dcc9
Server Actions: Fix member expr in closure captured values (#50020)
For static member expressions like `foo.bar`, we currently treat it as one whole Ident `foo.bar` and pass it over the `$$bound` array as one value. That causes a problem where the Ident inside the function body needs to be converted, because it can no longer access to `foo`.

Closes #49985. 
fix NEXT-1206
2023-05-19 15:05:59 +00:00
Steven
4b4925f4e8
fix: set cookies followed by redirect() (#49965)
- Fixes #49237 


fix NEXT-1120

Co-authored-by: Wyatt Johnson <633002+wyattjoh@users.noreply.github.com>
2023-05-19 00:17:19 +00:00
Tim Neutkens
c2da56e194
Fix going back to page after applying hash link (#50006)
## What?

@steven-tey noticed that on upstash.com that scrolling to hash keeps
happening regardless of the hash being set:

- Open site
- Click `Pricing` which adds `#pricing` and scrolls to the
`id="pricing"`
- Click `About` 
- Click on the logo

You'll notice that navigating back to the homepage ends up scrolling to
the `id="pricing` instead of to the top of the page.

## How?

This happened because we didn't reset the `hashFragment` and
`segmentPaths` for scrolling when scroll was applied, which means it
would keep that value in the state and would be applied as such on
navigation.

This PR ensures that besides setting `apply` to `false` we also reset
the `hashFragment` and `segmentPaths`.

Fixes NEXT-1205

<!-- 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-05-18 16:33:58 -07:00
Steven
783acc59a0
fix: warning fetch for [object Request] specified (#50003)
This PR fixes a warning that previous looked like the following:

```
Warning: fetch for [object Request] specified "cache: default" and "revalidate: 60", only one should be specified.
```
2023-05-18 23:20:05 +00:00
Tim Neutkens
babe50364e
Reset not-found and error boundary when navigating (#49855)
## What?

Currently the error boundary state does not reset when a navigation
happens because the `key` does not change. Because of that navigating
using next/link when the error boundary is in the open state ends up not
rendering the contents of the new navigation, instead it keeps the error
boundary contents.

## How?

This PR uses a pattern that is recommended in the React docs (setState
during render) to reset the error boundary if the `usePathname` value
has changed, it is used as a proxy for a new navigation.

Fixes #47862
Fixes NEXT-963
Fixes #49736
Fixes #49732
Fixes #49599


<!-- 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-05-18 22:06:57 +02:00
Jiachi Liu
7641278f82
Fix port value for metadataBase (#49924)
metadataBase is using `process.env.PORT` to construct a host when there's no `metadataBase` specified in layout. Dev server needs to pass down the PORT env from the parent prcoess.

Fixes #49807
Fixes #49859
Closes #49889
2023-05-17 13:37:47 +00:00
Shu Ding
4970811c5d
Fix chained .bind of Server Actions (#49874)
This makes sure that you can `.bind` a Server Action multiple times. Thanks to the feedback from @sophiebits:  https://github.com/vercel/next.js/pull/49422#pullrequestreview-1419134304
2023-05-16 22:36:17 +00:00
Shu Ding
05a9e0ac49
Fix conflict when re-exporting multiple Client References (#49468)
Closes #49324. Default export should only be added in the loader
generated boundary file when it actually exists.

fix NEXT-1112
2023-05-16 12:35:12 +02:00
Lee Robinson
fa1370fd9b
Update links from beta to stable docs. (#49349)
Now that the beta docs have been merged into stable with the release of
13.4, this updates all links as some paths have changed due to
redirects.

---------

Co-authored-by: Steven <steven@ceriously.com>
Co-authored-by: Tobias Koppers <tobias.koppers@googlemail.com>
Co-authored-by: JJ Kasper <jj@jjsweb.site>
2023-05-11 11:52:29 -07:00
JJ Kasper
ec6cdb3987
Update flakey app-actions deploy tests (#49667)
We'll need to investigate these flakes more but skipping so other tests
can run properly.

x-ref:
https://github.com/vercel/next.js/actions/runs/4944133723/jobs/8839614011
2023-05-11 09:16:15 -07:00
Jimmy Lai
02d020c459
actions: fill prefetchCache with revalidation payload (#49576)
This fixes a bug where the revalidation value was not stored into the
prefetch cache, leading you to potentially see stale value when
re-reading from the prefetch cache.

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

## For Contributors

### Improving Documentation or adding/fixing Examples

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

### Fixing a bug

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

### Adding a feature

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



## For Maintainers

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

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

link NEXT-1134

Co-authored-by: Tobias Koppers <tobias.koppers@googlemail.com>
2023-05-11 11:38:19 +02:00
Jimmy Lai
85c2921bf5
app-router: add support for parallel routes in useParams (#49595)
This PR changes `useParams` to return all dynamic params present in the
tree as opposed to only those on the canonical/URL path


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

## For Contributors

### Improving Documentation or adding/fixing Examples

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

### Fixing a bug

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

### Adding a feature

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



## For Maintainers

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

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

link NEXT-1108

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
2023-05-11 10:32:41 +02:00
JJ Kasper
bc4515d8b6
Ensure initialHeaders are normalized (#49643)
This makes sure we have the initial headers in the correct shape during
build.

Fixes: https://github.com/vercel/next.js/issues/49374
2023-05-10 21:44:11 -07:00
Jimmy Lai
e6d50ec6b4
interception routes: fix rewrites order (#49615)
This PR fixes an issue where the rewrites were applied too early and
thus not working with other beforeFiles rewrites

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

## For Contributors

### Improving Documentation or adding/fixing Examples

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

### Fixing a bug

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

### Adding a feature

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



## For Maintainers

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

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

link NEXT-1148

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2023-05-10 21:07:34 -07:00
JJ Kasper
2eeb1c1bd1
Fix fetchCache and no-store handling (#49638)
Follow-up to https://github.com/vercel/next.js/pull/49628 this updates
the `export const fetchCache` handling and `cache: 'no-store'` handling
as discussed which also aligns with our docs here
https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config#fetchcache

- `export const fetchCache = 'force-cache'`: forces all fetches to be
cached regardless of `cache: 'no-store'` but cacheable `revalidate`
values still take priority
- `export const fetchCache = 'default-cache'`: ensures fetches are
cached even if they come after a `cache: 'no-store'` fetch but don't
override `cache: 'no-store'` itself.
- without `export const fetchCache`, we still disable fetch cache for
successive fetches after a fetch that does `cache: 'no-store'`

x-ref: [slack
thread](https://vercel.slack.com/archives/C03KAR5DCKC/p1683732826894469)
2023-05-10 20:42:25 -07:00
JJ Kasper
ce746ef5c2
Handle unstable_cache in pages (#49624)
Ensures this method works in pages the same as in app as discussed. 

x-ref: [slack
thread](https://vercel.slack.com/archives/C042LHPJ1NX/p1683242040712889)
x-ref: [slack
thread](https://vercel.slack.com/archives/C042LHPJ1NX/p1683724596461329)
2023-05-10 13:59:48 -07:00
Jimmy Lai
824c7fdb4a
actions: make cookies.set revalidate (#49582)
This PR adds revalidation for the current page you're on when you call
cookies.set.

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

## For Contributors

### Improving Documentation or adding/fixing Examples

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

### Fixing a bug

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

### Adding a feature

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



## For Maintainers

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

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

link NEXT-1097
2023-05-10 17:29:54 +02:00
Jiachi Liu
ef2b8f8696
Fix canonical url for dynamic routes (#49512)
The `pathname` in app-render was actually "page" (e.g. `/blog/[slug]`),
with special url conventions. Instead we should use actual request url
as pathname. Rename previous `pathname` arg to `pagePath` for better
readability

Also improved the url validation
2023-05-09 16:31:06 -07:00
Steven
064e0c25d7
chore: fix flaky middleware matcher test (#49555)
```
    ✕ should match query path (2857 ms)

  ● Middleware custom matchers basePath › should match query path

    expect(received).toBe(expected) // Object.is equality

    Expected: "random"
    Received: ""
```

https://github.com/vercel/next.js/actions/runs/4929337370/jobs/8809028722?pr=49529#step:6:201
2023-05-09 22:37:03 +00:00
Shu Ding
000d022b4e
Support .bind syntax with Action functions (#49422)
This PR implements initial support for `.bind` syntax for inline actions
(not top-level `"use server"` files yet). For example:

```js
export default function Page({ foo, x, y }) {
  async function action(a, b, c, d) {
    'use server'
    console.log(a, b, c, d)
  }

  return <ClientComp action={action.bind(null, foo[0], foo[1], foo.x, foo[y])} />
}
```

Is now valid.

Fixes NEXT-1109.
2023-05-09 19:05:20 +02:00
Shu Ding
d9b82a9535
Fix HMR support for server layer imported SASS and SCSS (#49534)
Closes #43396.

https://github.com/vercel/next.js/issues/43396#issuecomment-1538638785
fix NEXT-684
2023-05-09 16:28:37 +00:00
Shu Ding
881d202962
Fix server CSS imports and HMR not working properly in specific conditions (#49462)
In Hot Reloader we use `mod.resource.replace(/\\/g, '/').includes(key)`
to see if the module is the entry. However that `includes` check isn't
solid. Say the entry key is `app/path/page`, these will all be matched:

```
app/path/page.js
app/path/page.css
app/unrelated/app/path/page/another/page.js
```

This PR fixes that and added a test case. I'm unsure if this fixes the
newly reported cases in #43396.

fix NEXT-1110
2023-05-09 17:48:19 +02:00
Darsh Patel
81f5ed7aa2
Fix: Router.query contains _next when using middleware with dynamic routes (#48753)
Fixes: #43598

This was a tricky one to find! Not sure why more people aren't
complaining about this issue, was super annoying in my use case since
links had the wrong URL.

## What?
This issue only occurred when basepath was defined and middleware and
dynamic pages are being used.
Example from the reproduction repo mentioned in the issue tagged:
<img width="686" alt="Screenshot 2023-04-23 at 9 32 55 PM"
src="https://user-images.githubusercontent.com/11258286/233850968-e14f6b49-858b-410e-b8f9-93c90447090a.png">


## Why?
`nextConfig` wasn't passed to `getNextPathnameInfo` function, hence the
basePath wasn't removed from a intermediate variable and that trickled
down to cause this issue.

Added test case based on the issue reproduction repo

---------

Co-authored-by: Jimmy Lai <laijimmy0@gmail.com>
2023-05-09 12:49:27 +02:00
Shu Ding
761c293093
Add test case for #49235 (#49488)
This PR adds a test case for `headers()` and `cookies().set()` in Client
Component imported actions.
2023-05-09 11:17:44 +02:00
Jiachi Liu
4171cf3866
test: pages react version with react hook in deployment (#48907)
testing react version in pages for deployment env
2023-05-09 11:16:56 +02:00
JJ Kasper
04799216ec
Fix failing actions e2e deploy test (#49497)
x-ref:
https://github.com/vercel/next.js/actions/runs/4921305860/jobs/8791173036
2023-05-08 21:09:42 -07:00
JJ Kasper
71d354363e
Fix external rewrite with body (#49487)
This ensures we use the proper body stream when rewriting to an external
resource as currently it tries to consume an already read body stream.

Fixes: https://github.com/vercel/next.js/issues/48040
2023-05-08 15:22:02 -07:00
Jiachi Liu
b20d5f2df7
Fix metadata image route encoding (#49482)
Fix the bad encoded buffer introduced in #49323
2023-05-08 14:16:34 -07:00
JJ Kasper
00ed2ba7cc
Fix revalidate: false detection in app (#49473)
When revalidate isn't defined in the tree at all and a fetch without
cache/revalidate fields is done we are incorrectly marking the initial
revalidate period with a time based value when it should be `false`.
This causes pages that should be fully static to revalidate
unexpectedly.

x-ref: [twitter
thread](https://twitter.com/diegohaz/status/1655638433795014657)
x-ref: [slack
thread](https://vercel.slack.com/archives/C03S8ED1DKM/p1683566860136879)
2023-05-08 13:19:41 -07:00
Jiachi Liu
5b5c4c3209
Replace metadata clone with custom handler in dev (#49343) 2023-05-08 20:47:41 +02:00
Jiachi Liu
96c7acf6ad
Inline static data buffer instead of using fs read (#49323) 2023-05-08 16:20:44 +02:00
Shu Ding
ef8fef1350
Fix link not being GC'd sometimes (#49318)
The `app-link-gc` module should treat the link with just pathname as the
href and full URL as the same resource. This avoids duplicate styles
during HMR:

<img width="482" alt="CleanShot 2023-05-05 at 18 12 12@2x"
src="https://user-images.githubusercontent.com/3676859/236511257-af510ed2-8e21-430a-bf71-24931b10e5de.png">

[Related bug report
(internal)](https://vercel.slack.com/archives/C03KAR5DCKC/p1683295788069859).
2023-05-05 20:23:35 +02:00
Shu Ding
9bd00a8896
Add test case for client sourcemaps (#49308)
This PR adds a test case to ensure that the server reference doesn't expose actual content of the original file in its sourcemap.

Closes NEXT-1041.
2023-05-05 14:23:04 +00:00
Tim Neutkens
25a9547cad
Remove experimental config from create-next-app (#49241)
## What?

Removes `experimental.appDir` this was leftover from when I flipped the
switch.

Kept the config file as in the future we might add future flags and
such. It also helps that it has the types comment included so you always
get types.

<!-- 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-05-05 00:22:28 -07:00
Shu Ding
bf49f62cda
Fix Server Actions defined in both layers in one entry (#49248)
This fixes an existing bug where there're Server Actions defined in both the "server" and "client" layers (client imported Actions). They have the same worker name as they exist in one route entry, but they're built into different modules and compiled differently (server and client layers). Because of that, each route entry can have 2 "action module entries".

This PR adds the logic to differentiate that via a "layer" field so they don't conflict.
2023-05-04 21:25:21 +00:00
Jiachi Liu
7fa4946b42
Apply basePath for metadata image (#49226)
Fixes #49162

When user configures the `basePath` in `next.config.js`, we need to
apply it to metadata image path resolving
fix NEXT-1087
2023-05-04 12:50:13 -07:00
JJ Kasper
30f84e31b4
Update dev logs to include request timings (#49191)
This updates our dev logs to include request timings and also includes
fetch timings in app directory to including info on whether the cache
was leveraged or not allowing easier debugging of contributing factors
to render times. In the future we can expand to include middleware
timings separate as well to single that out along with timings for
`getStaticProps` potentially as well.


<details>

<summary>Screenshot</summary>

![CleanShot 2023-05-04 at 00 13
19@2x](https://user-images.githubusercontent.com/22380829/236135624-da1d873b-5abf-42d0-9708-8e20d1c56cef.png)

</details>

<details>

<summary>Screenshot</summary>

![CleanShot 2023-05-04 at 00 13
32@2x](https://user-images.githubusercontent.com/22380829/236135642-bc974b82-13e0-47f0-8be5-581d92077fc1.png)

</details>

<details>

<summary>Screenshot</summary>

![CleanShot 2023-05-04 at 00 13
47@2x](https://user-images.githubusercontent.com/22380829/236135664-5b2975ce-fa78-40d5-b320-d42d35b17541.png)

</details>

x-ref: [slack
thread](https://vercel.slack.com/archives/C042LHPJ1NX/p1681418590738249)
2023-05-04 12:33:03 -07:00
Tim Neutkens
fe15a42077
Enable App Router for all applications (#49088)
Co-authored-by: Jimmy Lai <laijimmy0@gmail.com>
Co-authored-by: Shu Ding <g@shud.in>
2023-05-04 17:47:10 +02:00
Jiachi Liu
ab55764742
test: temporary disable flaky checking (#49217)
x-ref:
https://github.com/vercel/next.js/actions/runs/4883632043/jobs/8715611946
2023-05-04 17:28:55 +02:00
Jimmy Lai
51e51d25d6
action: support not found (#49209)
<!-- 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-05-04 15:59:24 +02:00
Jimmy Lai
aec49ec65d
actions: fix redirect on the edge (#49197)
- enables redirect for the edge
- enables production tests



link NEXT-1086
2023-05-04 11:32:50 +00:00
Jiachi Liu
bf09c65e53
Allow override icon rel (#49194)
Fixes #48392

When passing down `Array<IconDescriptor>`, it should allow overriding `rel` prop of icon instead of always picking the default one
fix NEXT-1085
2023-05-04 09:03:57 +00:00
Jiachi Liu
7fd97b8b32
Add warning for missing metadataBase in social images (#49180)
We picked `VERCEL_URL` env for `metadataBase` in preview mode, but also picking that on production, this could potentially use the unique build url for social images if you didn't set `metadataBase`

We recommend to set the major/preferred domain to `metadataBase` if you're using social images, this PR help warn you in every env if you're missing that

[slack thread](https://vercel.slack.com/archives/C03KAR5DCKC/p1683150633962539?thread_ts=1683144147.664059&cid=C03KAR5DCKC)
2023-05-04 08:17:00 +00:00
Sebastian Markbåge
b877de1442
Enable progressive enhanced form actions through decodeAction (#49187)
This uses the new built-in progressive enhancement features of React.
These always use `multipart/form-data` atm. When one comes in that's not
a fetch, we can use `decodeAction` to get a resolved function.

This also ensures that we can test this by passing disableJavaScript to
tests. This disables JS for the context.
2023-05-04 05:03:09 +00:00
Shu Ding
83b774eeb6
Fix standalone mode with appDir running in a single process (#49116)
Fixes #49055, fixes #48918. 

App dir will always require the server to run in the workers mode, so it
can keep a separate Node.js process for pages. This PR updates the
standalone server to initialize a "standalone server" (which works
similar to `start-server`), and changes the tracked files to include
Jest worker.
2023-05-04 05:55:05 +02:00
Shu Ding
0aac86ea82
Fix multipart/form-data handling in the Edge runtime (#49177)
Adds proper `multipart/form-data` handling in the Edge runtime and fixes a bug (previously we are always using `serverActionsManifest.node`). For the form data, we just use `await webRequest.request.formData()` for now and will handle streaming later.
2023-05-03 23:59:30 +00:00
Shu Ding
e7a233293a
Fix flaky test (#49178)
Found this one being a bit random during dev, but it's trivial. See discussions: https://github.com/vercel/next.js/pull/49168#issuecomment-1533788373
2023-05-03 23:25:46 +00:00
Jimmy Lai
2dc0ba4bd9
app router: support side effects on server requests (#48939)
<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation or adding/fixing Examples

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

### Fixing a bug

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

### Adding a feature

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



## For Maintainers

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

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

link NEXT-920

---------

Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
2023-05-04 01:01:40 +02:00
Shu Ding
248f2defc2
Fix React channel env missing in custom server (#49168)
Fixes #48948
([repro](https://github.com/vercel/next.js/issues/48948#issuecomment-1533542001)).
When running inside a custom server with app dir, we should always opt
into the prebundled React with correct channels.

Thanks @karlhorky for help testing it!

Fixes #49169 too.

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2023-05-04 00:40:23 +02:00
Andrew Clark
e659653e48
Upgrade React to 18.3.0-canary-b7972822b-20230503 (#49158)
Includes the following upstream changes:

- [b7972822b](https://github.com/facebook/react/commits/b7972822b)
useOptimisticState -> useOptimistic
([#26772](https://github.com/facebook/react/pull/26772)) (Andrew Clark)
- [388686f29](https://github.com/facebook/react/commits/388686f29) Add
"canary" to list of allowed npm dist tags
([#26767](https://github.com/facebook/react/pull/26767)) (Andrew Clark)
- [8a25302c6](https://github.com/facebook/react/commits/8a25302c6)
fix[dynamic-scripts-injection]: unregister content scripts before
registration ([#26765](https://github.com/facebook/react/pull/26765))
(Ruslan Lesiutin)
- [2c2476834](https://github.com/facebook/react/commits/2c2476834)
Rename "next" prerelease channel to "canary"
([#26761](https://github.com/facebook/react/pull/26761)) (Andrew Clark)
- [fa4314841](https://github.com/facebook/react/commits/fa4314841)
Remove deprecated workflow key from Circle config
([#26762](https://github.com/facebook/react/pull/26762)) (Andrew Clark)
- [5dd90c562](https://github.com/facebook/react/commits/5dd90c562) Use
content hash for react-native builds
([#26734](https://github.com/facebook/react/pull/26734)) (Samuel Susla)
- [559e83aeb](https://github.com/facebook/react/commits/559e83aeb)
[Fizz] Allow an action provide a custom set of props to use for
progressive enhancement
([#26749](https://github.com/facebook/react/pull/26749)) (Sebastian
Markbåge)
- [67f4fb021](https://github.com/facebook/react/commits/67f4fb021) Allow
forms to skip hydration of hidden inputs
([#26735](https://github.com/facebook/react/pull/26735)) (Sebastian
Markbåge)
- [8ea96ef84](https://github.com/facebook/react/commits/8ea96ef84)
[Fizz] Encode external fizz runtime into chunks eagerly
([#26752](https://github.com/facebook/react/pull/26752)) (Josh Story)
- [491aec5d6](https://github.com/facebook/react/commits/491aec5d6)
Implement experimental_useOptimisticState
([#26740](https://github.com/facebook/react/pull/26740)) (Andrew Clark)
- [9545e4810](https://github.com/facebook/react/commits/9545e4810) Add
nonce support to bootstrap scripts and external runtime
([#26738](https://github.com/facebook/react/pull/26738)) (Dan Ott)
- [86b0e9199](https://github.com/facebook/react/commits/86b0e9199) Gate
DevTools test to fix CI
([#26742](https://github.com/facebook/react/pull/26742)) (Andrew Clark)
- [b12bea62d](https://github.com/facebook/react/commits/b12bea62d)
Preinits should support a nonce option
([#26744](https://github.com/facebook/react/pull/26744)) (Josh Story)
- [efbd68511](https://github.com/facebook/react/commits/efbd68511)
Remove unused `initialStatus` parameter from `useHostTransitionStatus`
([#26743](https://github.com/facebook/react/pull/26743)) (Sebastian
Silbermann)
- [18282f881](https://github.com/facebook/react/commits/18282f881) Fix:
Update while suspended fails to interrupt
([#26739](https://github.com/facebook/react/pull/26739)) (Andrew Clark)
- [540bab085](https://github.com/facebook/react/commits/540bab085)
Implement experimental_useFormStatus
([#26722](https://github.com/facebook/react/pull/26722)) (Andrew Clark)

---------
2023-05-03 14:03:19 -07:00
JJ Kasper
e4beb85b49
Update cache methods for app dir (#49165)
This ensures we match behavior local and deployed and also cleans up
naming of the methods.

---------
2023-05-03 13:21:58 -07:00
Shu Ding
1e75beada2
Fix CSS module imports not included in root not-found file (#49155)
When using the `not-found.js` file to match missed routes, `serverCSSForEntries` will always be empty as the `ComponentMod.pages` itself doesn't contain any actual entry. We need to handle that as a special case.

Closes #48133.
2023-05-03 16:45:12 +00:00
Jiachi Liu
a623653e16
Forward response to edge runtime for response modification (#49145)
For edge runtime, we're modifying `res.statusCode` in actions handler, but we didn't forward the `res` object to it, previously we're using a fake `res` `{}`. This PR fixes it so that the propery status code will be returned to the client

[slack-thread](https://vercel.slack.com/archives/C052S77L05C/p1682988777740609)
2023-05-03 14:04:31 +00:00
Jiachi Liu
c09b0a0890
Static generate dynamic sitemaps (#49114)
Follow up of #48867 

- Statically optimize dynamic generated sitemap routes
- Previously the generated sitemap urls looks bit off
(`/route/sitemap.xml/[id]`), we polish it into `/route/sitemap/[id].xml`
in this PR
2023-05-03 12:11:57 +02:00
Sophie Alpert
05cd5157e5
app router: Fix infinite redirect loop in MPA navigation (#49058)
Not 100% convinced that this is the correct fix but it's the best I can
think of.

Previously, we would sometimes call location.assign()/.replace()
hundreds of times (or more) as I described in
https://github.com/vercel/next.js/issues/48438 and
https://github.com/vercel/next.js/issues/48309#issuecomment-1512290958.
Sometimes this would just make things slow but the navigation would
eventually succeed; sometimes this would just hang the browser.

Now we trigger it only once (or—for a reason I don't quite
understand—twice in dev, as you can see in the test) and never commit
that render.

This also fixes the bug I mentioned in
https://github.com/vercel/next.js/issues/48438#issuecomment-1528649776
where usePathname() and useSearchParams() would return the page we are
navigating to (even if that's an external page wholly unrelated to our
site!).

Fixes #48309, fixes #48438.

link NEXT-1028

Co-authored-by: Jimmy Lai <laijimmy0@gmail.com>
2023-05-03 11:04:53 +02:00
JJ Kasper
e54e38a5a6
Fix edge runtime detection from layouts (#49126)
This ensures we properly handle edge runtime during build when loading pages as currently we are only check the page itself for the runtime flag although it can be nested higher up but we already have the relevant info in the middleware-manifest so we can use that during build. 


Fixes: 
```sh
info  - Linting and checking validity of types
info  - Collecting page data ..ReferenceError: self is not defined
    at Object.<anonymous> (/Users/jj/dev/vercel/next.js/test/e2e/app-dir/app-edge/.next/server/app/edge/basic/page.js:1:1)
    at Module._compile (node:internal/modules/cjs/loader:1254:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
    at Module.load (node:internal/modules/cjs/loader:1117:32)
    at Module._load (node:internal/modules/cjs/loader:958:12)
    at Module.require (node:internal/modules/cjs/loader:1141:19)
    at require (node:internal/modules/cjs/helpers:110:18)
    at requirePage (/Users/jj/dev/vercel/next.js/packages/next/src/server/require.ts:126:10)
    at <anonymous> (/Users/jj/dev/vercel/next.js/packages/next/src/server/load-components.ts:105:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

> Build error occurred
Error: Failed to collect page data for /edge/basic
```
2023-05-03 08:01:58 +00:00
JJ Kasper
5cae80dbc8
Tweak app cache handling for paths (#49108)
This updates some handling as discussed and cleans up un-necessary
fields from previous PR.

---------
2023-05-02 17:48:59 -07:00
Jiachi Liu
9102771c65
Optimize non-dynamic metadata routes to static in production build (#49109)
* For sitemap if they're not using dynamic routes generation `generateSitemaps`, should optimize them as static sitemap
* For icons and social images, if they're not using `generateImageMetadata`, should optimize them as static path

Closes NEXT-1071
Fixes #48991
2023-05-02 21:36:44 +00:00
Steven
20f90c387c
chore: rename draft mode enabled to isEnabled (#49096)
After trying out draft mode on canary, I realized that it was easy to
select the wrong option from the VS Code intellisense suggestion
dropdown.

So this PR changes `enabled` to `isEnabled` and also wraps in a class to
make the icons for methods look different.

## Before

<img width="545" alt="image"
src="https://user-images.githubusercontent.com/229881/235705729-2be5a5a0-2299-4152-bee7-b6d5659a8d59.png">

## After

<img width="545" alt="image"
src="https://user-images.githubusercontent.com/229881/235733072-338dfb2f-9e27-4d04-b009-a66503efe682.png">
2023-05-02 21:45:28 +02:00
JJ Kasper
abc74fb92e
Update revalidate handling for app (#49062)
This updates revalidate handling for app and moves some exports from
`next/server` to `next/cache`

x-ref: [slack
thread](https://vercel.slack.com/archives/C042LHPJ1NX/p1682535961644979?thread_ts=1682368724.384619&cid=C042LHPJ1NX)

---------
2023-05-02 08:19:02 -07:00
Shu Ding
ee48c66731
Add test case for file uploads (#49048)
This PR adds a test case of handling file inputs in a form.

Fixes NEXT-1062
2023-05-02 14:49:15 +02:00
Steven
e6acd40cba
feat: make enableUndici: true default and remove node-fetch (#49061)
- Closes #49053

Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2023-05-02 04:10:59 +00:00
Steven
58e5c780f3
feat: add draft mode to next/headers (#48789)
fix NEXT-1003

Co-authored-by: Wyatt Johnson <633002+wyattjoh@users.noreply.github.com>
2023-05-01 21:37:17 +00:00
Jimmy Lai
25ba8a74b7
app router: don't unmount/remount on search param changes (#49047) 2023-05-01 20:57:45 +02:00
Shu Ding
905cb5a56b
Rename experimentalReact (#49046)
This PR renames `experimental.experimentalReact` as
`experimental.serverActions` and makes it a hard compilation error if
it's not set but detected server actions.
2023-05-01 20:35:52 +02:00
Shu Ding
d3c59a1147
Fix failing test on canary branch (#49038)
Not sure when it was introduced (this was a warning before), but it's
failing on `canary` right now:
https://github.com/vercel/next.js/actions/runs/4851306015/jobs/8645117315
2023-05-01 15:23:14 +02:00
Tim Neutkens
ec8e0f911f
Ensure app/layout.tsx can export preferredRegion (#49031)
Fixes a small bug where `layout` directly under `app` wasn't considered.
<!-- 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-05-01 11:58:36 +02:00
Shu Ding
97be2e6728
Fix CSS ordering issue with HMR (#49010)
Closes #48807.

The issue seems to be introduced with recent React Float change, which isn't a real problem but a behavior change. Resources are layered by the `precedence` key and the style insertion logic can be simplified as "insert the new stylesheet right after the existing stylesheet in the same layer". When multiple stylesheets are inserted in the same render pass, their new order will be flipped.

This is a nice feature so we can always maintain the order of resources that might conflict.
2023-04-30 20:50:58 +00:00
Tim Neutkens
1d410c808d
Update type of preferredRegion (#49003)
Follow-up to #48959, adds the right types after the renames of
properties.

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

## For Contributors

### Improving Documentation or adding/fixing Examples

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

### Fixing a bug

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

### Adding a feature

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



## For Maintainers

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

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->
2023-04-30 15:21:38 +02:00
Tim Neutkens
905b62e599
Fix scroll when loading.js/ts is used (#48986)
### What?

Whenever you navigated and a page suspended through `loading` or an error happened caught by `error` in the first level of segments (e.g. `/dashboard` but not `/dashboard/settings`) scroll would not be applied. This happened because the focus and scroll handling component is rendered as part of `InnerLayoutRouter` and the Suspense / Error boundary was rendered **around** `InnerLayoutRouter`. This behavior is incorrect as we still want to immediately scroll to the place where the loading is rendered.

This PR fixes the behavior by allowing the scroll to apply to loading / error too.

### How?

Moved the scrolling component around the loading/error/innerlayout boundary and added tests.
2023-04-29 17:43:55 +00:00
Josh Story
4f5f4769e5
preload fonts using ReactDOM.preload (#48931)
This PR updates the way we preload fonts. Previously we tracked which
fonts we needed to preload for each layer and rendered a `<link
rel="preload" href="..." as="font" />` tag for each preloadable font.
This unfortunately gets blocked by data fetching and we want to be able
to hint these preloads as soon as possible. Now that React support Float
methods in RSC we can use `ReactDOM.preload(..., { as: "font" })` to
implement this functionality

This PR makes the following changes
1. expose a `preloadFont` method through the RSC graph
2. expose a `preconnect` metho through the RSC graph
3. refactor the preloads generation to use `preloadFont` instead of
rendering a preload link
4. If there are no fonts to preload but fonts are being used in CSS then
a `preconnect` asset origin is called instead of rendering a preconnect
link
5. instead of emitting a data attribute per font preload indicating
whether the project is using size-adjust we now emit a single global
meta tag. In the future we may get more granular about which fonts are
being size adjusted. In the meantime the current hueristic is to add
`-s` to the filename so it can still be inferred.

In the process of completing this work I discovered there were some bugs
in how the preconnect logic was originally implemented. Previously it
was possible to get multiple preconnects per render. Additionally the
preconnect href was always `"/"` which is not correct if you are hosting
your fonts at a CDN. The refactor fixed both of these issues

I want to do a larger refactor of the asset loading logic in App-Render
but I'll save that for a couple weeks from now

Additionally, the serialized output of preloads now omits the word
anonymous when using crossorigin so tests were updated to reflect
`crossorigin=""`

Additionally, tests were updated to no longer look for the size-adjust
data attribute on preloads

Additionally, There is a note about leaving a `{null}` render in place
to avoid a conflict with how the router models lazy trees. I'll follow
up with a PR addressing this

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2023-04-29 00:50:20 +02:00
Tim Neutkens
799a05ce8f
Support preferredRegion and Support runtime/preferredRegion on layouts (#48959)
### What?

Implements resolving of `runtime` and `preferredRegion` in layouts. It
will resolve from the root layout down, each layout can override
`runtime` or `preferredRegion`.

```
app
├── layout.js -> export const runtime = 'edge'
├── page.js -> Edge runtime
└── dashboard
    ├── page.js -> Edge runtime
    └── settings
        ├── layout.js -> export const runtime = 'nodejs'
        └── page.js -> Node.js runtime
```

Adds support for `preferredRegion`. This is similar to `export const
config = { region: ['sfo1'] }` in `pages`.

However, there is a difference. It supports `export const
preferredRegion = 'home'` and `export const preferredRegion = 'edge'`.
`home` refers to the configured default region on your deployment
platform and `edge` refers to "all regions".

### How?

I've implemented a temporary resolving in `entries.ts`.
`preferredRegion` is tracked through the entry module in webpack which
is why it's added to all the loaders that create an entry module, this
prevents having to resolve/parse again later on.

Fixes NEXT-880
Fixes NEXT-1064
Fixes #48905
Closes #48933
2023-04-28 17:40:34 -05:00
JJ Kasper
7bfd582999
Ensure WebSocket is polyfilled for node runtime as well (#48924)
Follow-up to https://github.com/vercel/next.js/pull/48870 this exposes
WebSocket for the Next.js runtime so we don't have divergence in APIs as
discussed with @cramforce
2023-04-28 15:48:14 -05:00
Jiachi Liu
a141366ff6
Error for missing dynamic generated id and refactor metadata image url (#48953)
### What?

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

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

### Why?

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

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

### How?

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

Closes NEXT-1063

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


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

## For Contributors

### Improving Documentation or adding/fixing Examples

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

### Fixing a bug

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

### Adding a feature

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



## For Maintainers

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

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

---------

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

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

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


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

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

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

---------

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

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

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

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

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

### How?

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

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


Fixes NEXT-1056

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

## For Contributors

### Improving Documentation or adding/fixing Examples

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

### Fixing a bug

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

### Adding a feature

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



## For Maintainers

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

### What?

### Why?

### How?

Closes NEXT-
Fixes #

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

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


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

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

For dynamic routes you might have different sitemap for different params

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

### How

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

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

cc @styfle

---------

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

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

This PR also adds the same support for Custom Routes.

cc @styfle.

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

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

closes ALY-579

---------

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

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

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

## For Contributors

### Improving Documentation or adding/fixing Examples

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

### Fixing a bug

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

### Adding a feature

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



## For Maintainers

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

### What?

### Why?

### How?

Closes NEXT-
Fixes #

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

## Context

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

## This PR

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

## Follow ups

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


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

## For Contributors

### Improving Documentation or adding/fixing Examples

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

### Fixing a bug

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

### Adding a feature

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



## For Maintainers

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

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

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

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

Closes NEXT-426

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

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

## For Contributors

### Improving Documentation or adding/fixing Examples

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

### Fixing a bug

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

### Adding a feature

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



## For Maintainers

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

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

---------

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

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

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

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

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

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

and then you changed it to:

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

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

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


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

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

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

Follow up for #47910

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

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

---

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

---------

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

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

Add a warning if the legacy usage is detectd

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

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

### Why?

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

Previously we defined the component segment as

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

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

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

### How?

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

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

fix NEXT-656

---------

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

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

<!-- 

## For Contributors

### Improving Documentation or adding/fixing Examples

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

### Fixing a bug

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

### Adding a feature

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



## For Maintainers

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

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

fix #48122
link NEXT-1020

---------

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

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

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

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

## For Contributors

### Improving Documentation or adding/fixing Examples

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

### Fixing a bug

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

### Adding a feature

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



## For Maintainers

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

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

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

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

## For Contributors

### Improving Documentation or adding/fixing Examples

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

### Fixing a bug

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

### Adding a feature

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



## For Maintainers

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

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

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

## For Contributors

### Improving Documentation or adding/fixing Examples

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

### Fixing a bug

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

### Adding a feature

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



## For Maintainers

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

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

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

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

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

## For Contributors

### Improving Documentation or adding/fixing Examples

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

### Fixing a bug

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

### Adding a feature

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



## For Maintainers

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

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

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

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

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

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

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

### How?

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

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

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

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

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

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

---------

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

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

### How?

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

Fixes NEXT-997

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

## For Contributors

### Improving Documentation or adding/fixing Examples

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

### Fixing a bug

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

### Adding a feature

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



## For Maintainers

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

### What?

### Why?

### How?

Closes NEXT-
Fixes #

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

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

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

## For Contributors

### Improving Documentation or adding/fixing Examples

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

### Fixing a bug

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

### Adding a feature

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



## For Maintainers

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

### What?

### Why?

### How?

Closes NEXT-
Fixes #

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

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

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


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

## For Contributors

### Improving Documentation or adding/fixing Examples

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

### Fixing a bug

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

### Adding a feature

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



## For Maintainers

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

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

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

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

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

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

Closes NEXT-990

### Why

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

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

## For Contributors

### Improving Documentation or adding/fixing Examples

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

### Fixing a bug

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

### Adding a feature

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



## For Maintainers

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

### What?

### Why?

### How?

Closes NEXT-
Fixes #

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

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

### Why?

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

### How?

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

---------

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

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


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

## For Contributors

### Improving Documentation or adding/fixing Examples

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

### Fixing a bug

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

### Adding a feature

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



## For Maintainers

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

### What?

### Why?

### How?

Closes NEXT-
Fixes #

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

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

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

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

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

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

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

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

## For Contributors

### Improving Documentation or adding/fixing Examples

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

### Fixing a bug

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

### Adding a feature

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



## For Maintainers

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

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

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

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

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

fixes NEXT-971

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

## For Contributors

### Improving Documentation or adding/fixing Examples

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

### Fixing a bug

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

### Adding a feature

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



## For Maintainers

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

### What?

### Why?

### How?

Closes NEXT-
Fixes #

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

---------

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

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

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

fix NEXT-926

---

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

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

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

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

### Why?

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

### How?

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

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

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

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

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

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

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

### Why?

See example

Closes NEXT-966
Fixes #


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

## For Contributors

### Improving Documentation or adding/fixing Examples

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

### Fixing a bug

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

### Adding a feature

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



## For Maintainers

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

### What?

### Why?

### How?

Closes NEXT-
Fixes #

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

x-ref: https://twitter.com/simonecervini/status/1644123851003928579
2023-04-06 17:52:24 -07:00