Commit graph

5559 commits

Author SHA1 Message Date
Tim Neutkens
1b4e2ccd63 v12.1.7-canary.11 2022-05-23 13:35:21 +02:00
Sukka
d1122f8282
perf: run type check and eslint in parallel (#37105) 2022-05-23 11:25:09 +02:00
Damien Simonin Feugas
4e6b6a5b86
feat(middleware): issues warnings when using node.js global APIs in middleware (#36980) 2022-05-23 11:07:26 +02:00
Charles Stover
f9ed7954bf
Support TS exactOptionalPropertyTypes (fixes #35280) (#35281)
fixes #35280

Before:

![image](https://user-images.githubusercontent.com/343837/158047041-d4b65f19-c090-496b-b0c1-75faa388ea66.png)

After:

![image](https://user-images.githubusercontent.com/343837/158046975-7393f818-be1a-4d03-99db-643e88595657.png)
2022-05-23 05:26:44 +00:00
Eric Matthys
0d80b113a3
Warn when building a TS project with composite: true and fallback to incremental (#35270)
* Warn when building a TS project with composite: true and fallback to incremental

* lint-fix

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-05-23 00:04:00 -05:00
Dawson Booth
88747a2653
Add JSX.Element to styles type in DocumentInitialProps (#36392)
* Change styles element fragment to array

* update type

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-05-22 23:00:36 -05:00
akfm
ad7f728e2d
fix: Scroll restoration bug caused by idx reset to 0 on reload (#36861)
fix scroll restoration bug

changed key from index to random string, to be inconsistent with session storage when reloading

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-05-22 21:39:12 -05:00
Sharath Challa
11ad65e445
Add eslint rule for not allowing styled-jsx in _document.js (#32678)
## Bug

- [ ] Related issues linked
fixes #32656



Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-05-23 02:32:13 +00:00
mattbrandlysonos
305214476b
fix NextApiRequestCookies and NextApiRequestQuery types (#25532)
Hello! Thanks for making next.js so great.

## Bug

Right now, these types give false confidence. These `key`s are treated as though [a value is defined for _every_ string](https://dev.to/sarioglu/avoiding-unintended-undefined-values-while-using-typescript-record-4igo). However, given an arbitrary request, a particular cookie or query param could be `undefined`.

For example, when building an `/api` endpoint, the code might look like this:

```ts
import type { NextApiRequest, NextApiResponse } from "next"

export default function handler(req: NextApiRequest, res: NextApiResponse) {
  // According to the old types, `value` is a string
  const value = req.cookies.value

  // Type-checking passes but leads to a runtime error when no `value` cookie is provided in the request
  //   Uncaught TypeError: Cannot read property 'toLowerCase' of undefined
  value.toLowerCause()

  // ...
}
```

By using `Partial`, TypeScript now knows that these objects don't have values defined for every `key` and accessing a given `key` might resolve to `undefined`.

---

The only obvious error this caused within this repo was on line 333 of the same file. For better or worse, I ended up casting that cookie value to a `string`. There's a series of `if` statements before it that, I guess, are guaranteeing that it's truly a string. Potentially, that stretch could be refactored such that TypeScript _knows_ it's a string.

Also, I tried to follow the contributing guidelines. However, running `yarn types` kicked out a bunch of errors about overwriting files:

```
$ yarn types
yarn run v1.22.10
$ lerna run types --stream
lerna notice cli v4.0.0
lerna info Executing command in 2 packages: "yarn run types"
@next/env: $ tsc index.ts --declaration --emitDeclarationOnly --declarationDir types --esModuleInterop
next: $ tsc --declaration --emitDeclarationOnly --declarationDir dist
next: error TS5055: Cannot write file '/Users/mbrandly/code/next.js/packages/next/dist/build/index.d.ts' because it would overwrite input file.
next: error TS5055: Cannot write file '/Users/mbrandly/code/next.js/packages/next/dist/build/webpack/plugins/build-manifest-plugin.d.ts' because it would overwrite input file.
...
...
...
```

Let me know if there's anything I can improve here! Thanks again.
2022-05-23 00:48:26 +00:00
Jonathan Pollak
2872df525b
Add missing file in mini-css-extract-plugin (#25691)
Adds the `hmr/hotModuleReplacement.js` file to the compiled output
that is used in
`packages/next/build/webpack/plugins/mini-css-extract-plugin.ts`.

Fixes #25560



## Bug

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


Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-05-23 00:16:50 +00:00
Hannes Bornö
318664562c
next-swc: Improve error message for nested styled jsx tags (#33805)
Before
![image](https://user-images.githubusercontent.com/25056922/151694166-a27a35b6-5fb4-4179-8c88-bd98ede35fea.png)

After
![image](https://user-images.githubusercontent.com/25056922/151758033-65576e5b-e2e8-435d-87b3-9e384b13936b.png)


Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-05-22 22:45:58 +00:00
John Armstrong
78bdbbed1c
next-bundle-analyzer: openAnalyzer option (#36493)
* Add `openAnalyzer` option to next-bundle-analyzer

* Document openAnalyzer option

* add type

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-05-22 17:23:23 -05:00
Motoki saito
b4089f3732
improve getStaticProps error message (#34287)
* improve getStaticProps error message

* Revert "improve getStaticProps error message"

This reverts commit 60544afac1e971d62f3273e2b5600d8b28d94764.

* apply suggestion

* rm .only

* update test

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-05-22 16:50:21 -05:00
Stef
90ada64d05
Add typedef for next-bundle-analyzer (#35075)
* Add typedef for next-bundle-analyzer

* Update package.json

* update type

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-05-22 16:32:20 -05:00
await-ovo
ff37cc9e13
fix: should listen for config file changes when specifying the app directory (#36570)
Fixes: #36569 



## Bug

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

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


Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-05-22 19:42:53 +00:00
Joseph
baed42c79a
fix: Catch hash change errors, and emit a routeChangeError event (#36828)
* fix: Catch hash change errors, and emit a `routeChangeError` event

* Add test

* update test

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-05-22 14:15:08 -05:00
Exortions
ef69aca4df
Merge multiple log statements (#35310)
* Merge multiple log statements

It is inefficient to use multiple console.log satements, and if something is logged to the console in the middle of execution, it will be in the center of the text, making it hard to read.
This pull request merges multiple console.logs into one.

In addition, it reduces the bundle size.

* ensure formatting matches

* update test

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-05-22 13:50:08 -05:00
Gáspár Körtesi
863db9b0e2
keep method when cloning Request, fixes #36522 (#36539)
keep method when cloning Request

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-05-22 12:58:17 -05:00
await-ovo
afbc511d3f
fix: place the charset meta tag at the top of the head (#36561)
Fixes: #36432 



## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [x] 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

- [x] Make sure the linting passes by running `yarn lint`
2022-05-22 17:28:54 +00:00
Sukka
87826ee186
fix(#33081): handle relative path correctly (#36823)
## Bug

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

Fixes #36823 
Closes #33084

The issue is caused by the `isLocalURL` function only checks if a URL starts with `/`, `#` or `?`. So a URL that starts with `.` will not be considered a "local URL". The PR fixes that by introducing a new util function `isAbsoluteUrl` that is fully compliant with [RFC3986](https://tools.ietf.org/html/rfc3986#section-4.3).
2022-05-22 16:43:48 +00:00
Baruch-Adi Hen
e2fde26b59
Fix: Cleaner error message when importing sass without it being installed in dev (#35051)
This PR removes the not-very-helpful stack trace when sass is being used but the npm package is not installed. Fixes #13975

- Fix behavior to show the modified error message if either node-sass OR sass is missing
- dispose of stack trace if the condition above passes
- update the error link to [err.sh](https://err.sh/next.js/install-sass) equivalent 
- update the relevant test to verify the stack trace is omitted and to account for the new link


## Bug

- [x] Related issues linked using `fixes #13975`
- [ ] 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`


Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-05-22 06:56:18 +00:00
hui.liu
11cb49b385
Fix next/link can't jump to non-latin anchors (#36430)
fixes #11109 

## Bug

- [x] 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`
2022-05-22 06:32:11 +00:00
Iaroslav Kolbin
29b3cdf93f
Remove invalid attrs for head html element (#36457)
Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-05-22 00:54:33 -05:00
Justin Goping
9b61b10245
Fix Trusted Types violations from dangerouslySetInnerHTML on style elements (#36751)
Remove dangerouslySetInnerHTML usage in style elements

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-05-22 00:26:54 -05:00
Justin Goping
15ddd20b1b
Enable Trusted Types Compatibility in Webpack (#36750)
Linked to issue #32209.

## 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
The purpose of this PR is to enable Trusted Types compatibility in Webpack. When the app is run in development mode, Webpack is currently set to use an [eval-source-map](5a16b1a26f/packages/next/build/webpack/config/blocks/base.ts (L33)). This source map involves passing raw strings to `eval()` calls, which raise Trusted Types violations. The solution to this problem is to set `webpack5Config.output.trustedTypes` in the Webpack config. As shown in the documentation [here](https://webpack.js.org/configuration/output/#outputtrustedtypes), setting this value to a string will create a Trusted Types policy with the specified name. By creating a policy within Webpack, the raw strings passed to the `eval()` calls will be promoted to be of type `TrustedScript`. The issue where this was addressed in Webpack can be found [here](https://github.com/webpack/webpack/issues/14075).

### Note:
The policy name that is set in the Webpack config is currently `nextjs#bundler`. Once it is released to the public and application developers begin using it, it may be harder to change the value since any application developers with a custom policy name allowlist would now need to update their next.config.js headers to allow this new name. Thus, a good name should ideally be determined before this pull request is merged. The reason that `nextjs#bundler` is preferred over `nextjs#webpack` is in case Next.js moves to a different bundler in the future. Having a generic name would allow for application developers to keep their next.config.js file the same after the bundler switch has occurred. If a different name is preferred, feel free to comment what that would be.

The code was tested in a sample application to ensure it behaved as expected.

Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-05-22 04:25:26 +00:00
Elijah
a31793eceb
Properly await for this.hasPage() in base-server (#37091)
* Properly await for this.hasPage() in base-server

this.hasPage() is not properly awaited in a check in base-server.ts,
which may cause unexpected behavior.

* lint-fix

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-05-21 23:00:49 -05:00
Joseph
8bdee983e0
feat: Opt-out Error page from dark scheme color (#36951)
* feat: Opt-out Error page from dark scheme color

* fix: Narrow `withDarkMode` to the media-query

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-05-21 22:35:17 -05:00
THE FALCON
7e57432247
Fix DecodeError from invalid URI causes 500 with middleware vs 400 without (#36993)
* Excluded `DecodeError` error from runMiddleware function

* Fix merge error/check and add test

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-05-21 22:25:51 -05:00
LongYinan
33c837b115
Stabilize SWC emotion transform plugin (#37058) 2022-05-21 04:09:30 +00:00
JJ Kasper
6e40fbd495
Ensure hydration error doc link is shown with react 18 (#37074)
Follow-up to https://github.com/vercel/next.js/pull/31519 this ensures the error link we added is shown with react 18 as well. 

## Documentation / Examples

- [x] Make sure the linting passes by running `yarn lint`
2022-05-20 19:04:27 +00:00
Jiachi Liu
d25e246b50
Keep custom app as non server component (#37044)
We added custom _app as server component support in #33149, but we found it's pretty confusing on usage like support it both server component pages and regular pages at the same time for having similar layout purpose.
When using the _app.server and _app at the same time, applying them into proper places become more confusing.
In that case, we decide to make _app.js can't be a server component, and you can still keep all the existing thing there. And also you don't need to think of the corresponding APIs of custom _app in RSC

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [x] Docs updated
2022-05-20 18:07:20 +00:00
Javi Velasco
036ffa7057
Extract and refactor getPageStaticInfo (#37062)
Extract config parsing
2022-05-20 14:24:00 +02:00
JJ Kasper
6cc2147386
v12.1.7-canary.10 2022-05-19 17:11:19 -05:00
Damien Simonin Feugas
bf089562c7
feat(middleware)!: forbids middleware response body (#36835)
_Hello Next.js team! First PR here, I hope I've followed the right practices._

### What's in there?

It has been decided to only support the following uses cases in Next.js' middleware:
- rewrite the URL (`x-middleware-rewrite` response header)
- redirect to another URL (`Location` response header)
- pass on to the next piece in the request pipeline (`x-middleware-next` response header)

1. during development, a warning on console tells developers when they are returning a response (either with `Response` or `NextResponse`).
2. at build time, this warning becomes an error.
3. at run time, returning a response body will trigger a 500 HTTP error with a JSON payload containing the detailed error.

All returned/thrown errors contain a link to the documentation.

This is a breaking feature compared to the _beta_ middleware implementation, and also removes `NextResponse.json()` which makes no sense any more.

### How to try it?
- runtime behavior: `HEADLESS=true yarn jest test/integration/middleware/core`
- build behavior : `yarn jest test/integration/middleware/build-errors`
- development behavior: `HEADLESS=true yarn jest test/development/middleware-warnings`

### Notes to reviewers

The limitation happens in next's web adapter. ~The initial implementation was to check `response.body` existence, but it turns out [`Response.redirect()`](https://github.com/vercel/next.js/blob/canary/packages/next/server/web/spec-compliant/response.ts#L42-L53) may set the response body (https://github.com/vercel/next.js/pull/31886). Hence why the proposed implementation specifically looks at response headers.~
`Response.redirect()` and `NextResponse.redirect()` do not need to include the final location in their body: it is handled by next server https://github.com/vercel/next.js/blob/canary/packages/next/server/next-server.ts#L1142

Because this is a breaking change, I had to adjust several tests cases, previously returning JSON/stream/text bodies. When relevant, these middlewares are returning data using response headers.

About DevEx: relying on AST analysis to detect forbidden use cases is not as good as running the code.
Such cases are easy to detect:
```js
new Response('a text value')
new Response(JSON.stringify({ /* whatever */ })
```
But these are false-positive cases:
```js
function returnNull() { return null }
new Response(returnNull())

function doesNothing() {}
new Response(doesNothing())
```
However, I see no good reasons to let users ship middleware such as the one above, hence why the build will fail, even if _technically speaking_, they are not setting the response body. 



## Feature

- [x] 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.
- [x] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [x] Make sure the linting passes by running `yarn lint`
2022-05-19 22:02:20 +00:00
Donny/강동윤
9732463f92
Update swc (#37009)
This PR

 - updates swc crates to 224a2ea8b6

 - resolves`https://github.com/vercel/next.js/discussions/30237?sort=new#discussioncomment-2759673`

 - resolves `https://github.com/vercel/next.js/discussions/30237?sort=new#discussioncomment-2780370`


<img width="1840" alt="image" src="https://user-images.githubusercontent.com/29931815/169214393-5798681f-2a48-48b8-ba4a-24e4360e4ea5.png">
2022-05-19 20:29:04 +00:00
残月
5b21f09184
Fixes beforeInteractive inline scripts don't run (#37033)
BeforeInteractive inline script in v12.1.7-canary.8  don't run. Beacause the script has unknow src.

![image](https://user-images.githubusercontent.com/17813559/169257330-4419228a-6d10-4815-9451-d9a5dd7f011b.png)

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


## 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`
2022-05-19 19:53:30 +00:00
JJ Kasper
50833d009d
v12.1.7-canary.9 2022-05-19 13:06:44 -05:00
JJ Kasper
947bcd8ca7
Update to latest version of @vercel/nft (#37041) 2022-05-19 11:57:31 -05:00
Shu Ding
cd6b491cef
Fix styled-jsx not working in client components in the edge runtime when SSR (#37042)
The Edge SSR server and the client bundle should share the same Styled JSX instance to ensure the context can be passed correctly, same with the way we handle `next/head`.

## 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`
2022-05-19 16:44:43 +00:00
Javi Velasco
f354f46b3f
Deprecate nested Middleware in favor of root middleware (#36772)
This PR deprecates declaring a middleware under `pages` in favour of the project root naming it after `middleware` instead of `_middleware`. This is in the context of having a simpler execution model for middleware and also ships some refactor work. There is a ton of a code to be simplified after this deprecation but I think it is best to do it progressively.

With this PR, when in development, we will **fail** whenever we find a nested middleware but we do **not** include it in the compiler so if the project is using it, it will no longer work. For production we will **fail** too so it will not be possible to build and deploy a deprecated middleware. The error points to a page that should also be reviewed as part of **documentation**.

Aside from the deprecation, this migrates all middleware tests to work with a single middleware. It also splits tests into multiple folders to make them easier to isolate and work with. Finally it ships some small code refactor and simplifications.
2022-05-19 15:46:21 +00:00
Kiko Beats
cc8ab99a92
Edge Cookies: Add .getWithOptions method (#36943)
Hello,

This is an iteration after first work at https://github.com/vercel/next.js/pull/36478.

What that PR missed is a way to just get a cookie value. Well, this PR adds two new things:

`cookies.get` returns the cookie value that could be `string | undefined`:

```js
const response = new NextResponse()
response.cookies.set('foo', 'bar', { path: '/test' })

const value = response.cookies.get('foo')
console.log(value) // => 'bar'
```

Additionally, if you want to know all the cookie details, you can use `cookies.getWithOptions`:

```js
const response = new NextResponse()

response.cookies.set('foo', 'bar', { path: '/test' })
const { value, options } response.cookies.getWithOptions('foo')

console.log(value) // => 'bar'
console.log(options) // => { Path: '/test' }
```
2022-05-19 13:04:58 +00:00
JJ Kasper
5acf9db617
v12.1.7-canary.8 2022-05-18 20:35:50 -05:00
Hannes Bornö
e3382e64f0
Don't add locale to client side redirects from data fetching (#36944)
## Bug

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

Fixes #36169
2022-05-19 00:31:43 +00:00
Steven
9f0024a5ee
Change experimental layout=raw to use native img lazy loading (#36985)
This PR changes the experimental `layout=raw` images to use the native lazy loading behavior (as opposed to the IntersectionObserver).

This will (eventually) lead to smaller client bundles and faster image loading since there is no JS needed to load the image.

However, we'll lose the `lazyRoot` and `lazyBoundary` behavior since those are specific to the IntersectionObserver implementation.
2022-05-18 21:05:15 +00:00
Houssein Djirdeh
81e69e8662
Fixes beforeInteractive scripts failing in custom document (#37000)
- Fixes #36997
- Fixes #31275

@janicklas-ralph Any idea why tests were passing while this check was failing? Can we add a stronger test for this?
2022-05-18 18:36:11 +00:00
Shu Ding
b2045c7669
Simplify the logic for static flight response generation (#36984)
* code refactor

* simplify static data

* htmlEscapeJsonString in view-render
2022-05-18 13:18:28 +02:00
JJ Kasper
f3c31137e1
Fix interopDefault on jest object-proxy (#37002)
This fixes the interop default from https://github.com/vercel/next.js/pull/36877 on the jest `object-proxy` as it currently causes the below error when running tests in our `with-jest` example:

```sh
    TypeError: 'get' on proxy: property '__esModule' is a read-only and non-configurable data property on the proxy target but the proxy did not return its actual value (expected 'true' but got 'false')
```

## Bug

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

x-ref: https://github.com/vercel/next.js/pull/36877
2022-05-18 09:41:13 +00:00
Damien Simonin Feugas
4a86a8ffb1
fix(middleware): false positive dynamic code detection at build time (#36955)
## What's in there?

Partially fixes https://github.com/vercel/edge-functions/issues/82
Relates to #36715 

Our webpack plugin for middleware leverages static analysis to detect Dyanamic code evaluation in user `_middleware.js` file (and depedencies). Since edge function runtime do not allow them, the build is aborted.

The use of `Function.bind` is considered invalid, while it is legit. A customer using `@aws-sdk/client-s3` reported it.
This PR fixes it.

Please note that this check is too strict: some dynamic code may be in the bundle (despite treeshaking), but may never be used (because of code branches). Since this point is under discussion, this PR adds tests covering some false positives (`@apollo/react-hook`, `qs` and `has`), but does not change the behavior (consider them as errors).

## Notes to reviewer

I looked for test facilities allowing to download the required 3rd party modules. `createNext()` in production context made my day, but showed two issues:
- `cliOutput` is not cleaned in between tests. While clearance during `stop()` would be annoying, I hope that clearance during `start()` is better.
- if `start()` fails while building, the created instance can never be stopped. This is because we don't clear `childProcess` after `build`. 

## Bug

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

- [x] Make sure the linting passes by running `yarn lint`
2022-05-17 19:35:48 +00:00
Josh Story
f1babe9302
escape flight response values (#36989)
Applies additional escaping to flight data written to script tags during RSC. A test was added. I'm not aware of any issues reported for this and there are no new errors

## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
2022-05-17 17:44:44 +00:00
Hannes Bornö
4fd883f238
Remove optional chaining from eslint rule to support older node versions (#36978)
fixes #36693

## Bug

- [x] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
2022-05-17 17:09:31 +00:00