Commit graph

5577 commits

Author SHA1 Message Date
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
JJ Kasper
af86ca08e4
v12.1.7-canary.7 2022-05-17 11:01:35 -05:00
Tim Neutkens
fe3d6b7aed
Add support for browserslist and legacyBrowsers experimental option (#36584)
Implements the first part of #33227

- Applies browserslist to JS transforms when `experimental.browsersListForSwc` is enabled. 
- You don't have to use browserslist, there's also `legacyBrowsers: false` which will be the new default in Next.js 13. See #33227 for which browsers and why. `legacyBrowsers` requires `browsersListForSwc: true` to function until it is the default. 

```js
module.exports = {
  experimental: {
    legacyBrowsers: false,
    browsersListForSwc: true,
  }
}
```

I only implemented the JS part of the RFC, the CSS part should be handled in a follow-up PR.



## Bug

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

## Feature

- [x] 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`
- [x] Integration tests added
- [ ] 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

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


Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-05-17 15:09:34 +00:00
JJ Kasper
c947abb439
Update lockfile patching for different versions (#36959)
This ensures different lockfile versions are handled and we skip patching when the version isn't supported. This also adds an env variable to allow skipping this check if desired. 

## Bug

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

Closes: https://github.com/vercel/next.js/issues/36816
2022-05-17 14:45:23 +00:00
Donny/강동윤
16bcb070d8
Update swc (#36972)
This PR updates swc to f226c0a3d8


This PR resolves

 - `https://github.com/vercel/next.js/discussions/30237#discussioncomment-2739632`

<img width="1840" alt="image" src="https://user-images.githubusercontent.com/29931815/168766189-c9412011-afae-4888-9b43-045e91478771.png">

Which is related to `styled-components`
2022-05-17 14:15:24 +00:00
Sukka
96034e2d9c
fix(#36651): disable reactRemoveProperties in jest transform (#36922)
## Bug

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

Fixes #36651.

Always disable `reactRemoveProperties` in `next/jest` transformation.
2022-05-17 11:05:31 +00:00
LongYinan
c7f2c635cb
Fix SWC dynamic transform with suspense but without ssr (#36825)
The Babel plugin works fine, so it seems not a runtime issue.

fixes https://github.com/vercel/next.js/issues/36636
2022-05-17 10:41:17 +00:00
Luis Alvarez D
31a538d68b
Update @types/node-fetch to latest (#36953)
Currently, if you try the following code while developing with Next.js inside Middleware:

```ts
const url = new URL(MY_URL)
const res = await fetch(url)
```

The app will work as expected, and so will the dom types for TS 4.5+. However when running `next build` or `tsc` typescript fails with:

<img width="837" alt="image" src="https://user-images.githubusercontent.com/4278345/168647502-06b8b223-e0cf-4e8b-9a82-cdac51748789.png">

The types for `node-fetch` have been updated to include `URL` so this PR updates the dependency to fix it.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
2022-05-16 17:45:22 +00:00
Sidharth Rathi
7b83c19da5
Support graceful shutdowns (#36909)
## 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.
- [x] Related issues linked using [19693](https://github.com/vercel/next.js/discussions/19693)
- [ ] 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`


Closes #29959
2022-05-16 14:40:39 +00:00
Tim Neutkens
b11d4411e0
Add additional layer for server components case (#36921)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2022-05-16 11:46:45 +02:00
Donny/강동윤
359d03f899
Update swc (#36745)
This PR

 - updates swc crates to a09bfc22f8

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

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

![image](https://user-images.githubusercontent.com/29931815/168412242-6b72fc0e-788e-446b-804e-f071e0e67b73.png)


 - applies various bugfixes
2022-05-16 09:37:21 +00:00
Jiachi Liu
ed4d009841
Drop the unstable web vital hook and remove exports of flush effects (#36912)
* remove the experimental web vital hook api
* remove the exported flush effects api and only error on development, keep only usage to styled-jsx

for web vital hook API: The usage is not widly adopted since the existing exported vital api could do the same work. In the future we'll deprecate the `_app.server` in favor of `_app` in server component pages. so that this api won't be required.

for flush effects api: other css-in-js libs are not using the same approach like styled-jsx which holding a style registry and could flush it during streaming. emotion-js and styled-components are still relying on `Document.getInitialProps` atm and we have supported it in latest canary
2022-05-14 21:20:24 +00:00
Sukka
bbfda44248
fix(#36855/#30300): export 404.html correctly (#36910)
## Bug

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

The PR fixes #30300 and #36855.

The corresponding integration test case has been added.
2022-05-14 13:57:48 +00:00
Shu Ding
b122178ead
Decouple entries for server components and client components (#36860)
* (wip)

* dev mode

* build mode

* update comment

* fix tests

* fix _N_SSP and _N_SSG exports

* fix missing variables

* fix api route bug

* fix compiler stats

* fix lint errors

* add extra cache group for edge server

* fix test

* fix test

* fix views route meta and entries

* fix linter error

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2022-05-13 19:48:53 +02:00
LongYinan
9e568dae24
Make esm default interpolation work with jest mock (#36877)
fixes https://github.com/vercel/next.js/issues/36794
2022-05-13 16:39:38 +00:00
JJ Kasper
257eccb7fc
v12.1.7-canary.6 2022-05-13 10:25:27 -05:00
Steven
d67baa0d1f
Fix return type of middleware req.cookies.get() (#36872)
Follow up to #36478 

Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-05-12 21:44:06 +00:00
JJ Kasper
4475de58ff
Update client router for tests (#36822)
## 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`


Co-authored-by: Tim Neutkens <6324199+timneutkens@users.noreply.github.com>
2022-05-12 20:52:59 +00:00
JJ Kasper
1ccf368f1a
v12.1.7-canary.5 2022-05-12 13:11:34 -05:00
Jiachi Liu
adb56ef2bc
Enable html post optimization for react 18 (#36837)
Follow up for #35888 to re-enable more test, and re-enable post processors after #36792 has better support for document.gIP with react 18. Apply post-pocessing when the the shell chunk is fully buffered.

re-enabled integration tests for react 18:
- amphtml
- amphtml-custom-optimizer
- app-document
- font-optimization

Fixes #35835


## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
2022-05-12 17:41:37 +00:00
JJ Kasper
03d00e284f
Add experimental config for basePath testing (#36843)
This adds an experimental config for testing `basePath` handling on the client. 

x-ref: [slack thread](https://vercel.slack.com/archives/CLDDX2Y0G/p1652221605742559)

## 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-12 16:47:34 +00:00
JJ Kasper
8e401aecfd
Eagerly load swc bindings for wasm fallback for jest (#36784)
Follow-up to https://github.com/vercel/next.js/pull/36612 this updates to eagerly load the swc bindings unless babel is being used so that we don't wait for the transform calls to initialize swc. Eagerly loading in jest also allows us to fallback to the wasm bindings when previously we couldn't since they needed to wait for the import.
2022-05-12 09:15:27 +00:00
Houssein Djirdeh
72f5c93aad
Telemetry: track usage of 'experimental/nextScriptWorkers' (#36812)
Track usage of the experimental `nextScriptWorkers` flag.

Backend PR: https://github.com/vercel/next-telemetry/pull/75

https://nextjs.org/docs/basic-features/script#off-loading-scripts-to-a-web-worker-experimental
2022-05-11 19:18:44 +00:00
Sukka
093288c9d7
fix(#30300): force export 404.html (#36827)
## Bug

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

The PR fixes #30300.

The previous integration test case only checks if `/out/404.html` exists. However, the test passes since `/out/404.html/index.html` is being exported instead.
The PR changes that by checking if a given path exists and is a file.
2022-05-11 18:44:25 +00:00
Sukka
d76bbde311
fix(#36534): enable interopClientDefaultExport for next/jest (#36824) 2022-05-11 13:13:13 -05:00
Hannes Bornö
2e135346cf
Don't convert error to string (#36804)
Stack trace disappears when error is converted to string.
I changed the types in `log.ts` to match `console.log`/`console.error`/`console.warn`.

fixes #31591
2022-05-11 17:02:15 +00:00
LongYinan
6f344e6617
Build x86_64-freebsd SWC binary (#36826)
Close https://github.com/vercel/next.js/issues/36639


Build successfully: https://github.com/vercel/next.js/actions/runs/2305589556
2022-05-11 16:20:05 +00:00
JJ Kasper
334d42c441
v12.1.7-canary.4 2022-05-11 09:26:55 -05:00
Jiachi Liu
4de5b64c0b
Wait for shell resolve with gIP is customized in react 18 (#36792)
When getInitialProps is customized with react 18, since gIP requires to return `html` as doc property which could be used by  user-land customization, we do blocking-rendering there and passdown the `html` to document

Fixes #36675
Closes #36419
2022-05-11 13:25:23 +00:00
JJ Kasper
e05a95a844
Update moduleNameMapper jest config and remove extra deps (#36787)
* Update moduleNameMapper jest config and remove extra deps

* move svg mock to its own entry for easier overriding

* remove package script
2022-05-10 16:36:10 -05:00
Shu Ding
fdc071c5fd
Move FlightManifestPlugin to server compilers (#36810)
* move FlightManifestPlugin to server compilers

* revert loader condition

* fix module id

* fix test and refactor

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2022-05-10 21:20:13 +02:00
Remco Haszing
8f9296c00d
Add final newline to package-lock.json (#36813)
This aligns the output with what npm outputs. Without this change,
Next.js causes unwanted changes in package-lock.json.

## 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

- [x] Make sure the linting passes by running `yarn lint`
2022-05-10 17:38:25 +00:00
JJ Kasper
482fe25cbb
Update root component handling (#36781) 2022-05-10 18:57:14 +02:00
Erik Brinkman
c7b2083f2e
Add experimental flag to force SWC transforms (#36789)
fixes #36763
fixes #36590

## Feature

- [x] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
   - It hasn't been accepted for implementation, although that process isn't clear, and this is a pretty trivial fix.
- [x] 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.
   - This is somewhat inherent in the error log
- [x] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [x] Make sure the linting passes by running `yarn lint`
2022-05-10 10:33:31 +00:00
JJ Kasper
7d52589bd6
Update x-nextjs-cache header in minimal mode (#36791) 2022-05-09 17:08:29 -05:00
Tim Neutkens
db8f161dfe
Clarify variables being used during rendering (#36773)
Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-05-09 11:52:08 -05:00
Kiko Beats
b78c28f7a0
feat: better cookies API for Edge Functions (#36478)
This PR introduces a more predictable API to manipulate cookies in an Edge Function context.

```js
const response = new NextResponse()

// set a cookie
response.cookies.set('foo, 'bar') // => set-cookie: 'foo=bar; Path=/'`

// set another cookie
response.cookies.set('fooz, 'barz') // => set-cookie: 'foo=bar; Path=/, fooz=barz; Path=/'`

// delete a cookie means mark it as expired
response.cookies.delete('foo') // => set-cookie: 'foo=; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT, fooz=barz; Path=/'`

// clear all cookies means mark all of them as expired
response.cookies.clear() // => set-cookie: 'fooz=; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT, foo=; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT'`
``` 

This new cookies API uses [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) interface, and it's available for `NextRequest` and `NextResponse`.

Additionally, you can pass a specific cookies option as a third argument in `set` method:

```js
response.cookies.set('foo', 'bar', {
  path: '/',
  maxAge: 60 * 60 * 24 * 7,
  httpOnly: true,
  sameSite: 'strict',
  domain: 'example.com'
}
```

**Note**: `maxAge` it's in seconds rather than milliseconds.

Any cookie manipulation will be reflected over the `set-cookie` header, transparently.

closes #31719
2022-05-09 09:50:32 +00:00
Tim Neutkens
40e9891175
Add flight render starting point (#36760)
## 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-08 16:38:43 +00:00
Sukka
26459ef097
replace use-subscription with use-sync-external-store (#36733)
- [x] Make sure the linting passes by running `yarn lint`

Back in 2019, React released the first version of `use-subscription` (https://github.com/facebook/react/pull/15022). At the time, we only has limited information about concurrent rendering, and #9026 add the initial concurrent mode support.

In 2020, React provides a first-party official API `useMutableSource` (https://github.com/reactjs/rfcs/pull/147, https://github.com/facebook/react/pull/18000):

> ... enables React components to safely and efficiently read from a mutable external source in Concurrent Mode.

React 18 introduces `useMutableSource`'s replacement `useSyncExternalStore` (see details here: https://github.com/reactwg/react-18/discussions/86), and React changes `use-subscription` implementation to use `useSyncExternalStore` directly: https://github.com/facebook/react/pull/24289

> In React 18, `React.useSyncExternalStore` is a built-in replacement for `useSubscription`.
> 
> This PR makes `useSubscription` simply use `React.useSyncExternalStore` when available. For pre-18, it uses a `use-sync-external-store` shim which is very similar in `use-subscription` but fixes some flaws with concurrent rendering.

And according to `use-subscription`:

> You may now migrate to [`use-sync-external-store`](https://www.npmjs.com/package/use-sync-external-store) directly instead, which has the same API as `React.useSyncExternalStore`. The `use-subscription` package is now a thin wrapper over `use-sync-external-store` and will not be updated further.

The PR does exactly that:

- Removes the precompiled `use-subscription` introduced in #35746
- Adds the `use-sync-external-store` to the dependencies.
  - The `use-sync-external-store` package enables compatibility with React 16 and React 17.
  - Do not pre-compile `use-sync-external-store` since it is also the dependency of some popular React state management libraries like `react-redux`, `zustand`, `valtio`, `@xstate/react` and `@apollo/client`, etc. By install
- Replace `useSubscription` usage with `useSyncExternalStore` 

---

Ref: #9026, #35746 and #36159


Co-authored-by: Jiachi Liu <4800338+huozhi@users.noreply.github.com>
2022-05-08 12:19:33 +00:00
Jiachi Liu
a84672e63e
Use react dom server node api to detect react root is enabled (#36749)
x-ref: https://github.com/vercel/next.js/pull/36552#issuecomment-1120128946
x-ref: https://github.com/preactjs/next-plugin-preact/pull/59

`preact/compat` doesn't have `/server.browser` exports, to make it work with latest of next.js: 

* use `react-dom/server` to detect if it could opt-in streaming rendering by checking react 18 `renderToPipeableStream` API in short time fix. In long term `preact/compat`should support `/server.browser` that same with react 17.
* Also filed a PR to `next-plugin-preact` to skip chunk-prepending to pages in edge compiler
2022-05-07 18:45:40 +00:00
Tim Neutkens
51d962d60f
Leverage pageExtensions for resolving in loader (#36747)
## 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-07 13:37:14 +00:00
Tim Neutkens
e78c42c91b
Fix leftover todo in loader (#36734) 2022-05-06 18:11:11 +02:00
Tim Neutkens
a1bb1c69ed v12.1.7-canary.3 2022-05-06 13:11:55 +02:00
Tim Neutkens
6f90d19609
Add route loader (#36712)
* Add route loader

* Update to leverage new view-loader

* fix lint

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-05-05 15:42:22 -05:00
Jiachi Liu
4fb0beb1ee
fix: duplicate app server (#36710)
Fixes #36659

`App` is alreay included in `ServerComponentWrapper`

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
2022-05-05 18:53:51 +00:00
JJ Kasper
41c0a66902
Update renderOpts.dev handling and fix check (#36666)
* Update renderOpts.dev handling and fix check

* Update awaiting in load-components

* extra arg

* fix streaming case
2022-05-05 11:11:17 -05:00
Steven
cefb944ee5 v12.1.7-canary.2 2022-05-05 08:08:52 -04:00
JJ Kasper
e8a8220d49
Tweak routing tests (#36667)
Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
2022-05-05 13:15:32 +02:00
Steven
da8d1984d2
Add experimental wildcard remotePatterns config for upstream images (#36245)
## Description 
This PR implements a new configuration object in `next.config.js` called `experimental.images.remotePatterns`.

This will eventually deprecate `images.domains` because it covers the same use cases and more by allowing wildcard pattern matching on `hostname` and `pathname` and also allows restricting `protocol` and `port`.

## Feature

- [x] Implements an existing feature request.
- [x] Related issues linked
- [x] Unit tests added
- [x] Integration tests added
- [x] Documentation added
- [x] Telemetry added. In case of a feature if it's used or not.
- [x] Errors have helpful link attached, see `contributing.md`

## Related 

- Fixes #27925 
- Closes #18429 
- Closes #18632
- Closes #18730
- Closes #27345
2022-05-05 02:19:16 +00:00
Justin Goping
0dd62111f6
Fix various Trusted Types violations without use of policy (#34726)
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
There are three Trusted Types violations that are fixed in this PR:
### 1. ban-element-innerhtml-assignments: maintain--tab-focus.ts
The innerHTML assignment here is unsafe as a string is being used that could contain an XSS attack. The solution chosen was to replace the string containing HTML with programmatically-created DOM elements. This removes the Trusted Types violation as there is no longer a string passed in that can contain an XSS attack.

Notes on solution:
-  The `<svg>` tag is omitted completely since the original snippet returns fragment.firstChild.firstChild. The first firstChild omits the `<div>`, and the second firstChild omits the `<svg>`, so to remove unnecessary code the created elements start at the foreignObject level.
-  The reason createElementNS is used instead of createElement is because the ‘foreignObject’ element is a separate namespace from the default HTML elements. The documentation for this command is found [here](https://developer.mozilla.org/en-US/docs/Web/API/Document/createElementNS).

The code was tested to be equivalent by rendering both the original code and the re-written code in a browser to see if they evaluate to the same thing in the DOM. The DOM elements styles were then compared to ensure that they were identical.

### 2. ban-window-stringfunctiondef: packages/next/lib/recursive-delete.ts
The setTimeout function caused a Trusted Types violation because if a string is passed in as the callback, XSS can occur. The solution to this problem is to ensure that only function callbacks can be passed to setTimeout. There is only one call to the sleep function and it does not involve a string callback, so this can be enforced without breaking the application logic. In the process of doing this, promisify has been removed and the promise has been created explicitly.

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

### 3. ban-window-stringfunctiondef: packages/next/client/dev/fouc.ts
This file also uses setTimeout, so the call was wrapped in a `safeSetTimeout` call that specifies that the callback argument is not a string.
2022-05-05 00:11:36 +00:00
Justin Goping
44c89e50c8
Route Loader Trusted Types Violation Fix (#34730)
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
There is one tsec violation that is fixed in this PR:
### 1. ban-script-src-assignment: route-loader.ts
XSS can occur with the line script.src = src in appendScript(src, script) if src can be controlled by a malicious user. From tracing through the code, it was determined that src comes from the function `getFilesForRoute(route)`. The behaviour of this function differs depending on the environment (development vs. production), but in both cases the function will construct strings that lead to valid file paths. These strings depend on two variables: `assetPrefix` and `route`, but due to the nature of the constructed strings it was determined that the scripts here are safe to use. Thus, the solution was to promote these strings to `TrustedScriptURL`s. This is the Trusted Types way of declaring that the script URL passed to the DOM sink is safe from DOM XSS attacks.

To create a `TrustedScriptURL`, a policy needs to be created. This policy was put in its own file: `client/trusted-types.ts`. This policy has the name `nextjs`. If this name should be changed to something else, feel free to change it now. However, 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.

The code was tested in a sample application to ensure it behaved as expected.
2022-05-03 23:22:08 +00:00
Jiachi Liu
ce6e8b5622
fix: react root enabled properly in custom server (#36664)
Fixes #36643

## Bug

* hoist react dom choosing in client
* also assign __NEXT_REACT_ROOT env in custom server

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
2022-05-03 22:42:00 +00:00
JJ Kasper
87529e987c
v12.1.7-canary.1 2022-05-03 16:02:45 -05:00
JJ Kasper
95fb221e87
Fix asPath handling for data route revalidation in minimal mode (#36660) 2022-05-03 15:40:36 -05:00
Tim Neutkens
b9bf269991 v12.1.7-canary.0 2022-05-03 13:17:28 +02:00
JJ Kasper
44f436b91b
Add initial handling for routing tests (#36635)
x-ref: https://github.com/vercel/next.js/pull/36618
2022-05-03 10:37:23 +00:00
OJ Kwon
837e0a6af8
feat(next-swc): introduce experimental tracing support for swc (#35803)
* feat(next-swc/napi): expose initcustomtracesubscriber

* feat(next/config): enable experimental swcTrace

* feat(trace): add trace for emotion transform

* refactor(swc): use .next for the default trace output

* refactor(swc): teardown subscriber via drop

* refactor(swc/trace): simplify config

* refactor(swc/trace): adjust teardown
2022-05-02 15:20:59 -07:00
JJ Kasper
3692a5ecdb
Add falling back to wasm swc build on native load failure (#36612)
Follow-up to https://github.com/vercel/next.js/pull/36527 this adds falling back to the wasm swc build when loading the native bindings fails so that we don't block the build on the native dependency being available.  

This continues off of https://github.com/vercel/next.js/pull/33496 but does not add a postinstall script yet and only downloads the fallback when the native dependency fails to load.
2022-05-02 21:11:45 +00:00
Jiachi Liu
fcec758779
Flush initial styled-jsx in gIP first in concurrent rendering (#36594)
* Use flushed effects to generate styled-jsx styles insted of gIP by default

* ensure styles are flushed inside the default getInitialProps

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Co-authored-by: Shu Ding <g@shud.in>
2022-05-02 22:52:46 +02:00
JJ Kasper
b188fab336
v12.1.6 2022-05-02 14:46:56 -05:00
Tim Neutkens
0c23f5d1d2 v12.1.6-canary.17 2022-05-02 20:27:26 +02:00
Tim Neutkens
20e5fed1cf
Handle styled-jsx in newLinkBehavior codemod (#36628)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2022-05-02 19:07:14 +02:00
Naoyuki Kanezawa
9e53af8e30
Fix next node buildin module error message for edge runtime (#36434)
- improve the message for importing node builtin module on edge runtime
- fix to show the message on overlay of error browser with `next dev`
- fix https://github.com/vercel/next.js/issues/36237

The message is NOT shown when using edge runtime (not middleware) since I cannot find a way to detect a webpack compilation is for edge runtime.

## 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-02 15:21:40 +00:00
JJ Kasper
c905fda590
Fix swc jest pagesDir config (#36623)
This updates the `pagesDir` config for the new return shape updated in https://github.com/vercel/next.js/pull/36619, no additional tests were added as existing tests were failing from this. 

x-ref: https://github.com/vercel/next.js/runs/6257712883?check_suite_focus=true
x-ref: https://github.com/vercel/next.js/runs/6257712805?check_suite_focus=true
x-ref: https://github.com/vercel/next.js/pull/36619
2022-05-02 14:59:38 +00:00
Tim Neutkens
4eee0e32f3
Update findPagesDir (#36619)
Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
Co-authored-by: Jiachi Liu <4800338+huozhi@users.noreply.github.com>
2022-05-02 15:07:21 +02:00
Tim Neutkens
6bb0e91a0c
Add tests for routing experiment (#36618)
## 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-02 10:18:16 +00:00
Tim Neutkens
ddba1aab1f v12.1.6-canary.16 2022-05-01 18:58:46 +02:00
Tim Neutkens
5aa54b3385
Add pagesDir to Jest transformer (#36599)
Fixes #35469

Adds `pagesDir` which is required for the Relay transform.

Added a test case based on https://github.com/hanford/relay-swc-jest.



## 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`


Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-05-01 16:39:30 +00:00
JJ Kasper
bd3dfe1f4b
Update status code for normalize error (#36580)
This updates to show a 400 (bad request) when an invalid path is sent to Next.js similar to our decode failure handling. 

## Bug

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

Closes: https://github.com/vercel/next.js/issues/36555

Co-authored-by: Tim Neutkens <6324199+timneutkens@users.noreply.github.com>
2022-05-01 09:23:06 +00:00
Jiachi Liu
7a09f88d14
Reexports styled-jsx JSXStyle in nextjs (#36585)
When using pnpm / yarnPnP to install next.js, styled-jsx as dependency is not hoisted in the top level node_modules, it will fail when nodejs is trying to resolve `styled-jsx/style` from project directory. Re-export `styled-jsx/style` in next.js and let swc/babel plugin compile the import path it to `next/dist/shared/lib/styled-jsx`

Resolves #10149
Closes #21320
Closes #9325



Co-authored-by: Tim Neutkens <6324199+timneutkens@users.noreply.github.com>
2022-04-30 20:25:05 +00:00
Javi Velasco
0de109baab
Refactor Page Paths utils and Middleware Plugin (#36576)
This PR brings some significant refactoring in preparation for upcoming middleware changes. Each commit can be reviewed independently, here is a summary of what each one does and the reasoning behind it:
- [Move pagesDir to next-dev-server](f2fe154c00) simply moves the `pagesDir` property to the dev server which is the only place where it is needed. Having it for every server is misleading.
- [Move (de)normalize page path utils to a file page-path-utils.ts](27cedf0871) Moves the functions to normalize and denormalize page paths to a single file that is intended to hold every utility function that transforms page paths. Since those are complementary it makes sense to have them together. I also added explanatory comments on why they are not idempotent and examples for input -> output that I find very useful.
- [Extract removePagePathTail](6b121332aa) This extracts a function to remove the tail on a page path (absolute or relative). I'm sure there will be other contexts where we can use it.
- [Extract getPagePaths and refactor findPageFile](cf2c7b842e) This extracts a function `getPagePaths` that is used to generate an array of paths to inspect when looking for a page file from `findPageFile`. Then it refactors such function to use it parallelizing lookups. This will allow us to print every path we look at when looking for a file which can be useful for debugging. It also adds a `flatten` helper. 
- [Refactor onDemandEntryHandler](4be685c37e) I've found this one quite difficult to understand so it is refactored to use some of the previously mentioned functions and make it easier to read.
- [Extract absolutePagePath util](3bc0783474) Extracts yet another util from the `next-dev-server` that transforms an absolute path into a page name. Of course it adds comments, parameters and examples.
- [Refactor MiddlewarePlugin](c595a2cc62) This is the most significant change. The logic here was very hard to understand so it is totally redistributed with comments. This also removes a global variable `ssrEntries` that was deprecated in favour of module metadata added to Webpack from loaders keeping less dependencies. It also adds types and makes a clear distinction between phases where we statically analyze the code, find metadata and generate the manifest file cc @shuding @huozhi 

EDIT: 
- [Split page path utils](158fb002d0) After seeing one of the utils was being used by the client while it was defined originally in the server, with this PR we are splitting the util into multiple files and moving it to `shared/lib` in order to make explicit that those can be also imported from client.
2022-04-30 11:19:27 +00:00
Steven
7998b63a38
Fix missing Content-Length header from Image Optimization API (#36581)
Fixes #35514
2022-04-30 01:50:42 +00:00
JJ Kasper
c838b5f50d
v12.1.6-canary.15 2022-04-29 11:54:57 -05:00
Houssein Djirdeh
fd2ba11763
Adds inline script functionality to next/script for worker and beforeInteractive strategies (#36364)
Adds inline script functionality to `next/script` for `worker` and `beforeInteractive` strategies. 

- fixes #36318 
- fixes #26343
- fixes #26591
- fixes #26343
- fixes #26240


Co-authored-by: Janicklas Ralph <6142074+janicklas-ralph@users.noreply.github.com>
2022-04-29 15:20:31 +00:00
JJ Kasper
e30d7237ef
Ensure older lockfile/invalid formats are handled (#36577) 2022-04-29 09:42:48 -05:00
Balázs Orbán
486040eff2
chore: clarify CLI network errors (#36567)
Makes it easier to detect why a network error occurred with the CLI or `next info`, based on https://github.com/vercel/next.js/issues/36344

## 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-04-29 12:39:17 +00:00
Jiachi Liu
ea779c5188
bump styled-jsx to latest (#36554)
x-ref: https://github.com/coryetzkorn/twitter-algorithm/pull/2

* Bump styled-jsx to latest version (5.0.2), so that it could get dedup when user installs the styled-jsx manually
* Remove the legacy `@types/styled-jsx`
2022-04-28 21:12:58 +00:00
Jiachi Liu
cd7419e9c8
Hoist the desired ReactDOM import expression (#36552)
* hoist `react-dom/server` imports to reduce module load time in nodejs
* simplify `reactRoot` detection condition by checking the streaming rendering API we're using. (if it doesn't existed, like react 17, then we won't enable `reactRoot`)
* Merge `__NEXT_CONCURRENT_FEATURES` into `__NEXT_REACT_ROOT` env var since they're identical now
2022-04-28 19:17:23 +00:00
JJ Kasper
244456936b
v12.1.6-canary.14 2022-04-28 13:34:45 -05:00
Balázs Orbán
f000503984
unlock eslint-config-next dependencies (#35781)
Fixes #35753

## 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`


Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-04-28 17:15:58 +00:00
JJ Kasper
60f74230fe
Tweak lockfile patching to be eager (#36549)
This is a follow-up to https://github.com/vercel/next.js/pull/36527 to make sure we eagerly patch the lockfile as the correct swc dependency will be present if the platform matches so the load failure isn't hit which is where we were previously patching the lockfile. This is done in the background so does not block compilation. This also removes some extra logs that aren't necessary. 

<details>

<summary>before lockfile patch</summary>

![before](https://user-images.githubusercontent.com/22380829/165780507-09e5aee6-3253-483f-9e3f-e24bea6df377.png)

</details>


<details>

<summary>after lockfile patch</summary>

![after](https://user-images.githubusercontent.com/22380829/165780545-829665aa-05ec-431d-aa2f-42c4ce3badd7.png)

</details>

This also fixes a case I noticed where we weren't flushing events before exiting when builds fail
2022-04-28 16:40:37 +00:00
Shu Ding
4392b6a9fa
Refactor base server to get rid of the __server_context hack (#36550)
This PR makes the `Options` type of base server configurable as well as assigning to `this.serverOptions`, so the web server can access it during `constructor()`. This gets rid of the dirty `__server_context` hack.

## 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-04-28 16:16:51 +00:00
Donny/강동윤
38aa6d7140
Update swc (#36535)
This PR updates swc to a72f436148


This PR applies

 - https://github.com/swc-project/swc/pull/4452
   - Fixes `yield*` of async generators in async generators.
   - Fixes name mangling of injected helpers.
     - Note: This only applies to tiny files which enables lots of helpers.
 - https://github.com/swc-project/swc/pull/4468
   - Fixes newer version of react.
2022-04-28 10:14:48 +00:00