Commit graph

17328 commits

Author SHA1 Message Date
Jimmy Lai
30da48fcd2
server: enable minification by default (#54960)
This PR will enable minifying the *server* part of the user code by default when running `next build`.

## Explanation

Next.js compiles two versions of your code: the client version for the app that runs in the browser, and the server for the code that will run on the server. Whilst the client code has always been minified and optimised, we haven't done so historically for the server side.

## How does this impact me?

There are several consequences to this change:
- minified code makes error stacks less readable. To fix that, you can use source maps, which you can enable with `experimental.serverSourceMaps`. This is not enabled by default as this is an expensive operation.
- however the server code will be optimised for size so as a result, cold boots should improve

## opting out

you can opt out via specifying `experimental.serverMinification: false` in `next.config.js`
2023-09-06 10:24:01 +00:00
Shu Ding
d30c94b816
Adjust optimizePackageImports (#55040)
Added a few popular libs (all tested locally), removed some that don't have barrel entries.
2023-09-06 10:14:42 +00:00
CSY54
b3ed162fe2
docs: add missing quotation mark (#54968)
There is a quotation mark missing in the docs. Adding it back in this PR.
2023-09-06 07:22:31 +00:00
迷悟
57bbc59028
docs: fix typo (#54973) 2023-09-06 07:16:19 +00:00
Hyewon Kim
85fb714f16
docs: Fix typo in getting-started/project-structure (#55035)
<!-- 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 #

-->

- Fix typo in [Next.js Project Structure: Top-level
files](https://nextjs.org/docs/getting-started/project-structure#top-level-files)
- It's common to create it as `next-env.d.ts` without dots.
2023-09-06 00:12:17 -07:00
Ryota Murakami
7decb13000
chore(ci): bump pnpm v8.6.11 to v8.7.1 (#54873)
My "pnpm@v8.7.0" was not working and I noticed it by accident and sent a PR.

Co-authored-by: Steven <229881+styfle@users.noreply.github.com>
2023-09-06 00:39:44 +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
vercel-release-bot
cdfb9de498 v13.4.20-canary.18 2023-09-05 22:49:40 +00:00
Shu Ding
a9b5174e68
Experimental server optimization (#54925)
Server React API optimization of `useEffect`, `useLayoutEffect` and `useState` under a `experimental.optimizePackageImports` flag.
2023-09-05 22:22:24 +00:00
Shu Ding
b65c823a64
Remove react-hot-toast from the optimizePackageImports list (#55029)
@MaxLeiter ran into an issue with this, need to investigate.
2023-09-05 15:05:20 -07:00
JJ Kasper
2f31fa9476
Update eslint dependencies note in docs (#55023)
Closes: https://github.com/vercel/next.js/issues/54105
2023-09-05 19:01:27 +00:00
vercel-release-bot
1b844600ce v13.4.20-canary.17 2023-09-05 18:20:51 +00:00
JJ Kasper
180749c096
Update ready check for PR stats (#55022)
Looks liket his has been broken since
https://github.com/vercel/next.js/pull/54713 due to the text it watches
for being changed.
2023-09-05 11:12:43 -07:00
Jimmy Lai
9f247d9f98
perf: use split chunks for the node server (#54988)
This PR introduces a change in the Next.js server that should improve memory usage nicely during dev.

## How

While investigating the repro cases in #54708, @timneutkens and I noticed that the high memory usage often involved `googleapis`. Digging a bit more, I also saw that in dev, the bundle generated for a page using `googleapis` was around 80MB and that requiring it in Node.js increased memory by 160MB 🥲 and that requiring another page that also used this also increased the memory by 160MB.

The problem is that Next.js, on new navigations and hot reloads, might need to load/reload all the code required for the page *all the time*. This issue is also exacerbated by the fact that there's a nasty Node.js bug that makes it impossible to clean that memory up, leading to memory bloat and overall a pretty bad DX.

So if we can't clean this up, what can we do about it?

The change I'm introducing in this PR is that I'm changing Next.js in order to split the code you're using from `node_modules` from the code you've written in different chunks. The idea is that the heavy code you're loading from `node_modules` is only gonna be loaded once per session this time.

This should make a navigation/page reload only load the user bundle now. On my simple test case, the cost of navigation went from ~200MB to ~40MB.

A few notes on the implementation:
- The chunks for the `node_modules` are split at the module level, this is to ensure that each of the node_modules dependencies is split in the most memory efficient manner. If it was a big monolithic chunk, it would potentially be reloaded again and again whenever reloaded, leading to leakage.
- I'm guessing we could do the same for the Edge server
- the first load for a page will still be fairly heavy memory wise, there's probably something else we can do there 
- there's also an issue with the webpack require cache being flushed, whereas it could be reused

## comparisons

### navigating a page

before
<img width="284" alt="CleanShot 2023-09-04 at 21 00 46@2x" src="https://github.com/vercel/next.js/assets/11064311/44e37df8-4414-4ca1-b6bf-fb0fb11751ea">


after
<img width="392" alt="CleanShot 2023-09-04 at 20 58 53@2x" src="https://github.com/vercel/next.js/assets/11064311/46226123-a73a-4132-a99d-fb812e59df46">
2023-09-05 15:54:44 +00:00
Tim Neutkens
bf3c3ce245
Client-side HMR message types (#55009)
Continuation of the previous PRs that introduce HMR event types for the server-side code, this leverages those types client-side too.
2023-09-05 15:30:35 +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
Lee Robinson
7a256e657b
Update Jest and Vitest example for App Router. (#54989)
Building off https://github.com/vercel/next.js/pull/54891, updates the `with-jest` and `with-vitest` examples with updated packages and App Router tests.
2023-09-05 13:31:47 +00:00
Kiko Beats
7288c866eb
upgrade edge-runtime (#55005)
Fixing `Headers#getSetCookie` method
2023-09-05 13:29:17 +00:00
Damien Simonin Feugas
39a66d5a08
chore: restore options to opt-in for server-side transpilation (#55010)
### 🧐 What's in there?

As discussed with @huozhi, it's restoring code from #52393 which I forgot to restore in #54891.
It is unlikely to make a difference, but we'll set globalWindow based on the desired test environment. This will not make any difference for most people.

### 🧪 How to test?

Once you've rebuilt your local version of Next, `pnpm testheadless jest/rsc` 

Co-authored-by: Jiachi Liu <4800338+huozhi@users.noreply.github.com>
2023-09-05 12:55:10 +00:00
Balázs Orbán
3a62a30649
chore: bump undici (#55007)
This bumps `undici` to the latest version to match the one used in newer Node.js versions', potentially fixing compatibility issues.

I also cleaned up some related `global as any` usage.
2023-09-05 12:29:51 +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
Lee Robinson
930db5c1af
docs: Add template API reference (#54938)
Ports content from the Pages and Layouts section about templates and formats to match other API reference pages.

Co-authored-by: Michael Novotny <446260+manovotny@users.noreply.github.com>
2023-09-04 16:54:56 +00:00
Tim Neutkens
37a6e213a2
Add turbopack-connected HMR event (#54976)
Additional HMR actions that weren't using the types yet.
2023-09-04 15:26:57 +00:00
Tim Neutkens
f313235428
Remove pong HMR event as it is not used (#54965)
While investigating the HMR event types I noticed `pong` is not being used in Pages Router nor in App Router.

This PR removes the code that sends it as it's essentially dead code.
2023-09-04 13:27:47 +00:00
vercel-release-bot
7a1924ed6d v13.4.20-canary.16 2023-09-04 11:58:51 +00:00
Damien Simonin Feugas
3338dd0b31
fix(next-swc): skips client/server only checks when running with Jest to unblock testing (#54891)
Co-authored-by: Jiachi Liu <inbox@huozhi.im>
2023-09-04 13:53:41 +02:00
Jiachi Liu
fd91ac4f45
Update codeowners (#54966)
add huozhi to `next-swc` package scope
2023-09-04 11:09:12 +00:00
Tim Neutkens
91922c44eb
Add serverError action to list of HMR events (#54964)
Adds `serverError` to the list of HMR actions, missed this in the earlier PRs as it wasn't using `hotReloader.send`.

Also ensures on-demand-entry-handler reuses the hotReloader.send method.
2023-09-04 09:40:40 +00:00
Tim Neutkens
986f648baa
Unify serverError hmr event (#54962)
Ensures only one name is used for the event, makes it easier to search for, going to replace this with the constant like the other events in a follow-up PR but this can be landed as-is.
2023-09-04 09:01:22 +00:00
Sander
be3a7e471b
chore: upgrade playwright example (#53584)
Co-authored-by: Balázs Orbán <18369201+balazsorban44@users.noreply.github.com>
2023-09-04 00:26:08 +00:00
Tito
95e33c4dd2
Fix: slug type issue (#54616)
Failure at build time because - Type error: Argument of type 'string | null' is not assignable to parameter of type 'string'.
2023-09-04 00:23:38 +00:00
Jiachi Liu
9abf8863cc
docs: fix document format for __next_private_export_map__ (#54952)
Fix the document format of `__next_private_export_map__`

follow up: #54695
2023-09-03 20:53:30 +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
Shu Ding
ef6140723a
Ensure that barrel files behind wildcards are transformed into shortpath (#54951)
This fix ensures the case that if you `import { foo } from './index'`,
where:

index.js:

```js
export * from './subpkg'
```

subpkg.js:

```js

const unrelatedExpressions = ...

export { foo } from './foo'
export { bar } from './bar'
```

Previously we'll transform the proxy to the second module to `export {
foo } from './subpkg'`. With this fix it will be correctly optimized as
`export { foo } from './foo'` which is a shorter path.
2023-09-03 13:02:14 -07:00
Chanhee Lee
85f9e1b751
docs: Fix typo in app/building-your-application/caching (#54841)
- fix typo in [Building Your Application: Caching](https://nextjs.org/docs/app/building-your-application/caching#fetch-optionsnexttag-and-revalidatetag)
- `options.next.tags` is correct (current: `options.next.tag`)
2023-09-03 17:25:35 +00:00
Tim Neutkens
7ab02c5e1e
Fix typo in hot-reloader (#54944)
Noticed this small typo from hrm -> hmr.
2023-09-03 13:37:17 +00:00
Robert Bradford
17da2ca1fe
docs: Move general info about next.config.* to its index page (#53542)
I was reading through the current https://nextjs.org/docs/app/api-reference/next-config-js/pageExtensions and noticed it started explaining different file formats for the `next.config.*` file. Is that information better suited for the https://nextjs.org/docs/app/api-reference/next-config-js index page?

There was also a little redundancy at the top. 

Co-authored-by: Lee Robinson <9113740+leerob@users.noreply.github.com>
2023-09-03 00:12:47 +00:00
Rousan Ali
d58603fb63
docs: Update Vercel YouTube channel url (#54912) 2023-09-03 00:10:00 +00:00
Tim Neutkens
0f602f4943
Add types for hot reloader send method (#54932)
First part adding additional types for the various events that are sent through the websocket to the browser.

Will add additional details / comments on the types after landing these changes in the browser-side code too.
2023-09-03 00:07:32 +00:00
Fuma
f74f676f73
docs: Clarify the ability to access current route segments in layouts (#53349)
> Layouts do not have access to the current route segment(s). To access route segments, you can use useSelectedLayoutSegment or useSelectedLayoutSegments in a Client Component.

The term "current" is confusing. 
It should be only the route segments under the layout. For example: `app/layout.tsx` can not access `app/[slug]`.
2023-09-02 23:55:18 +00:00
Curtis L
96e13c3bf1
docs: add missing word in client components (#54830)
Missing word in client component page in docs when discussing the effect of "use client" on a client component's children and imported components. Not sure if 'children' is the appropriate word or whether there should be a reference to imported components too.
2023-09-02 23:47:56 +00:00
Florentin / 珞辰
a0beb340ca
docs: add maxDuration in API Routes config (#54844)
Update the code snippet for configuring API Routes to include `maxDuration` as an option.

Co-authored-by: Lee Robinson <9113740+leerob@users.noreply.github.com>
2023-09-02 23:43:11 +00:00
imageck
6c098a74e3
docs: Minor formatting fix in Pages Router SSG (#54915) 2023-09-02 23:34:21 +00:00
Rob Johansen
166f556f69
Fix typo in description of error.js (#54933) 2023-09-02 22:57:49 +00:00
Balázs Orbán
7a871a9424
chore: fix autolabeler (#54916)
### What?

Follow-up of #54824

### Why?

Correctly detect the section to look for while autolabeling. The text currently being searched is not present in the issue body, just the template. Example: #54911 where "App Router" is present but was not detected.
2023-09-02 21:05:10 +00:00
Okoye Charles
53d6da6cc6
fix: Fix grammar issues on README.md (#54921)
In this PR resolved the grammatical error on the [README.md](https://github.com/vercel/next.js/blob/canary/examples/with-passport-and-next-connect/README.md)

Fixes #54919
2023-09-02 15:10:37 +00:00
Justin Ridgewell
2b9ffb009c
Update turbopack (#54909)
Minor update that includes changes necessary to get HMR errors working.

Closes WEB-1494
2023-09-02 10:45:49 +00:00
Will Binns-Smith
125605c307
Debug tracing: time devserver startup (#54537)
This:

- Profiles dev server startup by wrapping most logic in a debug tracing Span
- Sets tracing globals for this case earlier, as they would otherwise be unavailable
- Allows Turbopack traces to be uploaded, as while currently incomplete, they are accurate


Closes WEB-1440

Co-authored-by: Jiachi Liu <4800338+huozhi@users.noreply.github.com>
2023-09-02 00:34:37 +00:00
Wyatt Johnson
c3d23c6db6
Simplify getPagePaths logic (#54908)
Simplified some logic around `getPagePaths` as well as another normalization function. This instead utilized some flat arrays using push instead of relying on a separate `flatten` method (allowing us to remove it). This also reduced the number of logic checks for this generation.
2023-09-01 23:42:34 +00:00