Commit graph

2198 commits

Author SHA1 Message Date
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
Luis Alvarez D
77150dac79
Include submodules in exported type definition (#28316) 2021-11-26 14:46:56 +01:00
Gerrit Alex
d38dd3d7e6
fix: support function components in _document in no-page-custom-font (#31560) 2021-11-26 14:27:13 +01: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
Dominik Ferber
feabd54f6b
avoid mutating response.cookie options (#31679)
Previously `response.cookie(name, value, options)` would mutate the passed in `options` which lead to unexpected behaviour as described in #31666.

This PR clones the `options` argument before mutating it.

## Bug

- [x] 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.
- [x] 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

- [x] Make sure the linting passes by running `yarn lint`
2021-11-22 11:20:01 +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
Kiko Beats
f52211bad3
fix(middleware): consider localhost variations (#31603)
Since `localhost` is actually an alias for `127.0.0.1` that points to loopback, we should take that into consideration at `NextURL` when we handle local URLs.

The implementation is based on [is-localhost-url](https://github.com/Kikobeats/is-localhost-url); I added some tests over local URLs variations present at the library to ensure other variations are working fine.

Additionally, I refactor some things over the code to avoid doing the same twice and added some legibility that is always welcome when you are working with URLs stuff.

 closes https://github.com/vercel/next.js/issues/31533
2021-11-19 21:24:22 +00: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
Nils Kaspersson
d1ce7b7c58
[ESLint] Prevent no-html-link-for-pages from warning for static files (#31495)
The rule [`no-html-link-for-pages`](https://nextjs.org/docs/messages/no-html-link-for-pages) will incorrectly flag an `<a>`-tag intended to download a local asset. This PR adds an exception to the rule for any anchor element with a `download` attribute.

Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2021-11-19 03:39:36 +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
Kiko Beats
593d943cd0
NextResponse: add .json static method (#31483)
closes: https://github.com/vercel/next.js/issues/31196

This new API was suggested in a previous version of this feature:
https://github.com/vercel/next.js/pull/31024#discussion_r745035448

Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2021-11-16 18:38:47 +00: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
a9eb0de8e7
Ensure swc dep is copied for isolated tests (#31462) 2021-11-15 13:55:32 -06:00
Kiko Beats
b51a020941
middleware: add request referrer support (#31343)
closes: https://github.com/vercel/next.js/issues/30353

According with spec, `'about:client'` is the default value is the user doesn't provide it.

It needs to add a test there, looks like there no unit tests for these classes 🤔
2021-11-15 19:52:44 +00: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
Tim Neutkens
e0531e30f4
Add support for legacy decorators through tsconfig/jsconfig (#31376) 2021-11-13 18:26:13 +01: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
Thibaut SABOT
d1adf1d503
Add eslint rule to prevent importing next/server outside of _middleware (#30973)
* Add eslint rule to prevent importing next/server outside of _middleware

* add error to manifest.json

Co-authored-by: Javi Velasco <javier.velasco86@gmail.com>
2021-11-12 17:44:39 -06: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
Tim Neutkens
a4692d400d
Add support for jsxImportSource in tsconfig/jsconfig (#31358) 2021-11-12 21:51:43 +01:00
JJ Kasper
06f3d398b1
Ensure NODE_ENV is replaced correctly with swc (#31274) 2021-11-12 13:59:21 -06:00
Filip Skokan
f796ea3e7d
fix(middleware): fetch resource may be a URL instance (or any stringifiable value) (#31260)
The `resource` argument[^1] in fetch may also be an instance of URL (or any other stringifiable value) but the sandbox variant of middlewares doesn't support that.

```js
export async function middleware(req, ev) {
  await fetch(new URL('https://www.googleapis.com/oauth2/v3/certs'), {
    redirect: 'manual',
    method: 'GET',
  })

  return new Response(JSON.stringify({}), { status: 200 });
}
```

This is fixing the use of e.g. URL instance in `fetch`.

```
TypeError: initurl.startsWith is not a function
  at getFetchURL (/my-next-app/node_modules/next/dist/server/web/sandbox/sandbox.js:246:17)
  at fetch (/my-next-app/node_modules/next/dist/server/web/sandbox/sandbox.js:77:29)
  at Object.middleware [as handler] (webpack-internal:///./pages/_middleware.js:86:15)
  at async adapter (webpack-internal:///./node_modules/next/dist/server/web/adapter.js:30:22)
  at async DevServer.runMiddleware (/my-next-app/node_modules/next/dist/server/next-server.js:430:26)
  at async DevServer.runMiddleware (/my-next-app/node_modules/next/dist/server/dev/next-dev-server.js:394:28)
  at async Object.fn (/my-next-app/node_modules/next/dist/server/next-server.js:807:34)
  at async Router.execute (/my-next-app/node_modules/next/dist/server/router.js:211:32)
  at async DevServer.run (/my-next-app/node_modules/next/dist/server/next-server.js:1115:29)
  at async DevServer.run (/my-next-app/node_modules/next/dist/server/dev/next-dev-server.js:440:20)
```

[^1]: https://developer.mozilla.org/en-US/docs/Web/API/fetch#parameters
2021-11-12 13:22:27 +00:00
Jiachi Liu
cf206a8392
Resolve stream piper on complete shell for renderToReadableStream (#31186)
1. Align `renderToReadableStream` with `renderToNodeStream`, resolve promise of `NodeWritablePiper` only when `onCompleteShell` is called.
2. update webpack to disable chunk loading for web runtime

Item 1 is the preparation for middleware-ssr-loader. Then we can do the following there

```js
try {
   result = await renderToHTML(page)
} catch (e) {
   result = await renderToHTML(errorPage)
}
result.pipe(renderResult)
```
2021-11-12 00:00:54 +00:00
Alexander Savelyev
0c04f96e9b
bugfix/second-locale-in-pathname remove console.log (#31289)
Sorry, I forgot to remove console.log in a test
2021-11-11 21:54:27 +00:00