Commit graph

1216 commits

Author SHA1 Message Date
Wyatt Johnson
e23dac0cbf
fix: added support for tests to add resolutions for deps (#55398)
Some tests may depend on `latest` to help us catch problems earlier. This adds support for the `resolutions` field for tests to allow pinning of deps that may be problematic upstream.
2023-09-14 17:35:13 +00:00
Jiachi Liu
14e94e69c5
fix duplicated error logging when start server (#55328)
There're few places calling `loadConfig` to access nextjs config for different purpose, and every of them will do validation of next config scheme and could log the warnings potentially to cause duplicated warnings. To address that issue this PR limit the places when should the warnings be logged in certain places, mainly the `next` command entry. Refactor the API here to make it more explicit

Previous logging redeisgn also might trigger duplicated compilation, for instance you compiled page A but then editing another component it might still displaying page A is recompiled. Now we always display `"Compiled .."` message when there's a recompilation but avoid the unnecessary ones such as initial edge compilor ready but there's no modules inside. Then when it recompiles or recovers from error nextjs server will tell "Compiled .." instead of the specific page which might be not related.

Also refactors a minor issue: When `silent` option is set to `true`, auto recorrect next config option from `loadConfig` API like `traillingSlash` is not working

Closes NEXT-1610

Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2023-09-13 22:25:41 +00:00
Jimmy Lai
f4e6dea1f2
build: fix externals resolution when importing from next/dist (#55269)
This fixes a "bug" where Sentry was trying to access some of the internal async storages and it would fail because their imports would be compiled as-is instead of using the special rules for Next externals as we are short-cutting it for `next/dist` requests for some reason.

Not a bug per se because this is technically an undocumented API but I think it's a reasonable fix since we don't provide an API for that. The alternative for them would be to try to play around with the bundling, which is not a good use of anyone's time.
2023-09-12 10:26:34 +00:00
JJ Kasper
7d93808c43
Remove render workers in favor of esm loader (#54813)
Currently we create separate workers to isolate `pages` and `app`
routers due to differing react versions being used between the two. This
adds overhead and complexity in the rendering process which we can avoid
by leveraging an `esm-loader` similar to our `require-hook` to properly
alias `pages` router to the bundled react version to match `app` router
when both are leveraged together.

This aims to seamlessly inject the `esm-loader` by restarting the
process with the loader arg added whenever `next` is imported so that
this also works with custom-servers and fixes the issue with custom
req/res fields not working after upgrading.


x-ref: https://github.com/vercel/next.js/issues/53883
x-ref: https://github.com/vercel/next.js/issues/54288
x-ref: https://github.com/vercel/next.js/issues/54129
x-ref: https://github.com/vercel/next.js/issues/54435
closes: https://github.com/vercel/next.js/issues/54440
closes: https://github.com/vercel/next.js/issues/52702
x-ref: [slack
thread](https://vercel.slack.com/archives/C03KAR5DCKC/p1693348443932499?thread_ts=1693275196.347509&cid=C03KAR5DCKC)

---------

Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
Co-authored-by: Zack Tanner <zacktanner@gmail.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2023-09-11 22:17:52 +02:00
Will Binns-Smith
8f30255922
Revert swc versions to one that doesn't use lightningcss (#55148)
Using lightningcss results in a breaking change to Next.js, so let's revert swc for now.


Closes WEB-1526
2023-09-08 20:02:51 +00:00
Jimmy Lai
5217e7eb06
server: re-land bundled runtimes (#55139)
see https://github.com/vercel/next.js/pull/52997

also added a fix by @jridgewell to fix turbopack





Co-authored-by: Justin Ridgewell <112982+jridgewell@users.noreply.github.com>
2023-09-08 16:05:29 +00:00
Vũ Văn Dũng
f47c409174
Check for type of route handler returned value at build time (via the TS plugin) and at runtime (#51394)
### What?

Fixes #51130. Before this PR, the package assumes that route handlers return a `Response` which is not necessarily the case.

The linked issue specified three suggestions to resolve this

1. Return a default 200 response
2. Throw a better error message
3. or both

~~In this issue I implemented (3), except that it is a warning and not an error. Do tell if the team wants to follow a different approach, as it is not too hard to change this.~~

This PR implements (2).

### How?

The returned value of the handler is checked at runtime to ensure it is actually a `Response` instance.

The return type `AppRouteHandlerFn` is also modified to `unknown` to avoid similar assumptions elsewhere.

The TS plugin is also modified to check for the return type during build time.



Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2023-09-08 03:26:53 +00:00
Jiachi Liu
6ffb8dafbd
Reenable app-static usePathname tests (#55065)
Re-enable `usePathname` related tests

Closes NEXT-112
2023-09-08 00:30:41 +00:00
Jiachi Liu
60d3ab3e47
Filter out pages tree view for app dir only output (#55120)
Only output app routes if there's no pages routes in next build output


For hello world app you'll only see app dir routes
```
Route (app)                              Size     First Load JS
+ First Load JS shared by all            78.1 kB
  ├ chunks/main-app-e4c0616da69beffe.js  76.5 kB
  └ chunks/webpack-bf1a64d1eafd2816.js   1.61 kB


○  (Static)  automatically rendered as static HTML (uses no initial props)
```

Also filter out `/favicon.ico` static route as it's confusing
2023-09-08 00:06:05 +00:00
Jiachi Liu
8076d0c68a
Add option to support log full request url in verbose mode (#55111)
Fixes #52239
Closes NEXT-1604

Change the logging option to object for flexibility
```js
experimental: {
  logging: {
    level: 'verbose', // control log level
    fullUrl: true, // console fetching url logging
  }
}
```

### After vs Before
<img src="https://github.com/vercel/next.js/assets/4800338/e0a05e2d-b69e-4075-afe1-8179c827f548" width="400">
<img src="https://github.com/vercel/next.js/assets/4800338/89a73ae3-1999-49ac-86f0-2c7248adc22c" width="400">
2023-09-07 23:58:09 +00:00
Wyatt Johnson
2b514ea8e3
Strip internal routing headers (#55114)
This strips the internal routing headers added by the routing server. Based on some of the changes being introduced in https://github.com/vercel/next.js/pull/54813 this strips the headers, but this also adds some internal flags to turn this off during testing to validate correct routing beheviour.
2023-09-07 22:08:53 +00:00
JJ Kasper
7267538e00
Revert "perf: add bundled rendering runtimes (#52997)" (#55117)
This reverts commit a5b7c77c1f.

Our E2E tests are failing with this change this reverts to allow investigating async 

x-ref: https://github.com/vercel/next.js/actions/runs/6112149126/job/16589769954
2023-09-07 21:07:53 +00:00
Zack Tanner
d330f7b02c
fix: ensure mpa navigation render side effects are only fired once (#55032)
This is to fix an issue where these redirect side effects can be fired multiple times when the router reducer state changes. This block is still run when the router state updates, which can lead to superfluous attempts to redirect to a page.

With these changes, we keep track of the page that is being redirected to. If a re-render occurs while that request is in flight, we don't trigger the side effects. 

[Slack x-ref](https://vercel.slack.com/archives/C04DUD7EB1B/p1694049914264839)
2023-09-07 20:53:07 +00:00
Wyatt Johnson
18980a6411
Fixed i18n data route RegExp (#55109)
The previous RegExp for data routes when i18n was enabled yielded a pattern like:

```
^\/_next\/data\/development\/(?<nextLocale>.+?)\/about.json$
^\/_next\/data\/development\/(?<nextLocale>.+?)\/blog/about.json$
```

But the capture group for the `nextLocale` did so greedily, where the following:

```
/_next/data/development/en-US/blog/about.json
```

Would actually match both routes.

This changes it to prevent the locale from including a `/` via `[^/]`, resulting in the new expressions:

```
^\/_next\/data\/development\/(?<nextLocale>[^/]+?)\/about.json$
^\/_next\/data\/development\/(?<nextLocale>[^/]+?)\/blog/about.json$
```
2023-09-07 18:20:41 +00:00
Jimmy Lai
a5b7c77c1f
perf: add bundled rendering runtimes (#52997)
## What?

In Next, rendering a route involves 3 layers:
- the routing layer, which will direct the request to the correct route to render
- the rendering layer, which will take a route and render it appropriately
- the user layer, which contains the user code 

In #51831, in order to optimise the boot time of Next.js, I introduced a change that allowed the routing layer to be bundled. In this PR, I'm doing the same for the rendering layer. This is building up on @wyattjoh's work that initially split the routing and the rendering layer into separate entry-points.

The benefits of having this approach is that this allows us to compartmentalise the different part of Next, optimise them individually and making sure that serving a request is as efficient as possible, e.g. rendering a `pages` route should not need code from the `app router` to be used.

There are now 4 different rendering runtimes, depending on the route type:
- app pages: for App Router pages
- app routes: for App Router route handlers
- pages: for legacy pages
- pages api: for legacy API routes

This change should be transparent to the end user, beside faster cold boots.

## Notable changes

Doing this change required a lot of changes for Next.js under the hood in order to make the different layers play well together.

### New conventions for externals/shared modules

The big issue of bundling the rendering runtimes is that the user code needs to be able to reference an instance of a module/value created in Next during the render. This is the case when the user wants to access the router context during SSR via `next/link` for example; when you call `useContext(value)` the value needs to be the exact same reference to one as the one created by `createContext` earlier.

Previously, we were handling this case by making all files from Next that were affected by this `externals`, meaning that we were marking them not to be bundled.

**Why not keep it this way?**

The goal of this PR as stated previously was to make the rendering process as efficient as possible, so I really wanted to avoid extraneous fs reads to unoptimised code. 

In order to "fix" it, I introduced two new conventions to the codebase:
- all files that explicitly need to be shared between a rendering runtime and the user code must be suffixed by `.shared-runtime` and exposed via adding a reference in the relevant `externals` file. At compilation time, a reference to a file ending with this will get re-written to the appropriate runtime.
- all files that need to be truly externals need to be suffixed by `.external`. At compilation time, a reference to it will stay as-is. This special case is needed mostly only for the async local storages that need to be shared with all three layers of Next.

As a side effect, we should be bundling more of the Next code in the user bundles, so it should be slightly more efficient.

### App route handlers are compiled on their own layer

App route handlers should be compiled in their own layer, this allows us to separate more cleanly the compilation logic here (we don't need to run the RSC logic for example).

### New rendering bundles

We now generate a prod and a dev bundle for:
- the routing server
- the app/pages SSR rendering process
- the API routes process

The development bundle is needed because:
- there is code in Next that relies on NODE_ENV
- because we opt out of the logic referencing the correct rendering runtime in dev for a `shared-runtime` file. This is because we don't need to and that Turbopack does not support rewriting an external to something that looks like this `require('foo').bar.baz` yet. We will need to fix that when Turbopack build ships.

### New development pipeline

Bundling Next is now required when developing on the repo so I extended the taskfile setup to account for that. The webpack config for Next itself lives in `webpack.config.js` and contains the logic for all the new bundles generated.

### Misc changes

There are some misc reshuffling in the code to better use the tree shaking abilities that we can now use.

fixes NEXT-1573

Co-authored-by: Alex Kirszenberg <1621758+alexkirsz@users.noreply.github.com>
2023-09-07 15:51:49 +00:00
OJ Kwon
4f1be5d999
test(next-dev): migrate styled-jsx integration test (#55079)
### What?

There are tests under `next-dev-tests` which used native binary to run tests for Turbopack. This should belong to next.js integration tests, and also indeed there are overlaps.

As a first step, PR removes duplicated styled-jsx test and mark existing test under turbopack test filter as enabled.


Closes WEB-1510
2023-09-07 02:51:20 +00:00
Zack Tanner
1f797faaa6
fix: skipTrailingSlashRedirect being ignored in pages (#55067)
This moves `resolve-href` into `next/src/client` to make sure that when it calls `normalizeTrailingSlash`, that function has access to `process.env.__NEXT_MANUAL_TRAILING_SLASH` (inlined via `DefinePlugin`).

Closes NEXT-1599
Fixes #54984
2023-09-06 18:03:37 +00:00
Jiachi Liu
16cbc829ce
test: merge base path tests (#55069)
Merge app-dir base path related tests into one
2023-09-06 17:20:47 +00:00
Jiachi Liu
f2f1c251bf
Fix duplicated dynamic metadata routes in dev mode (#55026)
In dev mode, we're using a catch-all route for dynamic metadata routes, e.g. page path `/twitter-image` would become `/twitter-image/[[...metadata_id...]]/route` as a dynamic custom app route.

But we're missing to convert it in filesystem scanning for routing purpose, adding the metadata related normalizing logic for app page to align with other places.
2023-09-06 00:21:06 +00:00
Florentin / 珞辰
ffd504c43f
[functions-config-manifest] use correct extra config for pages router (#54786)
When using page routes we need to pass the contents of the `export const config` to the `extraConfig` populating the functions config manifest rather then relying on named exports like in app router.
2023-09-05 14:13:37 +00:00
Jiachi Liu
e117c000e4
Redesign nextjs logging (#54713)
The current logging styles has been existed for a while, this PR gives a fresh impression for the logging output from Next.js.
We want to achieve few new goals that makes the output clean, modernized, sweet 🍫 .

Few goals are addressed with this redesign:

## Refresh Impression & Simplification

The new design of logging is much more information centralized and streamlined.

* Given a `ready` message at the begining when compilers are bootstrapped.
* Only show `compiled` event with green check mark indicating succesful compilation, this will merge the unclear `compiling` event which shows `(client and server)` before, now tell you the route compilation info in one line.

hello world app

### `next dev`

#### After vs Before


<img src="https://github.com/vercel/next.js/assets/4800338/9649b340-8241-4756-a2b3-a989f0b74003" height="120"> 
<img src="https://github.com/vercel/next.js/assets/4800338/ee181263-3dd4-40d0-9ffc-819a56b45900" height="120">  

 


 

### `next build`

#### After vs Before


<img src="https://github.com/vercel/next.js/assets/4800338/5db9829a-9ffc-49f0-b030-93ee92f5c248" width="360"> 
<img src="https://github.com/vercel/next.js/assets/4800338/b9527b83-27c8-4426-9c0d-c0d4072b7d58" width="360">





### error status

#### After vs Before

<img src="https://github.com/vercel/next.js/assets/4800338/00455226-ace7-468b-8d90-0d36bf038489" height="120"> 
<img src="https://github.com/vercel/next.js/assets/4800338/1be8c451-d3f0-465c-9ef7-6b0dde7cff85" height="120"> 



## Streamlization

If you have customized envs and experiments Next.js will give the brief in the early summary about your network information, env vars, and enabled experimental features

<img src="https://github.com/vercel/next.js/assets/4800338/ca1a7409-1532-46cb-850f-687e61e587b2" width="400">


## Polish

### fetching logging structure 

#### After vs Before
<img src="https://github.com/vercel/next.js/assets/4800338/97526397-dffe-4736-88ed-e5cbe5e945bd" width="400">
<img src="https://github.com/vercel/next.js/assets/4800338/ab77c907-5ab5-48bb-8347-6146d2e60932" width="400">


### Dedupe Duplicates

The logging is moved from `@next/env` to `next` itself, `@next/env` will only notify the invoker that the env is reloaded. Then the duplicated logs for the env reloading cases can be avoid.

#### After vs Before
<img src="https://github.com/vercel/next.js/assets/4800338/04799295-e739-4035-87aa-61cec962fc39" width="400">
<img src="https://github.com/vercel/next.js/assets/4800338/e29020c9-0031-4bf3-a21b-8b64633f43a2" width="400"> 


### Different indicators

Use unicode text icons for different situation: 
* passed -> check mark
* warning -> warning
* error -> red cross
* loading -> circle

<img src="https://github.com/vercel/next.js/assets/4800338/715c34bd-298f-4990-a5d7-e12e455ead44" width="400">



Co-authored-by: Tim Neutkens <6324199+timneutkens@users.noreply.github.com>
2023-09-05 11:40:00 +00:00
Zack Tanner
c013e98fa4
fix: server actions firing twice after navigation (#54948)
The original logic here was introduced to unblock client side navigations if a server action was in flight, however this introduced a bug where subsequent actions would fetch twice after navigation. 

This was happening because the promise handling was in the wrong spot: previously this would potentially cause both the `then` callback to fire while simultaneously the action reducer would handle the result. Moving it to where we're first checking if there's a pending navigation will more reliably indicate if the action was resolved after we discarded it in the reducer.

Closes NEXT-1589
Fixes #54746
2023-09-03 20:31:48 +00:00
Jiachi Liu
6bc23cd2bd
Fix group routes custom root not-found (#54931)
For group routes, as their custom layout show up at the 1st level of the loader tree, so previously we tried to add the default not-found to that layer, but if they have custom root not-found, we should use that as the root not-found componeny, instead of using default not-found component to form the 404 page

Closes NEXT-1588

Fixes #51075
Fixes #54892
2023-09-03 20:15:24 +00:00
Zack Tanner
ef33018a3d
fix next/headers when used in src/middleware (#54889)
This updates the check to see if a request is made in middleware to be a bit less brittle so it doesn't break if middleware is located in `/src/middleware` (`params.page` would be `/src/middleware` rather than `/middleware` in that case)

fixes https://github.com/vercel/next.js/discussions/54853
2023-09-01 18:56:51 +00:00
Jiachi Liu
28ef2473af
Fix performance measures crashing the app (#54858)
There're various of cases would cause the `beforeRender` performance mark is not existed in the performance entries, learned from the issues description. We have to check if that mark is existed.

This PR also refactors all the mark names and measurement names into constants so that we won't easily mistype them


Fixes #20743
Fixes #40903
Fixes #47560

Co-authored-by: Balázs Orbán <18369201+balazsorban44@users.noreply.github.com>
2023-09-01 14:51:38 +00:00
Donny/강동윤
a5c180388a
Update swc_core to v0.82.11 (#54653)
### What?

Update swc crates to
44de87f481

### Why?

To use `import with` and etc...

### How?

Closes WEB-1460
Fixes #

---

Turbopack counterpart: https://github.com/vercel/turbo/pull/5820

---------

Co-authored-by: Tobias Koppers <tobias.koppers@googlemail.com>
2023-09-01 15:35:04 +02:00
JJ Kasper
2eef775472
Update tag handling for app cache (#53321)
Optimizes how we handle cache tags for soft tags (auto-added by Next.js)
and normal tags (added manually) and adds differentiating between
`revalidatePath('/blog/first')` and page/layout.

Soft tags are not stored across cache entry and instead auto sent along
when checking cache entries. This allows us to prevent storing
exponential amounts of tags across cache entries while still having the
relationship between them so that single path revalidation can work
properly.

x-ref: [slack
thread](https://vercel.slack.com/archives/C042LHPJ1NX/p1690586837903309)
2023-08-31 15:17:40 -07:00
Wyatt Johnson
962ce0dcee
Short circut 404's for /favicon.ico in development (#54747)
In development, it's common to have a project without a favicon.ico in the public or static folders. This short circuits the route process in development so it doesn't compile the not found page for every page request.

Co-authored-by: Tim Neutkens <6324199+timneutkens@users.noreply.github.com>
2023-08-30 16:15:19 +00:00
Janicklas Ralph
d3a107991c
Updating Third party capital version. (#54418)
Updated Third-party-capital version. Refactored `next/third-parties` to update the way components are built. Updated tests.

cc: @kara @huozhi @gnoff
2023-08-29 23:13:35 +00:00
Max Leiter
387a8ff01a
Server actions: support relative URLs in redirect() (#54736)
slack ref: https://vercel.slack.com/archives/C03S8ED1DKM/p1693331432057499
2023-08-29 21:08:56 +00:00
Tim Neutkens
ac1e392cc7
Remove experimental.legacyBrowsers as it is stable (#54718)
This experimental option went to stable in Next.js 13, so this code was
leftover from then.
The reason `true` wasn't needed is that you can provide your own
`browserslistrc` that will allow targeting any browsers needed.

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

## For Contributors

### Improving Documentation

- Run `pnpm prettier-fix` to fix formatting issues before opening the
PR.
- 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 #

-->
2023-08-29 22:31:06 +02:00
Max Leiter
4c3b7f9b7a
Export RedirectType from next/navigation (#54729)
A continuation of #51864 with RedirectType used in an e2e test and some
ts-ignores removed from the codebase. Happy to split it into two PRs but
I left comments in the two consequential files

---------
2023-08-29 11:05:44 -07:00
Jiachi Liu
8ed492f3c1
Default app router not found (#54199)
Adding a default app router not-found error page in production. We introduced a custom global not-found page if you have `not-found.js` file under app directory. Next.js will still routed you to default pages 404 if there's no routes matched when you don't have a custom `not-found.js`.

This PR creates a default layout (only having `html` and `body`) and will use the default not-found component as children to build a default 404 page for app router, and server will route to that page when there's any app router pages existed. This will also fix the hmr issue that when you hit a pathname doesn't exist, nextjs will compile `/_error` for you which is not expected, now we're using `/not-found` instead

Closes NEXT-1359
2023-08-28 22:09:16 +00:00
Shohei Maeda
efd8d22654
Add new permanentRedirect function in App Router (#54047)
for internal:
https://vercel.slack.com/archives/C03S8ED1DKM/p1691700057242999

### Problem

- The existing [`redirect()`
function](https://nextjs.org/docs/app/api-reference/functions/redirect)
can't control the status code.
- The existing [`redirect()`
function](https://nextjs.org/docs/app/api-reference/functions/redirect)
returns a 307 HTTP redirect response while it returns a 308-equivalent
meta tag `<meta http-equiv="refresh" content="0;url=/foo"/>` in
streaming response (e.g., suspense boundary), making the behavior
inconsistent.

### Solution

Adding a new `permanentRedirect()` function and changing the meta tag
default accordingly.

| func   |      HTTP status      |  meta tag |
|---|:---:|---|
| `redirect()` | 307 | `<meta http-equiv="refresh"
content="1;url=/foo"/>` |
| `permanentRedirect()` | 308 | `<meta http-equiv="refresh"
content="0;url=/foo"/>` |

ref.
https://developers.google.com/search/docs/crawling-indexing/301-redirects

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2023-08-28 14:22:43 -07:00
Vincent Voyer
e4ff4da7c8
fix(DX): More precise error messages for export const config deprecation (#54492)
Before:
```
Error: `export const config` in /vercel/path0/src/app/api/route.js is deprecated. Please change `runtime` property to segment export config. See https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config
```

After:
```
Error: `export const config` in /vercel/path0/src/app/api/route.js is deprecated:
  - Change `config.runtime…` to `export const runtime = "edge"`
  - Change `config.regions…` to `export const preferredRegion = ["us-east-1"]`
Visit https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config for more information.
```

The values proposed in Change.. are the actual ones from the customers, they can just copy paste.

Closes NEXT-1560
2023-08-25 16:25:15 +00:00
Zack Tanner
e08839a5a9
fix infinite navigate events when Promise is proxied (#54394)
### What
When the global `window.Promise` is proxied, things that rely on custom Promise properties (e.g. the `status` field) break. In the case of navigation events, the prefetch cache is never identified as being fulfilled, so navigation hangs in an infinite loop.

### How?
This ensures that the value being stored in the prefetch cache have the expected Promise signature even when proxied. 

x-ref: https://github.com/vercel/next.js/discussions/53746 
[slack x-ref](https://vercel.slack.com/archives/C03S8ED1DKM/p1692626697034029)
2023-08-24 16:22:48 +00:00
Zack Tanner
9ea6bc4bcb
fix: custom incremental cache handlers should work when transpiled (#54472)
This fixes a `CurCacheHandler is not a constructor` error when the custom cache handler path is transpiled from ESM -> CJS (resulting in the handler being attached to the `default` property on the module's exports)

Closes NEXT-1558
Fixes #54453
2023-08-24 03:48:30 +00:00
JJ Kasper
fb3f045679
Generate prefetch RSC paylod during build for SSR paths (#54403)
This ensures we prerender the prefetch RSC payload for non-fully
prerendered paths so that we don't need to invoke un-necessarily to
generate this payload.

x-ref: [slack
thread](https://vercel.slack.com/archives/C05KYT5S9FF/p1692155103311829)
2023-08-23 16:09:27 -07:00
Shu Ding
758b9d251a
Use push for Server Action redirections (#54458)
Closes #53911. When calling `redirect()` instead a Server Action, the previous route should exist in the history when it's handled by the framework.
2023-08-23 19:47:46 +00:00
Jiachi Liu
9834ab7e15
Fix not found css not being preloaded while navigation (#53906)
### Problem

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

### Solution

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

Related react change: https://github.com/facebook/react/pull/27265
Fixes #53210
2023-08-23 13:07:30 +00:00
Jiachi Liu
db72cb12d9
refactor: Use swc AST to determine use client and server directives (#54358)
Follow up for #54202, use swc AST to determine the directives. Also add server actions directives for extendibility here in case we might need it in the future

Closes NEXT-1538
2023-08-23 12:28:20 +00:00
Shu Ding
ad556aee1b
Fix compilation of next/dynamic with ssr: false in App Router (#54411)
For the server compilation, we currently transpile the dynamic import
expression to `null` if `ssr` is disabled. However to make the Server
Actions layer work (as it can be created again from a Client Component),
we can't do that optimization.

This PR changes it to always keep that import expression when
`react_server_components` (App Router) is enabled, no matter which layer
it's on.

Closes #52672.
2023-08-23 14:15:31 +02:00
JJ Kasper
d54ed07b3c
Fix missing locale info for middleware data request (#54357)
This ensures we properly populate locale information with `skipMiddlewareUrlNormalize` enabled as we shouldn't provide incorrect values even if we are skipping normalizing. 

Fixes: https://github.com/vercel/next.js/issues/53646
2023-08-21 22:34:42 +00:00
Jiachi Liu
70231ef7cd
test: add case for marking _document with edge runtime (#54316)
Can't repro anymore, add a test case for issue 45189

Closes #45189
Closes NEXT-1396
2023-08-21 20:56:46 +00:00
JJ Kasper
0e91c79f57
Fix windows next-swc builds (#54353)
Fixes this build error on windows due to invalid path:

```sh
 Error: error: invalid path 'test/e2e/app-dir/app/app/bootstrap/[[...*]]/ClientComponent.js'
 Error: The process 'C:\Program Files\Git\cmd\git.exe' failed with exit code 128
```

x-ref:
https://github.com/vercel/next.js/actions/runs/5930602201/job/16080672888#step:7:62
2023-08-21 13:35:12 -07:00
Zack Tanner
892839ff83
fix: server actions blocking navigation events (#54307)
A long-running server action shouldn't block page navigation. This makes use of a global mutable to detect when a navigation event occurs -- this change will unblock other reducers (such as navigation).

If we bailed on the action, we trigger a `router.refresh()` to ensure any side effects from the action are refetched.

Closes NEXT-1131
Fixes #49425
2023-08-21 20:34:42 +00:00
Josh Story
3370022ac2
add test case for CSP with bootstrap scripts and preinit modules (#54348)
in #54059 the nonce attribute was added to preinitialized scripts to when using this CSP directive. The test added asserts there is at least one script that has the nonce attribute. I've changed this to 2 because currently our builds produce at least two "main" scripts, the main chunk and the webpack runtime. The way we bootstrap there is always exactly one bootstrap script which means if we only assert that there is one script with a nonce we might not be asserting anything about the preinit script path. If we ever update our webpack config to produce a single main script this test will fail but we should never do that (it's bad for caching) and so it shouldn't happen and if it does it will hopefully force us to consider if we're making a mistake

Additionally I've added another test that is more e2e. it asserts that the page bootstraps even when using CSP (in prod). In Dev it asserts the CSP attributes but it expects the bootstrap to fail because our dev mode violates the CSP directive with eval.
2023-08-21 18:49:21 +00:00
Nikhil Bhargava
24cd55c09f
Adds nonce to preinit scripts (#54059)
Fixes #54055.

A bug recently introduced in https://github.com/vercel/next.js/pull/53705 made it so that we were now preinitializing some of our scripts slightly better, but in doing so, we failed to pass in a nonce. This broke nonce-based CSP usage. The fix was to add the `nonce` to our `ReactDOM.preinit` calls.

Manual testing shows that this change fixes the error and the nonce is now passed in as expected.


Co-authored-by: Dan Ott <360261+danieltott@users.noreply.github.com>
2023-08-20 13:55:02 +00:00
Jimmy Lai
6aa07fb999
app-router: tweak prefetch cache status heuristics (#53864)
This PR changes the heuristic in the client cache to only check and show the prefetched data when it was prefetched or last read 30s ago vs keeping it around as long as it was accessed within 30s.
2023-08-20 11:25:48 +00:00
Jiachi Liu
f2a3fd9fc3
Handle basePath for redirect() (#54277)
### What & Why
Add base path handling for the url in redirect error if the `basePath` is configured.

This is only break for server rendering case as the `basePath` is missing in the `Location` header. When running `next build`, everything is managed well with app router and base path on client side so it didn't break.

### How

Adding `basePath` if it's presented for `Location` header.
Update the `RenderOpts` type as basePath is already passed down in it, also update them for turbopack entries

Fixes #54163
Closes NEXT-1529
2023-08-20 03:32:52 +00:00