Commit graph

1948 commits

Author SHA1 Message Date
JJ Kasper
55d8a14e8a
Fix flakey next/link react streaming test (#32351)
x-ref: https://github.com/vercel/next.js/runs/4477101349?check_suite_focus=true
x-ref: https://github.com/vercel/next.js/runs/4475354509?check_suite_focus=true
x-ref: https://github.com/vercel/next.js/runs/4474805941?check_suite_focus=true
2021-12-10 07:43:55 +00:00
JJ Kasper
3ca0ac7f74
Update AMP validation tests (#32327) 2021-12-09 12:27:38 -06:00
Jiachi Liu
b044f42334
Fix RSC link navigation (#32303)
Co-authored-by: JJ Kasper <jj@jjsweb.site>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2021-12-09 14:45:22 +01:00
JJ Kasper
9c1b183a9c
Fix styled-jsx tests from swc bump (#32297)
Fixes failing tests from swc bump in https://github.com/vercel/next.js/pull/32210 which removed some whitespace. 

x-ref: https://github.com/vercel/next.js/runs/4456734159?check_suite_focus=true
x-ref: https://github.com/vercel/next.js/runs/4461064714?check_suite_focus=true
2021-12-08 18:59:09 +00:00
Donny/강동윤
4ce49b79a2
Update swc (#32210)
Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
2021-12-08 18:54:21 +01:00
Axel Mohamed SADAT
d459b5f99a
fix(NODE_ENV): Warn when launching start or build on development (#14033)
The PR aims to fix [#14022](https://github.com/vercel/next.js/issues/14022)

Co-authored-by: Tim Neutkens <6324199+timneutkens@users.noreply.github.com>
2021-12-07 14:25:39 +00:00
Maia Teegarden
21f8c6a7c3
Chore/load bindings improvements (#32191)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2021-12-07 11:14:38 +01:00
Keen Yee Liau
53e52fefc3
telemetry: collect feature usage for linting during build (#32022)
Currently, we have telemetry to measure how ESLint is invoked,
but we do not have telemetry that tells us how many users have
disabled ESLint during build.

This commit adds a new feature, `build lint` to track this metric.



## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

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

## Documentation / Examples

- [ ] Make sure the linting passes by running `yarn lint`
2021-12-07 02:41:31 +00:00
Gerald Monaco
9bcf678e64
Revert support for render prop in <Main /> (#32184)
Reverts support for render prop in `<Main />` in `Document`. This was added just to support the `useFlushEffect` hook, but we've tweaked the design a bit, moving it to `App`.
2021-12-06 21:22:05 +00:00
Tim Neutkens
980e16998c
Fix document type import path (#32117)
There was a mistake in #32077 which imported a different module than _document in the _document .d.ts file. I found that we didn't have a test for a custom _document.tsx and _app.tsx with TypeScript, so I've added one that fails on canary and passes with this fix to ensure this does not happen in the future.

Fixes #32110




## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

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

## Documentation / Examples

- [ ] Make sure the linting passes by running `yarn lint`
2021-12-04 10:23:15 +00:00
JJ Kasper
f0fd4962e9
Revert "Fix running server with Polyfilled fetch (#31935)" (#32100)
This reverts commit 1c199a5e4a.
2021-12-03 15:31:52 -06:00
JJ Kasper
6d98b4fb43
Ensure invalid URLs respond with 400 correctly (#32092)
This ensures we catch any errors in `handleRequest` so that we can respond with a 400 for invalid requests. 

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

Fixes: https://github.com/vercel/next.js/issues/32075
Closes: https://github.com/vercel/next.js/pull/32080
2021-12-03 17:31:09 +00:00
Javi Velasco
1c199a5e4a
Fix running server with Polyfilled fetch (#31935)
This PR fixes #30398

By default Next will polyfill some fetch APIs (Request, Response, Header and fetch) only if fetch is not found in the global scope in certain entry points. If we have a custom server which is adding a global fetch (and only fetch) at the very top then the rest of APIs will not be polyfilled.

This PR adds a test on the custom server where we can add a custom polyfill for fetch with an env variable. This reproduces the issue since next-server.js will be required without having a polyfill for Response which makes it fail on requiring NextResponse. Then we remove the code that checks for subrequests to happen within the **sandbox** so that we don't need to polyfill `next-server` anymore.

The we also introduce an improvement on how we handle relative requests. Since #31858 introduced a `port` and `hostname` options for the server, we can always pass absolute URLs to the Middleware so we can always use the original `nextUrl` to pass it to fetch. This brings a lot of simplification for `NextURL` since we don't have to consider relative URLs no more.

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [x] Errors have helpful link attached, see `contributing.md`
2021-12-03 16:35:28 +00:00
JJ Kasper
abe53727b0
Include page for export errors for easier debugging (#32013)
This makes sure to include the `page` for dynamic routes when they encounter an error during prerendering as we currently only include the `path`, e.g. before we would only show `/blog/first` and now we show `/blog/[slug]: /blog/first` 

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

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

## Documentation / Examples

- [ ] Make sure the linting passes by running `yarn lint`
2021-12-02 19:31:36 +00:00
JJ Kasper
cc9e1ea3a1
Fix middleware types with skipLibCheck: false (#32025)
This ensures type checking passes correctly for middleware types when `skipLibCheck: false` is set in `tsconfig.json`. This also moves the `middleware-types` to be an isolated test to ensure it isn't relying on any monorepo dependencies. 

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

Fixes: https://github.com/vercel/next.js/issues/31992#issuecomment-984174872
2021-12-02 18:49:49 +00:00
Eric Matthys
f225179378
fix(Link): Do not ignore onMouseEnter prop with absolute href (#32012)
Fixes #22733

Regardless of whether it's recommended that Link be used with external href values or not, they can be used and `onMouseEnter` being swallowed with an external href value is unexpected behavior.

## Bug

- [x] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [x] Make sure the linting passes by running `yarn lint`
2021-12-01 18:32:27 +00:00
Jiachi Liu
928c77958e
Resolve streaming data for flight requests (#32010)
## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
2021-12-01 15:48:31 +00:00
Shu Ding
b7fb315cd7
Ensure that external modules are not bundled into the client for RSC (#31968)
If importing an external module inside a Server Component (`.server.js`), it shouldn't be bundled into the client. Only client components should be kept.

## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

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

## Documentation / Examples

- [ ] Make sure the linting passes by running `yarn lint`
2021-11-30 22:54:47 +00:00
Jeff
a2fa637ab3
fix(types): add missing ua types for NextRequest (#31901)
* fix(types): add missing ua type for NextRequest

add missing ua string type on NextRequest["ua"], returns full agent as string

* Update UserAgent type

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2021-11-30 15:59:02 -06:00
Steven
b01a6ba665
Add TS types for NextMiddleware (#30578)
This allows TypeScript users to have type safety for middleware functions.

- Closes #30490 

Co-authored-by: Lee Robinson <9113740+leerob@users.noreply.github.com>
Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2021-11-30 20:43:40 +00:00
Tim Koopman
8784682a74
Escape string when converting to regexp (#31791)
fixes #31411

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`


Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2021-11-30 19:15:13 +00:00
Jiachi Liu
d2cef24d5d
Fix image related link prop warning with react 18 beta (#31895)
## Bug

Fixes #31892 

react 18: requires camelcase for those props 
```
Warning: Invalid DOM property `imagesrcset`. Did you mean `imageSrcSet`
```
react 17: requires lowercase for those props

```
Warning: React does not recognize the `imageSrcSet` prop on a DOM element.
```

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`


### Utils

* Add command `yarn next-react-18 test/integration/any-react-18-app/`
* Add util `withReact18`

```js
const withReact18 = require('../../react-18/test/with-react-18')

module.exports = withReact18({
  experimental: {
    concurrentFeatures: true,
  },
})
```
2021-11-30 18:37:22 +00:00
Jiachi Liu
85e578a906
Enable default functional document when concurrentFeatures is enabled (#31954)
## Bug

Fixes: #31675 

Functional document without gIP should be enabled when streaming is enabled, even without rsc

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
2021-11-30 12:52:14 +00:00
Jiachi Liu
6920c0201b
Remove unpurpose test (#31898)
The test from #31784 can pass with or without the source code change in that PR.
I cannot repro it. The writable is true on build in the provided case
2021-11-29 15:03:13 +00:00
Michel Krämer
c8457e3abf
Fix disabling of built-in CSS support if there is a custom loader (#31078)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Co-authored-by: Lee Robinson <me@leerob.io>
2021-11-29 15:19:39 +01:00
Steven
b1be180d7d
Fix: Cannot assign to read only property 'children' (#31784)
- Closes #28498 

Co-authored-by: Jesse Jafa <12380586+awareness481@users.noreply.github.com>
2021-11-28 21:19:57 +00:00
Jiachi Liu
cf64e9130e
fix: rsc headers (#31854)
`headers` type should align with `NodeHeaders`
2021-11-26 18:04:36 +00:00
Juny
4c05de3c7e
fix amp validator message format (#31018)
## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

fixes https://github.com/vercel/next.js/issues/31012

I referred to the previous code.

```
    if (errors == null) {
      if (Object.keys(amp).length > 0) {
        warnings = (warnings || []).concat(formatAmpMessages(amp) || [])
        if (!warnings.length) warnings = null
      }
    }
```

https://github.com/vercel/next.js/pull/29753/files
2021-11-26 15:13:09 +00:00
Javi Velasco
2e5218c778
Fix hydration middleware effects (#31800)
Whenever we trigger a route change in the client we check if there route we are navigating to is affected by a middleware. When this is the case we run a preflight and in case there is an effect that tells us that the middleware is responding with content we force a _refresh_. This is fine for navigation in general but it is not ok when the change is triggered for hydration. For example, in cases where the rendered page is a dynamic page this triggers an infinite reload.

In this PR we add a test where we add a `_middleware` that proxies to a dynamic path. When making a request to `/interface/root-subrequest` there will be a middleware that simply performs a fetch against localhost for the same `/interface/root-subrequest`. The new request will skip the middleware to avoid loops and then render the dynamic page. Then client will force a change for hydration resulting in a preflight request that tells that the client must refresh because for that path there is a middleware writing content.

Then we add a fix which simply consist of checking the internal option that tells when a change is triggered for hydration and skip the preflight in such scenario.

## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

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

## Documentation / Examples

- [ ] Make sure the linting passes by running `yarn lint`
2021-11-26 12:46:57 +00:00
Tim Neutkens
92b397f2b7
Lazy-load postcss (#31762)
Co-authored-by: Tobias Koppers <1365881+sokra@users.noreply.github.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Co-authored-by: Tobias Koppers <tobias.koppers@googlemail.com>
2021-11-25 18:41:20 +01:00
JJ Kasper
4b538e9879
Add error link when hydration error occurs (#31519)
This adds an error document/link for hydration errors to help users debug these easier. While looking at adding this also noticed a typo in the dev-overlay which is fixed. 

<details>

<summary>screenshot</summary>

<img width="1109" alt="Screen Shot 2021-11-16 at 15 56 29" src="https://user-images.githubusercontent.com/22380829/142078200-6c036ed9-ca7f-4d26-ae07-eb9bd89e991a.png">

</details>

## Documentation / Examples

- [x] Make sure the linting passes by running `yarn lint`


Co-authored-by: Tim Neutkens <6324199+timneutkens@users.noreply.github.com>
2021-11-23 13:10:56 +00:00
Jiachi Liu
7f58a2e49f
Add cookies and headers for request using in RSC (#31623)
* Passdown the request with richer information
* test: access request header as prop from gSSP
2021-11-22 18:53:22 +00:00
Tobias Koppers
d971262603
add test case (#31691)
fixes #30567
2021-11-22 15:09:57 +00:00
Maia Teegarden
a79d4fc366
Extract next-swc Rust code into its own package (#31635)
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>
2021-11-21 12:59:56 +01:00
JJ Kasper
e8ca334d42
Fix non-concurrent function _document (#31628)
This ensures functional `_document` is rendered correctly when not using concurrent mode. 

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

Fixes: https://github.com/vercel/next.js/issues/31593
x-ref: https://github.com/vercel/next.js/pull/30156
2021-11-19 19:41:19 +00:00
JJ Kasper
1d9007307f
Fix accessing router before ready for HMR ping (#31588)
* Fix accessing router before ready for HMR ping

* update test name

* lint-fix
2021-11-18 16:23:21 -06:00
Javi Velasco
5a3d558c9f
Fix HMR for middleware #30791 (#31548)
Fixes #30791

The issue is that with Middleware we are introducing client compilation on a new layer. When a middleware changes (or is dropped after some time), Webpack reorganizes non-user modules as they are duplicated across different layer. This is currently triggering a full reload.

This also brings tests for HMR:
- Refresh on a Middleware change
- HMR works after a middleware compilation change.

Co-authored-by: Tobias Koppers <1365881+sokra@users.noreply.github.com>
2021-11-18 18:23:52 +00:00
Steven
44b4dbcd41
Adjust AVIF size so that its smaller than WebP size (#31494)
Generally, AVIF quality can be lower compared to WebP so we can adjust this for the user so that it looks roughly the same depending on if the browser supports AVIF or WebP.

- Fixes #31254 
- Related to https://github.com/lovell/sharp/issues/2850
2021-11-17 20:31:16 +00:00
Gerald Monaco
0cf7061859
Make missing Document components an error (#31505)
* Make missing document components an error

* Fix broken tests
2021-11-17 13:34:16 -06:00
Keen Yee Liau
9ab1709175
telemetry: track usage of 'optimizeFonts' (#31522)
`optimizeFonts` is enabled by default, but the Aurora team would like
to find out how many users explicitly turn it off.
2021-11-17 13:33:37 -06:00
Jiachi Liu
055e28ef81
Ensure only one doctype is rendered (#31534)
React-dom renders doctype automatically when `<html>` is detected. We should append `DOCTYPE` prefix only when necessary.
x-ref: https://github.com/facebook/react/pull/21680

## Bug

![image](https://user-images.githubusercontent.com/4800338/142215292-4af4a61d-2d75-48ae-a31a-0af641c72dcf.png)

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
2021-11-17 14:57:48 +00:00
Steven
d87dc2b5a0
Add detection for Google-PageRenderer bot (#31521)
- Fixes https://github.com/vercel/next.js/discussions/31482
2021-11-17 03:49:37 +00:00
Jiachi Liu
55ab4f06b7
Use _error for development in streaming (#31466)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2021-11-16 20:18:57 +01:00
Tobias Koppers
b79591cdaf
simplify output messages (#31454)
remove all `client/server/middleware only` messages and show `client and server` instead only when both compilers has been used.
2021-11-16 15:57:30 +00:00
Yamagishi Kazutoshi
32f0c9a403
Support ESLint v8 (#29865)
Co-authored-by: Michaël De Boey <info@michaeldeboey.be>
Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
2021-11-16 10:18:27 +01:00
JJ Kasper
be03a1d17b
Remove .only and ensure jest lint rules apply for all tests (#31456) 2021-11-15 12:46:12 -06:00
Jiachi Liu
ef5795327a
Close stream when fatal error occurs (#31164)
* support custom 500 error in streaming

* remove unused imports
2021-11-15 11:49:50 -06:00
Steven
eb0bd63af4
Fix basePath replacing server-side and normalizeLocalePath() when path is empty string (#30978)
This fixes our `basePath` detection/replacing server-side as we were incorrectly considering `/docss` a match for a `basePath` of `/docs` which caused us to have an unexpected value in the `normalizeLocalePath` function. 

- Fixes #22429
- Regression introduced in #17757 
- Fixes: https://github.com/vercel/next.js/issues/31423

Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2021-11-15 17:33:21 +00:00
Matt Kane
9952cc79db
Don't proxy middleware if host is the same (#31180)
This changes the check for whether a rewrite is internal or if it should be proxied. Currently it checks if `protocol` is unset, which is only the case for relative URLs or localhost. This means that requests where there is a hostname set, or if localhost is specified in another way such as `127.0.0.1`, then it will be proxied, which potentially causes a proxy loop or ssl error. This PR changes the test so that it also checks if the hosts match, and only proxies if they are different.

Fixes #31179 

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
2021-11-13 00:20:13 +00:00
Hiroshi Ogawa
4a22059b11
fix(30724): clear "x-middleware-next" header when chaining middlewares (#30866)
* fix(30724): clear "x-middleware-next" header when chaining middlewares

* refactor: do not accumulate "x-middleware-next" header

* test: fix grammar of test case title

* Update packages/next/server/next-server.ts

Co-authored-by: Javi Velasco <javier.velasco86@gmail.com>
2021-11-12 17:44:17 -06:00