Commit graph

3460 commits

Author SHA1 Message Date
Tim Neutkens
29aa48dfc4 v10.1.3 2021-04-02 12:24:12 +02:00
Tim Neutkens
6e51f2a816 v10.1.3-canary.2 2021-04-02 12:22:15 +02:00
Gerald Monaco
af3315b14d
Clean up RenderOptsPartial (#23614)
* Remove autoExport from RenderOpts

* Remove ampMode from RenderOpts

* Stop passing inAmpMode and hybridAmp

* Unset nextExport when falsy
2021-04-01 20:21:15 -05:00
JJ Kasper
95b9839622
v10.1.3-canary.1 2021-04-01 15:15:29 -05:00
Tobias Koppers
0ad805fee6
update webpack to 5.30 (#23612)
* has some memory usage improvements
* after a while cache entries that are unused and already persistent to disk are removed from the memory cache
  * When are read again, they are restored from disk again
  * Should play well together with adding and removing pages due to on-demand-entries

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.

## Documentation / Examples

- [ ] Make sure the linting passes
2021-04-01 19:25:57 +00:00
Shu Ding
2ed54cddfa
Update decoder to correctly handle grayscale PNGs (#23393)
This PR updates the Squoosh PNG decoder, which fixes #22929 in GoogleChromeLabs/squoosh#971.

## Bug

- [x] Fixes #22929
- [x] Integration tests added

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.

## Documentation / Examples

- [ ] Make sure the linting passes
2021-04-01 15:16:26 +00:00
JJ Kasper
65c22167c8
Ensure has segments are allowed in destination (#23588)
This ensures we gather segments from the experimental has field when validating segments used in the destination to prevent the invalid segments in the destination error from showing incorrectly. This usage has been added to the custom-routes test suite to ensure the segments are passed correctly from the has field. 

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

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
2021-04-01 09:15:28 +00:00
Tim Neutkens
0d5baf2c70
Mark this.router protected (#23573)
* Mark this.router protected

Seems that some people (#23558) are using Next.js internals based on the typings that TS generates automatically even though these values are not documented / should not be used in applications. This ensures the router value on Server is not used by accident.

* Mark all variables as protected

https://github.com/vercel/next.js/issues/23349

* fix type error

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2021-03-31 11:37:44 -05:00
Tim Neutkens
ce7f2b8329 v10.1.3-canary.0 2021-03-31 10:27:33 +02:00
Shu Ding
7adfce23ab
Fix memory leak in image optimization (#23565)
This RP fixes the problem that the image optimization API uses a large amount of memory, and is not correctly freed afterwards. There're multiple causes of this problem:

### 1. Too many WebAssembly instances are created

We used to do all the image processing operations (decode, resize, rotate, encodeJpeg, encodePng, encodeWebp) inside each worker thread, where each operation creates at least one WASM instance, and we create `os.cpus().length - 1` workers by default. That means in the worst case, there will be `N*6` WASM instances created (N is the number of CPU cores minus one).

This PR changes it to a pipeline-like architecture: there will be at most 6 workers, and the same type of operations will always be assigned to the same worker. With this change, 6 WASM instances will be created in the worst case.

### 2. WebAssembly memory can't be deallocated

It's known that [WebAssembly can't simply deallocate its memory as of today](https://stackoverflow.com/a/51544868/2424786). And due to the implementation/design of the WASM modules that we are using, they're not very suitable for long-running cases and it's more like a one-off use. For each operation like resize, it will allocate **new memory** to store that data. So the memory will increase quickly as more images are processed.

The fix is to get rid of `execOnce` for WASM module initializations, so each time a new WASM module will be created and the old module will be GC'd entirely as there's no reference to it. That's the only and easiest way to free the memory use of a WASM module AFAIK.

### 3. WebAssembly memory isn't correctly freed after finishing the operation

`wasm-bindgen` generates code with global variables like `cachegetUint8Memory0` and `wasm` that always hold the WASM memory as a reference. We need to manually clean them up after finishing each operation. 

This PR ensures that these variables will be deleted so the memory overhead can go back to 0 when an operation is finished.

### 4. Memory leak inside event listeners

`emscripten` generates code with global error listener registration (without cleaning them up): https://github.com/vercel/next.js/blob/99a4ea6/packages/next/next-server/server/lib/squoosh/webp/webp_node_dec.js#L39-L43

And the listener has references to the WASM instance directly or indirectly: https://github.com/vercel/next.js/blob/99a4ea6/packages/next/next-server/server/lib/squoosh/webp/webp_node_dec.js#L183-L192 (`e`, `y`, `r`).

That means whenever a WASM module is created (emscripten), its memory will be kept by the global scope. And when we replace the WASM module with a new one, the newer will be added again and the old will still be referenced, which causes a leak.

Since we're running them inside worker threads (which will retry on fail), this PR simply removes these listeners.

### Test

Here're some statistics showing that these changes have improved the memory usage a lot (the app I'm using to test has one page of 20 high-res PNGs):

Before this PR (`next@10.1.0`):

<img src="https://user-images.githubusercontent.com/3676859/113058480-c3496100-91e0-11eb-9e5a-b325e484adac.png" width="500">

Memory went from ~250MB to 3.2GB (peak: 3.5GB) and never decreased again.

With fix 1 applied:

<img src="https://user-images.githubusercontent.com/3676859/113059060-921d6080-91e1-11eb-8ac6-83c70c1f2f75.png" width="500">

Memory went from ~280MB to 1.5GB (peak: 2GB).

With fix 1+2 applied:

<img src="https://user-images.githubusercontent.com/3676859/113059207-bf6a0e80-91e1-11eb-845a-870944f9e116.png" width="500">

Memory went from ~280MB to 1.1GB (peak: 1.6GB).

With fix 1+2+3+4 applied:

<img src="https://user-images.githubusercontent.com/3676859/113059362-ec1e2600-91e1-11eb-8d9a-8fbce8808802.png" width="500">

It's back to normal; memory changed from ~300MB to ~480MB, peaked at 1.2GB. You can clearly see that GC is working correctly here.

---

## Bug

- [x] Related issues #23189, #23436
- [ ] Integration tests added

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.

## Documentation / Examples

- [ ] Make sure the linting passes
2021-03-31 08:24:42 +00:00
Tim Neutkens
1ff6057b3a v10.1.2 2021-03-30 10:32:36 +02:00
Tim Neutkens
1344e2dee2 v10.1.2-canary.0 2021-03-30 10:31:45 +02:00
Joe Haddad
eecc3342cb
Temporarily remove experimental ESLint integration (#23521)
This pull request **temporarily** removes ESLint, as it was not landed in accordance with our standard experimental policies. We are fully committed to landing this change again.

This is being reverted because:

- Next.js has very strict goals for its install size. This feature resulted in adding over 17MB, or a 43.6% increase.
- The feature was not first landed under the `experimental` key in `next.config.js`, rather, it was added under the stable namespace (top-level)
- Using the feature doesn't do a "guided setup" like TypeScript, it should ask you to "bring your own" dependencies for ESLint
- It uses a undesirable ESLint plugin name: `plugin:@next/next/recommended`. This should read out as strictly `next`, or as short as we can get it.
- Does not provide actionable warnings (missing link to resolve issue)
- Does not follow appropriate console output styling. We need to revisit how these are presented.

To re-land this, we need to ensure the following minimums are met:
- Very minor change in install size
- Fully experimental (i.e. flagged) with warnings
- Finalized package name and configuration shape, preferably so we can do ` { extends: 'next' } `.
2021-03-30 08:26:35 +00:00
Tim Neutkens
cd46241349 v10.1.1 2021-03-29 18:02:58 +02:00
Tim Neutkens
b73816b2b4 v10.1.1-canary.0 2021-03-29 18:00:50 +02:00
Tim Neutkens
2ec2ea8786
Make eslint opt-in until it lands on stable (#23509) 2021-03-29 17:58:55 +02:00
Tim Neutkens
fc286d6e19 v10.1.0 2021-03-29 16:56:57 +02:00
Tim Neutkens
378ba1d2eb v10.0.10-canary.14 2021-03-29 16:54:12 +02:00
Tim Neutkens
d40a804dd3 v10.0.10-canary.13 2021-03-29 14:01:21 +02:00
Tim Neutkens
46fa9b6421
Temporarily remove the automatic opt-in for webpack5 (#23497) 2021-03-29 13:42:04 +02:00
Tim Neutkens
cd9bb986eb
Add os-browserify dep (#23354)
Co-authored-by: Tobias Koppers <tobias.koppers@googlemail.com>
Co-authored-by: Joe Haddad <joe.haddad@zeit.co>
Co-authored-by: JJ Kasper <jj@jjsweb.site>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2021-03-29 10:25:27 +02:00
Tim Neutkens
b34a0c98fa
Update err.sh links to use nextjs.org/docs/messages instead (#23353) 2021-03-29 10:25:00 +02:00
JJ Kasper
f28ea89aa7
v10.0.10-canary.12 2021-03-26 11:02:54 -05:00
JJ Kasper
d130f63c41
Add handling fo beforeFiles, afterFiles, and fallback rewrites (#23407)
This adds support for returning an object from `rewrites` in `next.config.js` with `beforeFiles`, `afterFiles`, and `fallback` to allow specifying rewrites at different stages of routing. The existing support for returning an array for rewrites is still supported and behaves the same way. The documentation has been updated to include information on these new stages that can be rewritten and removes the outdated note of rewrites not being able to override pages. 



## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [x] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.

## Documentation / Examples

- [ ] Make sure the linting passes
2021-03-26 15:19:48 +00:00
JJ Kasper
9f5b61d091
v10.0.10-canary.11 2021-03-24 15:51:14 -05:00
JJ Kasper
a6c0d76ebb
Run server client/server builds serially (#23371)
Previously we special cased serverless builds and ran the client/server builds serially to allow the server build to load manifests produced in the client. To help with memory usage and for consistency this updates server mode to build in the same way.  

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.

## Documentation / Examples

- [ ] Make sure the linting passes
2021-03-24 20:50:49 +00:00
Shu Ding
98211405a6
Make sure the image optimization endpoint only response with images (#23366)
If the upstream MIME type isn't prefixed with `image/`, the endpoint should directly response with a 400 error.

## Bug

- [x] Fixes #23312
- [x] Integration tests added

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.

## Documentation / Examples

- [ ] Make sure the linting passes
2021-03-24 17:59:00 +00:00
JJ Kasper
1dae228877
v10.0.10-canary.10 2021-03-24 12:05:28 -05:00
JJ Kasper
75c721c583
Add has route field (#22341)
This adds support for a `has` field to `rewrites`, `redirects`, and `headers` to allow matching against `header`, `cookie`, and `query` values. Documentation and additional tests for the feature is also added in this PR. 

Closes: https://github.com/vercel/next.js/issues/22345
2021-03-24 16:50:16 +00:00
Tobias Koppers
1383bbffa1
upgrade webpack to 5.28.0 (#23350)
fixes some bugs and improves performance

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.

## Documentation / Examples

- [ ] Make sure the linting passes
2021-03-24 13:47:52 +00:00
Tim Neutkens
34f98451bd v10.0.10-canary.9 2021-03-24 14:12:21 +01:00
Joe Haddad
437c35f121
feat: automatically enable webpack 5 (#22323)
Co-authored-by: Tim Neutkens <timneutkens@me.com>
Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
2021-03-24 14:10:10 +01:00
Shu Ding
4c63456543
Remove visibility: inherit from the image component (#23329)
This is a follow-up PR of #19052, where `visibility: inherit` was mistakenly added back. It was removed in #23278.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.

## Documentation / Examples

- [ ] Make sure the linting passes
2021-03-23 22:11:37 +00:00
JJ Kasper
a16f7a3829
v10.0.10-canary.8 2021-03-23 16:35:15 -05:00
Houssein Djirdeh
e5ef60fecb
Add ESLint to Next.js (#22437)
For #22228

This PR:

- Adds ESLint to toolchain
  - Included by default for builds (`next build`)
  - Can be enabled for development (`next dev`)
  - Custom formatter built for output
- Adds appropriate tests
- Adds two documentation pages
2021-03-23 21:32:42 +00:00
Tim Neutkens
c219c1d9ce
Add polyfills for node_modules that are covered in webpack 4 to webpack 5 (#23316)
Brings back the remaining Node.js module polyfills to not break existing apps upgrading from webpack 4 to webpack 5.

Fixes #23169



## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.

## Documentation / Examples

- [ ] Make sure the linting passes
2021-03-23 20:59:42 +00:00
Bruno Crosier
48dd9954d8
Add fallback for <Image /> component when JavaScript is disabled in browser (#19052)
The current `<Image />` component does not fallback gracefully when JavaScript is disabled in the client / browser.

You can test this with the [official Next/Image example](https://csb-4k0kr-p8ya8f304.vercel.app/), by disabling JavaScript in the browser's DevTools. Video demo: https://streamable.com/frkvw9

This PR aims to fix this behaviour by using `<noscript></noscript>` tags to conditionally display a standard `<img>` element using the `props` passed to `<Image />` when JavaScript is disabled.

For browser sessions where JavaScript is enabled, this will not cause an increase in network requests, so there should be no downside.

One area where this PR is a bit "hacky" is that it uses a negative `margin-top` to counteract `sizerStyle.paddingTop`. From what I can tell, `sizerStyle.paddingTop` is generated on the server side, where we can not know ahead of time whether JavaScript is enabled in the browser - hence why I've opted for this solution. 

Fixes #19223
Fixes #21214
2021-03-23 19:25:00 +00:00
Shu Ding
c8680a344f
Remove visibility: hidden from the image component (#23278)
This PR removes the `visibility` style property change from next/image. It was previously added in #18195 to fix a bug that when no `src` is set, and that bug is not valid anymore as all images will always have `src` (and a fallback too).

It also fixes the problem that screen readers ignore elements with `visibility: hidden`.

Fixes #23201.

## Bug

- [x] Related issues #23201
- [ ] Integration tests added

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.

## Documentation / Examples

- [ ] Make sure the linting passes
2021-03-22 19:20:52 +00:00
Tim Neutkens
fe80128915 v10.0.10-canary.7 2021-03-22 11:35:23 +01:00
Tobias Koppers
c9a2e5b8f0
upgrade webpack to 5.27.1 (#23224)
fixes #23125

fixes https://github.com/tailwindlabs/tailwindcss-jit/issues/54

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.

## Documentation / Examples

- [ ] Make sure the linting passes
2021-03-22 09:21:51 +00:00
Shu Ding
89ec21ed68
Fix wrong source path resolved from the stack frame to not expose internal code (#23203)
Currently Next.js exposes internal code in the error overlay if certain errors were created from the user code. Some examples were attached in #20776.

We can clearly see that the path is wrong (`../next-server`), it should be `./node_modules/next/dist/next-server`:

![CleanShot 2021-03-19 at 01 33 04](https://user-images.githubusercontent.com/3676859/111670728-1ae7e400-8853-11eb-9213-3b359798900e.png)

The root cause is the `__nextjs_original-stack-frame` middleware resolves the file path with the following code:

```js
path.resolve(
  rootDirectory,
  getSourcePath(sourcePosition.source)
)
```

where `rootDirectory` is the **app root**, but `sourcePosition.source` comes from the module path, which is relative to the path of the `next` binary, not the app root. 

That explains why we see `../next-server` from the error above, because it's relative to `./node_modules/next/bin/next`.

Because of that, the resolved result will never have `node_modules` in its path and it won't be filtered by the error overlay in the UI. Here's a screenshot of the frame object in the UI:

![CleanShot 2021-03-18 at 23 01 29@2x](https://user-images.githubusercontent.com/3676859/111670062-65b52c00-8852-11eb-9293-3a6e5b7c4b9b.png)

And the filter we use to determine if a frame is expanded or not only depends on `body.originalStackFrame`:

```js
expanded: !Boolean(
  body.originalStackFrame?.file?.includes('node_modules') ?? true
)
```

So this PR also adds `source.file` check to ensure they will be ignored (not necessary because we fixed the path resolving).

Fixes #20776.
2021-03-20 19:34:45 +00:00
Tobias Koppers
8c72806ace
add separate progress output for typechecking (#23226)
## Bug

- [x] Related issues linked using `fixes #number`
- [ ] Integration tests added

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.

## Documentation / Examples

- [ ] Make sure the linting passes

Fixes #23240
2021-03-20 19:11:45 +00:00
Shu Ding
32c435d819
Experimental feature for allowing importing Typescript files outside of the root directory (#22867)
This PR attempts to provide an option to allow importing TS/TSX from outside of the current Next.js project root directory. Although this goes against the design decision that no source code should be imported from outside of root and [might bring tons of issues](https://github.com/vercel/next.js/issues/19928#issuecomment-741596557), it will still be helpful in some monorepo use cases.

This PR assumes that the external files are following the same language syntax rules and under the same tooling versions as the source code inside your project root. And it's also not allowed to enable the `baseUrl` feature in the external directory (as the project should only have 1 import base URL).

X-ref: #9474, #15569, #19928, #20374.
2021-03-19 16:43:46 +00:00
JJ Kasper
79066aee8e
v10.0.10-canary.6 2021-03-19 11:20:13 -05:00
Tim Neutkens
2874bbc61c v10.0.10-canary.5 2021-03-19 09:50:42 +01:00
Sam Ko
e71014609e
Fix invalid console.error link (#23213) 2021-03-19 09:22:19 +01:00
JJ Kasper
b6bb110aca
Ensure process exits after build completes (#23207)
This ensures we exit the build process after the build completes even if timers/connections are left open since this can cause the process to hang indefinitely. This was the previous behavior although got changed un-intentionally in e27b7e996d

This updates our production test with an open timer to ensure it doesn't block the process from completing.
2021-03-19 08:06:28 +00:00
Shu Ding
241a916e03
Improve image optimizer to only create 1 worker thread (#23188)
As stated in #23157, this PR merges all the operations into 1 worker thread (`processBuffer` in `impl.ts`) and only pass a list of operation names and args into the worker. This should improve the speed and memory usage of next/image.

Fixes #23157. X-ref: #22925.
2021-03-18 15:51:36 +00:00
Tim Neutkens
ea374d8156 v10.0.10-canary.4 2021-03-18 13:54:25 +01:00
Tobias Koppers
b267635d63
rename to NEXT_WEBPACK_LOGGING (#23186)
as vercel doesn't allow env vars starting with _
2021-03-18 12:53:41 +00:00