Commit graph

2801 commits

Author SHA1 Message Date
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
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
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
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
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
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
Jiachi Liu
092346d333
test: clean up duplicated tests (#36871)
Clean up integration tests

* app-document: Merge multi fetch reuqests into 1, add checking for `__NEXT_DATA__`
* rsc/streaming: Merge duplicated tests, move the head tests to client-navigation since they're running under react 18 now
* remove runtime subtest suite under rsc tests since it's covered in switchable runtime test suite
2022-05-13 00:46:12 +00: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
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
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
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
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
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
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
Jiachi Liu
f6af0bc2d8
test: merge rsc custom app cases (#36713)
the rsc & streaming test app is too big to build which is time consuming, move custom _app cases to switchable runtime test suite
2022-05-05 23:16:24 +00: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
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
LongYinan
2012f4e7c6
Update components in GitHub Actions (#36669)
`build-native` jobs tested on https://github.com/vercel/next.js/runs/6288266017
2022-05-04 18:51:25 +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
95fb221e87
Fix asPath handling for data route revalidation in minimal mode (#36660) 2022-05-03 15:40:36 -05:00
Tim Neutkens
fdc4ab88d6
Enable disabled tests that pass (#36644) 2022-05-03 15:12:06 +02: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
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
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
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
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
Tim Neutkens
2451f52bc8
Add support for passing ref to next/link with new behavior enabled (#36537) 2022-04-28 11:32:32 +02:00
JJ Kasper
917a736a55
Add event for swc load failure and attempt patching lockfile (#36527) 2022-04-28 11:31:15 +02:00
Jiachi Liu
ea81df0a83
Bump react dev dep to 18.1 (#36491)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2022-04-28 11:29:30 +02:00
JJ Kasper
9168b386ce
Normalize font optimization snapshot to reduce flakes (#36531) 2022-04-27 19:28:11 -05:00
Alex Castle
93d8fac184
Always add height and width prop to image with layout="raw" (#36523)
This PR makes the following changes:
* Always add the `height` and `width` prop to image with `raw` layout (previously only added to images without `sizes`)
* Add a warning if a raw layout image is getting stretched (which can be caused by interaction of height and width prop with styles)
* Remove automatic aspect-ratio style from `raw` images. This is no longer necessary if all `raw` images have height and width props.
* Update tests and docs accordingly
2022-04-27 21:59:05 +00:00
JJ Kasper
d66445f800
Ensure optional params are normalized correctly in minimal mode (#36513)
Follow-up for https://github.com/vercel/next.js/pull/36463 this fixes an issue with optional catch-all params not being normalized correctly which was caught by the runtimes tests. 

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
2022-04-27 18:46:33 +00:00
JJ Kasper
2fc27c1ec7
Update rewrite destination for flakey rewrite tests (#36519)
* Update rewrite destination for flakey rewrite tests

* update other test
2022-04-27 13:04:16 -05:00
JJ Kasper
89a4c1626b
Remove extra yarn PnP example test (#36518) 2022-04-27 11:41:34 -05:00
Tim Neutkens
f550da7031
Remove passhref Eslint rule as it's no longer needed with new link behavior (#36511) 2022-04-27 17:33:13 +02:00
Javi Velasco
0bf6655f1c
Use edge compiler for middleware (#36486)
* Refactor `path-match`

* Simplify `createPagesMapping`

* Rename `getRawPageExtensions` -> `withoutRSCExtensions`

* Remove unused `functions-manifest-plugin.ts`

* Enable `eval-source-map` for the edge server compiler

* Use Edge Compiler for Middleware & Refactor

* Update some comments

Co-authored-by: JJ Kasper <jj@jjsweb.site>

Update packages/next/shared/lib/router/utils/path-match.ts

Co-authored-by: JJ Kasper <jj@jjsweb.site>

Update packages/next/shared/lib/router/utils/path-match.ts

Co-authored-by: JJ Kasper <jj@jjsweb.site>

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-04-27 11:50:29 +02:00
JJ Kasper
a16fa39291
Update font-optimization test snapshot (#36492)
Fixes failing test case due to upstream font CSS change. 

x-ref: https://github.com/vercel/next.js/pull/36482#issuecomment-1110313267
2022-04-27 00:30:33 +00:00
JJ Kasper
743cf68555
Pass nextRuntime in webpack context (#36488)
Follow-up to https://github.com/vercel/next.js/pull/36383 this also exposes the `nextRuntime` for the custom webpack function in `next.config.js` to allow differentiating between the environments. 

x-ref: https://vercel.slack.com/archives/CGU8HUTUH/p1647866770704939
2022-04-26 21:05:40 +00:00
JJ Kasper
e44256978a
Update manual revalidate response cache handling (#36462)
This updates to ensure we only resolve a manual revalidate request when the cache has been fully set instead of eagerly like we do for generating pages in `fallback` mode. This also ensures the response cache keys manual revalidate requests separate from normal requests to ensure one doesn't block the other. This should resolve the below flakey tests.  

x-ref: https://github.com/vercel/next.js/runs/6163218261?check_suite_focus=true
x-ref: https://github.com/vercel/next.js/runs/6157328196?check_suite_focus=true
x-ref: https://github.com/vercel/next.js/runs/6151165153?check_suite_focus=true
2022-04-26 19:32:29 +00:00
JJ Kasper
7e7d7bbca6
Fix incorrect asPath with fallback rewrite in minimal mode (#36463)
This continues off of the change in https://github.com/vercel/next.js/pull/36368 and ensures a fallback rewrite does not influence the `asPath` as these are only matched when a filesystem or dynamic route aren't matched. 

## Bug

- [x] 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/36368
2022-04-26 19:12:29 +00:00
Jiachi Liu
d5e767b20d
Add process env NEXT_RUNTIME (#36383)
* To help determine the current running environment is in server nodejs / edge runtime
* Remove usage of `process.browser`
2022-04-26 17:54:28 +00:00
Sukka
487f7ababa
fix(#36435): apply correct fix (#36464)
* fix(#36435): apply correct fix

* fix: only apply interop default flag for re-exported

I really, really love glob.

* test: add test cases for next/dynamic and next/amp
2022-04-26 11:15:49 -05:00
Tim Neutkens
7d3bfac39f
Add stitches and material-ui tests for new link behavior + fix TypeScript types when imported (#36474)
Adds additional tests for material-ui and stitches based on questions in the Twitter thread.

Fixes TypeScript types when `LinkProps` is imported and used in combination with `<button>`, added a TODO to change this at a later point when the new behavior is the default instead of opt-in.



## 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-26 11:46:09 +00:00
LongYinan
26efcc5ded
Fix missing interpolation on next/head exports (#36435)
fixes https://github.com/vercel/next.js/issues/36183



## 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-04-26 04:13:33 +00:00
Tim Neutkens
489e65ed98
Rework <Link> behavior (backwards compatible) (#36436)
Fixes https://github.com/vercel/next.js/discussions/32233

⚠️ If you're looking at this PR please read the complete description including the part about incremental adoption.

## TLDR:

Official support for `<Link href="/about">About</Link>` / `<Link href="/about"><CustomComponent /></Link>` / `<Link href="/about"><strong>About</strong></Link>` where `<Link>` always renders `<a>` without edge cases where it doesn’t render `<a>`. You'll no longer have to put an empty `<a>` in `<Link>` with this enabled.

## Full context

### Changes to `<Link>`

- Added an `legacyBehavior` prop that defaults to `true` to preserve the defaults we have today, this will allow to run a codemod on existing codebases to move them to the version where `legacyBehavior` becomes `false` by default
- When using the new behavior `<Link>` always renders an `<a>` instead of having `React.cloneElement` and passing props onto a child element
- When using the new behavior props that can be passed to `<a>` can be passed to `<Link>`. Previously you could do something like `<Link href="/somewhere"><a target="_blank">Download</a></Link>` but with `<Link>` rendering `<a>` it now allows these props to be set on link. E.g. `<Link href="/somewhere" target="_blank"></Link>` / `<Link href="/somewhere" className="link"></Link>`

### Incremental Adoption / Codemod

The main reason we haven't made these changes before is that it breaks pretty much all Next.js apps, which is why I've been hesitant to make this change in the past. I've spent a bunch of time figuring out what the right approach is to rolling this out and ended up with an approach that requires existing apps to run a codemod that automatically opts their `<Link>` usage into the old behavior in order to keep the app functioning.

This codemod will auto-fix the usage where possible. For example: 

- When you have `<Link href="/about"><a>About</a></Link>` it'll auto-fix to `<Link href="/about">About</Link>`
- When you have `<Link href="/about"><a onClick={() => console.log('clicked')}>About</a></Link>` it'll auto-fix to `<Link href="/about" onClick={() => console.log('clicked')}>About</Link>`
- For cases where auto-fixing can't be applied the `legacyBehavior` prop is added. When you have `<Link href="/about"><Component /></Link>` it'll transform to `<Link href="/about" legacyBehavior><Component /></Link>` so that your app keeps functioning using the old behavior for that particular link. It's then up to the dev to move that case out of the `legacyBehavior` prop.


**This default will be changed in Next.js 13, it does not affect existing apps in Next.js 12 unless opted in via `experimental.newLinkBehavior` and running the codemod.**

Some code samples of what changed:

```jsx
const CustomComponent = () => <strong>Hello</strong>

// Legacy behavior: `<a>` has to be nested otherwise it's excluded

// Renders: <a href="/about">About</a>. `<a>` has to be nested.
<Link href="/about">
  <a>About</a>  
</Link>

// Renders: <strong onClick={nextLinkClickHandler}>Hello</strong>. No `<a>` is included.
<Link href="/about">
  <strong>Hello</strong>
</Link>


// Renders: <strong onClick={nextLinkClickHandler}>Hello</strong>. No `<a>` is included.
<Link href="/about">
  <CustomComponent />
</Link>

// --------------------------------------------------
// New behavior: `<Link>` always renders `<a>`

// Renders: <a href="/about">About</a>. `<a>` no longer has to be nested.
<Link href="/about">
  About
</Link>

// Renders: <a href="/about"><strong>Hello</strong></a>. `<a>` is included.
<Link href="/about">
  <strong>Hello</strong>
</Link>

// Renders: <a href="/about"><strong>Hello</strong></a>. `<a>` is included.
<Link href="/about">
  <CustomComponent />
</Link>
```

---


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


Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-04-25 22:01:30 +00:00
Naoyuki Kanezawa
a6282566f9
Do not polyfill node built-in modules on edge functions (#36190)
As the title. This is intended to be applied on both middleware and edge functions.

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


Co-authored-by: Jiachi Liu <4800338+huozhi@users.noreply.github.com>
2022-04-25 09:25:27 +00:00
shinkj11
42c01ddc8c
Fix next/image usage of onError() (#36305)
## History
In PR #35889, `onError` prop was added explicitly on the `Image` component, but it was ommitted from the `ImageElement` component. In result, the callback didn't work at all.

## Now
This PR deletes the `onError` prop from explicitly defined props. Explicitly adding `onError` on the `const imgElementArgs` is considered, but deleting the defined prop from `Image` is more reasonable because the prop isn't used in `Image` component.


## Bug

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

Co-authored-by: Steven <229881+styfle@users.noreply.github.com>
2022-04-22 16:13:08 +00:00
Balázs Orbán
0e02f20462
chore: upgrade PostCSS dependencies (#34354)
Co-authored-by: balazsorban44 <balazsorban44@users.noreply.github.com>
2022-04-22 13:14:29 +02:00
JJ Kasper
7c6052a084
Fix failing E2E deployment test cases (#36368)
This continues off of https://github.com/vercel/next.js/pull/36285 fixing some of the failing test cases noticed when running the E2E tests against deployments. After these are resolved the tests will be added to our CI flow after each canary release. 

## Bug

- [x] 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/36285
2022-04-22 08:00:33 +00:00
Janicklas Ralph
0441f816a6
Changes to the beforeInteractive strategy to make it work for streaming (#31936)
Changes to the beforeInteractive strategy to make it work for streaming

Splitting `beforeInteractive` into two strategies `beforeInteractive` at the _document level and `beforePageRender` for page level <Scripts>
2022-04-21 21:15:53 +00:00
Shu Ding
be9491e243
Ensure there is only 1 render pass in concurrent rendering with getInitialProps in _document (#36352)
This PR makes sure `renderPage` calls `renderShell` in concurrent features, and `renderToString` if not.

Closes #36268, #36229.

## 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-04-21 16:01:47 +00:00
JJ Kasper
6da71321df
Ensure beforeFiles client-side resolving handles dynamic routes (#36317)
This fixes resolving `beforeFiles` rewrites with `next/link` as previously we weren't resolving the destination to a dynamic route since the resolving was being marked as finished when it shouldn't be during `beforeFiles`. 

## Bug

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

Fixes: https://github.com/vercel/next.js/issues/35402
2022-04-21 14:58:43 +00:00
await-ovo
864d401ee1
fix(next): use moduleGraph.getIssuer to avoid deprecation warning (#36329) (#36330)
fix: #36329 



## 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.
- [ ] 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-21 14:14:03 +00:00
Jiachi Liu
2bdf1bc023
Use fallbackable path module for node and edge runtime (#36306)
x-ref: #36190
x-ref: #31506

* Move nodejs ptah module usage to next-server, keep base-server and web-server headless for `'path'`
* Use a native module `path` for nodejs runtime and `path` polyfill for edge runtime
2022-04-21 09:07:03 +00:00
残月
9fe2f2637c
feat:Add support for useDefineForClassFields typescript option (#36335)
* feat:Add support for useDefineForClassFields typescript option

* test:add test for useDefineForClassFields option

* test: fix lint error
2022-04-21 10:41:09 +02:00
JJ Kasper
b5d9ce5559
Add client HMR tracing for debugging (#36328)
This adds client HMR event tracing to help debug the client state for reproductions easier
2022-04-21 08:30:23 +00:00
JJ Kasper
073a05a1be
Add handling for testing against deployments (#36285)
This adds a new test mode `next-deploy` which allows testing against deployments using the Vercel CLI. After running these tests they uncovered some bugs we need to correct before fully enabling. Patching the uncovered issues will be done in follow-up PRs and then after resolved this will be enabled to run after new publishes. 

Tests that uncovered bugs to patch in follow-ups:

- [ ] test/e2e/getserversideprops/test/index.test.ts (req.url normalizing)
- [ ] test/e2e/i18n-api-support/index.test.ts (locale prefixed API routes matching)
- [ ] test/e2e/prerender.test.ts (/_next/data/build-id/ does not 404)
2022-04-20 12:23:09 +00:00
JJ Kasper
bf405c38eb
Ensure error is cleared for missing global css (#36292)
This ensures we strip ansi encoding from serialized errors as it causes the error to be illegible when rendered. This also adds a test for global CSS import being missing and then fixed. 

## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
2022-04-20 12:03:48 +00:00
Steven
835aeae1cb
Add telemetry for image config formats (avif/webp) (#36289)
This PR adds telemetry for image config formats since AVIF is opt-in (#30180).

See docs https://nextjs.org/docs/api-reference/next/image#acceptable-formats
2022-04-19 22:47:23 +00:00
Shu Ding
90d3478c52
Use renderToStaticMarkup to render documentHTML (#36213)
There wasn't a strong reason to choose `renderToStream` over `renderToStaticMarkup` for the document wrapper. But due to problems like #35870, we can switch back to the static renderer for now.

Fixes #35870.

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


Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-04-19 17:20:20 +00:00
Jiachi Liu
2e00eb6746
Validate streaming writer chunk type in testing (#36200)
* Validate streaming writer chunk type in testing

* call

* update text
2022-04-18 16:24:06 +02:00
Jiachi Liu
d895a50abb
rsc: skip next builtin module when apply loaders (#36202)
x-ref: https://github.com/vercel/server-components-notes-demo/pull/17

Previously in #35975 we ignore handling node_modules as a workaround for 3rd party packages, but for next buildin components we should still handle them for processing client components
2022-04-17 01:38:56 +00:00
JJ Kasper
63230ebce2
Fix build activity indicator position (#36208)
* Fix build activity indicator position

`devIndicators.buildActivityPosition` introduced in
https://github.com/vercel/next.js/pull/30109 needed more tweaks to properly
position the build indicator container. The build indicator was being rendered
off screen when set to a non-default position.

* Refactor stuff for smaller diff

* add config validation

* Apply suggestions from code review

Co-authored-by: Martin Šťovíček <martin.stovicek@monitora.cz>
2022-04-15 23:53:00 -05:00
Kiko Beats
8f8e497e1b
fix(NextResponse.json): pass options (#35367) 2022-04-15 22:23:42 -05:00
Sukka
3ae571d97b
refactor(build): no force transpile optional chaining / nullish (#35976) 2022-04-15 21:48:43 -05:00
Jiachi Liu
fe6e74dc57
Fix missing _app component of AppTree in gIP context (#36206)
## Bug

The custom app is missing in the `ctx.AppTree` that causing the issue, it was accidently missed in custom _app.server pr #35666

Fixes #36198

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [x] Errors have helpful link attached, see `contributing.md`
2022-04-16 01:55:16 +00:00
JJ Kasper
9c68aa7c7a
Stabilize flakey build-output test (#36195) 2022-04-15 13:43:50 -05:00
Steven
4c15f89b53
Add support for tsconfig moduleResolution node | node12 | nodenext (#36189)
- Fixes #35572 

Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-04-15 17:09:12 +00:00
JJ Kasper
1c20d3d071
Stabilize flakey prerender test (#36193) 2022-04-15 11:49:06 -05:00
Steven
4c872cb2dc
Fix next/image usage in most cases of onLoad() (#36176)
Even though we never documented it, the `onLoad` prop used to work (in most cases) in Next.js 12.1.4 and broke in 12.1.5 once the code was refactored in PR #35889.

We still shouldn't document it because `onLoad` doesn't work in all cases so [`onLoadingComplete`](https://nextjs.org/docs/api-reference/next/image#onloadingcomplete) is preferred, however tests were added for the cases that do work.

Use cases that don't work with `onLoad` are Data URLs as well as `loading="eager"`.
2022-04-15 15:02:23 +00:00
Tim Neutkens
1582e11185
Fix res.json support for string / null (#36186)
Continuation of #33592 with updates tests / changes.

Co-Authored-By: Balázs Orbán <info@balazsorban.com>

Co-authored-by: Balázs Orbán <info@balazsorban.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2022-04-15 16:04:00 +02:00
Michael Ward
1be5f36123
Adds linting rule to avoid assignment to 'module' variable. Fixes #34859 (#35279) 2022-04-15 14:45:53 +02:00
Tommaso De Rossi
5a785e45c7
Fix symlink and copy logic to standalone directory when using outputStandalone (#35535)
* fix symlink logic with outputStandalone

* refactored and commented copy function

* faster symlink check

* removed Dockerfile

* removed console.logs from test

* fix symlinksOutsideRoot test

* removed a console.log for files out of root

* added missing types to copy

* removed custom copy function, fix symlink code

* test outputStandalone and pnpm

* appProcess is no more a promise

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2022-04-15 14:35:47 +02:00
Jiachi Liu
a4aa1df7da
rsc: keep static page props (#36157) 2022-04-14 14:35:09 +00:00
Jiachi Liu
953cd9af33
rsc: mark next head as client component (#36138)
Follow up of #36135 

Add `next/head` as client component
2022-04-13 23:36:16 +00:00
Jiachi Liu
f74b59c48c
Reogranize the client component detection utils (#36135)
Refactor:

- group client components detction util
- add next script as rsc client component
2022-04-13 22:35:11 +00:00
Jiachi Liu
1e451ab716
Fix req.url of rsc dynamic routes pages gSSP in edge runtime (#36134)
We were feeding pathname like `/routes/[dynamic]` as `req.url` to RSC pages in edge runtime, which is not aligned with node runtime

## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
2022-04-13 21:31:53 +00:00
JJ Kasper
d24eeb647f
Fix only generated case in minimal mode (#36130) 2022-04-13 15:04:00 -05:00
Shu Ding
a4a970bafa
Support necessary headers in the web server response (#36122)
This PR adds support of `Content-Length`, `Etag` and `X-Edge-Runtime` headers to the web server.

## 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-04-13 17:14:53 +00:00
JJ Kasper
74dead2489
Add experimental onlyGenereated flag for unstable_revalidate (#36108)
* Add experimental ifGenereated flag for unstable_revalidate

* Apply suggestions from code review

Co-authored-by: Steven <steven@ceriously.com>

* update ifGenerated -> onlyGenerated

* rename const as well

Co-authored-by: Steven <steven@ceriously.com>
2022-04-13 11:56:58 -05:00
Naoyuki Kanezawa
1d8165bd79
fix: do not add locale prefix to api route on NextURL (#36118)
Fixes https://github.com/vercel/next.js/issues/35694

## Bug

- [x] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
2022-04-13 15:30:03 +00:00
Shu Ding
19b625e0c5
Fix export from and native modules in server component (#36072)
This PR fixes a bunch of bugs and it now supports:
- Importing a client component from a nested server component (a.server → b.server → c.client).
- The `export from` syntax in server component (`export { default } from './a.server'`)
- Native modules in server components (currently broken)

## Buga

- [ ] 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-04-13 08:50:36 +00:00
Jiachi Liu
20600ad29f
rsc: remove router injection (#36101) 2022-04-13 10:16:29 +02:00
LongYinan
da6f271d9b
Interpolate module.exports as default import (#36082)
fixes https://github.com/vercel/next.js/issues/34412

## 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.
- [ ] 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-12 14:32:42 +00:00
JJ Kasper
95a8f31d86
Fix outputStandalone with optimizeCss (#36028) 2022-04-11 16:14:28 -05:00
Naoyuki Kanezawa
93678b569b
Do not add locale to link for api route and middleware preflight (#35994)
Fixes https://github.com/vercel/next.js/issues/33578

This PR fixes `Link` component as well to not add locale for api routes since both preflight redirect and link should work the same.

Additionally, it fixes the webdriver method `browser.waitForCondition()` for playwright to not wrap with function string.

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
2022-04-11 15:59:07 +00:00
Donny/강동윤
16f7084e7f
feat(next-swc): Update swc crates (#35996)
* Move

* Adjust

* publish = false

* Tree

* Move tests

* fixup

* Split `emotion`

* Split `styled_jsx`

* Split `styled_jsx`

* fmt

* `--fix`

* clippy

* Update crates

* fixup

* publish

* Bump

* Rename

* authors

* Update

* More update

* Oh

* Update test refs

* Update test refs

* Update again

* Fix
2022-04-11 11:59:16 +02:00
LongYinan
01109734ce
Interpolate default exports (#35933)
* Add failing test for next/link next/image with "type": "module"

* Interpolate default exports

Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
2022-04-11 16:43:44 +08:00
Shu Ding
1ed38dd2d0
Support export all syntax in client components (#36027)
This PR adds the support of the `export * from './foo'` syntax in client components.

## 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-04-09 01:26:16 +00:00
Steven
0a04ab7478
Fix leaking internal config to user-defined loader prop in next/image (#36013)
The `config` was changed from a global variable to a function parameter of the `loader()` function in PR https://github.com/vercel/next.js/pull/33559 as an implementation detail, not as a public API. It was not meant to be used by the end user which is why it was [undocumented](https://nextjs.org/docs/api-reference/next/image#loader).

This config is meant for the default Image Optimization API. Since the `loader` prop bypasses the default Image Optimization API in favor of a custom function, that config is no longer be relevant because the function can implement the optimization url however it desires.

- Fixes #35115
2022-04-08 22:19:25 +00:00
Tobias Koppers
f4fbb83d4a
allow to provide postcss plugin options as a string (#35173)
fixes https://github.com/vercel/next.js/issues/35117

@balazsorban44 this needs a test case

## Bug

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


Co-authored-by: Balázs Orbán <18369201+balazsorban44@users.noreply.github.com>
2022-04-08 16:58:50 +00:00
Jiachi Liu
de0bc57b6e
test: organize react 18 tests (#36003)
* Organize react 18 test cases, group invalid cases to speed up the regular test cases
* Add `runDevSuite` and `runProdSuite` for group next dev/prod test cases

```js
runDevSuite(name, appDir, {
  runTests: (context, env) => { ... },
  beforeAll,
  afterAll,
})

runProdvSuite(name, appDir, {
  runTests: (context, env) => { ... },
  beforeAll,
  afterAll,
})
```
2022-04-08 15:29:35 +00:00
Jiachi Liu
630bf80a22
Support shared component with next built-in client components (#35975)
Fixes #35449

Include the shared components (from source code) is in client bundles, previously we lost them so that the client components imported by them are lost in module graph

* let flight server loader apply to all pages and imported modules (except node_modules at the moment)
* if it's a shared component from source code, include it in client bundle
* ignore handling node_modules at the moment (due to the limitation support of esm imports with RSC)

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [x] Errors have helpful link attached, see `contributing.md`
2022-04-07 19:45:33 +00:00
Shu Ding
51d7153ea8
Add test case for module resolution in node_modules from different contexts (#35978)
The same module should be created as 2 instances if it's imported from different contexts (server or client).

## 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-07 19:16:02 +00:00
JJ Kasper
26aacb04fb
Ensure minimalMode previousCache expire time is capped (#35954) 2022-04-07 11:32:45 -05:00
Jake Jarvis
f308826603
Add .eslintrc.cjs to list of supported next lint config files (#35440)
The logic for finding a user's custom `.eslintrc` config file is missing a check for `.eslintrc.cjs`, which is listed as one of the valid filenames in ESLint's docs:

https://eslint.org/docs/user-guide/configuring/configuration-files#configuration-file-formats

...so this PR makes `next lint`'s list of possible config files consistent with ESLint's.

I stumbled upon this when trying to rename my own config file, since I've pretty much moved completely to ESM by now... but [ESLint doesn't support modules yet](https://github.com/eslint/eslint/issues/14137#issuecomment-785421664), so renaming the file to `.cjs` just keeps things cleaner (and VS Code happier). This is my first PR here so even though I've only changed a couple of lines, please let me know if I'm overlooking something! 😊

## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
2022-04-07 15:03:40 +00:00
John Daly
9110b5a4f1
Emotion SWC Plugin - Allow for jsxImportSource to be configurable (#35963)
* Allowing the jsxImportSource to be configurable when using the Emotion SWC plugin

* Adding test case

* Addressing PR feedback

* Moving getEmotionOptions call back to where it was previously

Co-authored-by: Balázs Orbán <info@balazsorban.com>
2022-04-07 14:33:38 +02:00
Naoyuki Kanezawa
633050402f
fix: add locale prefix to middleware preflight url (#35911)
Fixes part of https://github.com/vercel/next.js/issues/34274

Navigating to `/` causes to redirect preflight request to a url of browser language like `/en`. 
This PR fixes to add the locale prefix always so that the redirect does not happen anymore and middleware can get a correct locale.

## 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-07 11:39:49 +00:00
Shu Ding
ad99734489
Fix flaky test (#35951)
Failed here: https://github.com/vercel/next.js/runs/5855144575?check_suite_focus=true#step:9:1795

## 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-06 20:41:13 +00:00
Naoyuki Kanezawa
9805399faa
Revert "fix the dynamic routing of middleware" (#35932)
Reverts vercel/next.js#32601
2022-04-06 14:35:52 +00:00
Steven
cec388cde2
Fix Firefox flash of white on next/image with placeholder=blur (#35889)
## History

In PR #24153, `placeholder=blur` was added and it set `element.style.backgroundImage = 'none'` instead of using react state to re-render. Then in PR  #25916, a delay was added to handle removing the blur placeholder. Then in PR #25994, `img.decode()` was utilized but we found this caused problems in Firefox in #26011.

## Today

This PR changes the the blur placeholder removal to use react state to re-render. This _should_ prevent Firefox from erroring although we should probably keep the catch() just in case. This was pointed out when React 18 caused subtle differences in Firefox in this comment https://github.com/vercel/next.js/issues/30128#issuecomment-1086754374
2022-04-05 22:47:55 +00:00
JJ Kasper
4a7ab34baf
Update repo to use react 18 by default (#35888)
This updates our `yarn next` command to leverage react v18 by default and removes the need for the test require hook/config modifying when testing react 18. There are some fixtures we need to investigate react 18 support in follow-ups:

- `test/integration/client-navigation-a11y`
- `test/integration/critical-css`
- `test/integration/custom-error-page-exception`
- `test/integration/font-optimization`
- AMP specific tests
2022-04-05 21:51:47 +00:00
Jiachi Liu
67d25a58a4
Custom app for switchable runtime (#35666)
x-ref: #33149
RFCs:
- #30996
- #31506 

## 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
- [x] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`
2022-04-05 19:46:17 +00:00
JJ Kasper
b1a7b88890
Add warning when importing "next" directly (#35884)
* Add warning when importing "next" directly

* Apply suggestions from code review

Co-authored-by: Balázs Orbán <info@balazsorban.com>

* Apply suggestions from code review

Co-authored-by: Steven <steven@ceriously.com>

* add example

Co-authored-by: Balázs Orbán <info@balazsorban.com>
Co-authored-by: Steven <steven@ceriously.com>
2022-04-05 10:57:45 -05:00
JJ Kasper
384953b35c
Stabilize react streaming ISR test (#35885) 2022-04-04 13:35:46 -05:00
Sukka
081e7b0027
fix: reset visible state when src/href changed (#35287)
* fix(#35286): reset visible state when image src changed

* fix(#35286): reset visible state when link href changed

* test(image): image with new src should be re-lazyloaded

* test: apply code suggestions from @styfle's review

* test: incorrect condition of image load check
2022-04-04 14:18:49 -04:00
Alex Castle
352e60dedd
Fix layout="raw" image element sizes prop (#35809)
This fixes an issue with how the sizes prop was being applied to images with the experimental raw layout. The only effects were on the raw layout, so won't effect any non-experimental functionality.
2022-04-01 16:41:02 +00:00
Shu Ding
0eb9f7e76d
Initial implementation of statically optimized flight data of server component pages (#35619)
Part of #31506 and https://github.com/vercel/next.js/discussions/34179. This PR ensures that in the `nodejs` runtime, the flight data is statically stored as a JSON file if possible. Most of the touched code is related to conditions of static/SSG/SSR when runtime and/or RSC is involved.

## 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-04-01 16:13:38 +00:00
LongYinan
8b9ae8314e
Collect packages are used and eliminated in getServerSideProps (#35404)
Collect telemetry info about packages are used and eliminated in `getServerSideProps`

https://github.com/vercel/next-telemetry/pull/71


Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-04-01 15:08:44 +00:00
JJ Kasper
e148d2bdbd
Continue testing react v17 with e2e tests (#35787)
* Continue testing react v17 with e2e tests

* update react 17 expected error

* Update env variable name and add log

* fix starter cache version

* remove extra setup condition

* Revert "remove extra setup condition"

This reverts commit 5760a9f8867213f95a9fac073fe27a9ec01b780f.

* update basepath test

* remove log

* stabilize test
2022-03-31 17:35:00 -05:00
Tim Neutkens
446432719f
Run e2e suite against React 18 (#35774)
* Run e2e suite against React 18

* update test

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-03-31 10:57:21 -05:00
Jiachi Liu
612cc8820d
test: add test for basic dynamic import with react 18 hydration (#35772)
x-ref: #35728

The hydration mismatch is fixed by #35732, that document could collect the dyamic imports module ids before the shell is flushed. Add a test for it
2022-03-31 09:59:31 +00:00
JJ Kasper
d95aed607c
Fix router isReady and react 18 not being detected with no config (#35762)
This fixes `router.isReady` being incorrect in dev mode due to the `isAutoExport` field being false from `hasConcurrentFeatures` being flagged similar to the static 404 in https://github.com/vercel/next.js/pull/35749. While investigating this I also noticed we aren't properly detecting react 18 when no `next.config.js` is present. 

## Bug

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

Fixes: https://github.com/vercel/next.js/issues/35754
x-ref: https://github.com/vercel/next.js/pull/35749
2022-03-31 02:11:00 +00:00
JJ Kasper
fe012ff916
Fix document styles with react 18 (#35760)
This is a follow-up to https://github.com/vercel/next.js/pull/35736 that ensures we use the styles from `_document.getInitialProps` instead of only applying the `styled-jsx` styles. 

## 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/35758
x-ref: https://github.com/vercel/next.js/pull/35736
2022-03-31 00:35:00 +00:00
Donny/강동윤
fdfa3c7bae
feat(next-swc): Update swc crates (#35395)
* Update crates

* fixup

* fix type

* Update test refs

* Update css crates

* Update test refs

* Update test refs

* Update test refs

* SourceMap

* Fix?

* Update crates

* Fix

* Update test refs

* Update test refs

* Update error reporter

* Update snapshots

* Update snapshots

* Bug?

* Fix

* Fix lint

* Update swc again

* fixup

* Update test refs

* Fix

Co-authored-by: Maia Teegarden <dev@padmaia.rocks>
2022-03-30 15:13:40 -07:00
Jiachi Liu
d95d2d35c7
Only resolve page runtime for react 18 and error on read failure (#35705)
* Read the proper page file from either pages directory or from node_modules (inernal pages like _app, _document)
* Only reading page runtime when `reactRoot` is enabled, reduce time for react 17 apps
2022-03-30 20:21:41 +00:00
Martin Nabhan
7b3ec57c62
Fix streaming SSR with multi-byte characters (#35724)
When using streaming SSR decodeText is called repeatedly with incoming
chunks of data. In that case a multi-byte character may occasionally
split between chunks, causing corruption. By setting the TextDecoder
option 'stream' to true, and reusing the same TextDecoder instance,
TextDecoder will memorise “unfinished” characters and decode them when
the next chunk comes.
2022-03-30 20:24:25 +02:00
Shu Ding
0409b384cb
Fix useStatic404 condition (#35749)
Static optimization is now supported with concurrent features, this PR fixes the condition for `useStatic404`.

## 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-03-30 18:12:35 +00:00
JJ Kasper
050936c040
test(fix: Prevent page to scroll to top during data HMR) (#35744)
* fix: Prevent page to scroll to top during data HMR

* Add test for scroll position with gssp refreshing
2022-03-30 11:20:50 -05:00
Shu Ding
600e0b3e4e
Fix _document and getInitialProps with React 18 (#35736)
* wip

* update test

* fix _document logic for edge runtime and rsc

* revert deleted file

* fix lint error

* fix

* remove doc gip test

* Revert "remove doc gip test"

This reverts commit a5fd1d7e58463b8dd92df111bc2ae71a34224ad1.

* fix test

Co-authored-by: Jiachi Liu <inbox@huozhi.im>
2022-03-30 11:10:48 -05:00
Tim Neutkens
62bb3482fe
Fix Fast Refresh for React 18 (#35718)
- Updates the React 18 test suite to the latest React version.
- Upgrade `react-refresh` module

Fixes #35518
Fixes #35703

## 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: Jiachi Liu <4800338+huozhi@users.noreply.github.com>
2022-03-30 12:16:17 +00:00
hiro
a00268e70f
Fix typos (#35683)
* fix(typo): wolrd -> world

* fix(typo): _lineNumer -> _lineNumber

* fix(typo): Dyanmic -> Dynamic

* fix(typo): mutliple -> multiple

* fix(typo): dyanmic -> dynamic

* fix(typo): speical -> special

* fix(typo): acceptible -> acceptable

* fix(typo): dyanmic -> dynamic

* fix(typo): nonexistant -> nonexistent

* fix(typo): nonexistant -> nonexistent

* fix(typo): nonexistant -> nonexistent

* fix(typo): nonexistant -> nonexistent

* fix(typo): nonexistant -> nonexistent

* fix(typo): nonexistant -> nonexistent

* fix(typo): accesible -> accessible

* fix(typo): explicitely -> explicitly
2022-03-28 22:53:51 -05:00
Seth Falco
ad7cb3b207
fix: don't override user-agent in fetch if specified (#35547)
* fix: don't override user-agent in fetch if specified

* Add test for fetch user-agent in middleware

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-03-28 18:04:21 -05:00
OJ Kwon
abfbf41eec
test(integration): emit console error when test fails (#35507)
Minor improvements to the integration test runner to emit process's stdout when its execution failed.

We have `console.log` for the output, but it doesn't emit actually since jest suppresses console output unlesss _assertion_ fails. If we throws in `before*` hook, since there's no actual assertion fails jest won't release captured console logs.

PR adds one straightforward workaround (https://stackoverflow.com/questions/48695717/console-log-statements-output-nothing-at-all-in-jest) to emit if process exits with non-zero errorcode. To avoid any existing behavior, this is not enabled for the cases when process successfully exits.

## 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`
- [x] 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-03-28 21:46:56 +00:00
Naoyuki Kanezawa
53d1b00c7f
fix the dynamic routing of middleware (#32601)
* fix the dynamic routing of middleware

* add middleware to dynamicRoutes of routes-manifest

* remove unused import

* fix middleware routing with static paths

* update manifest version test

* prevent to match with api route using regex

* use iterator instead of generator

* do not use Iterator

* fix type

* fix type

* remove unused import

* apply the fix for support colons

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-03-28 16:16:43 -05:00
JJ Kasper
6a4c70e051
Update default test timeouts for yarn install times (#35669)
This updates our default test times as discussed to account for longer `yarn install` times for the isolated tests as GitHub actions network can be slow. 

x-ref: https://github.com/vercel/next.js/pull/35507#issuecomment-1074606737
x-ref: [slack thread](https://vercel.slack.com/archives/CGU8HUTUH/p1647919982840099)
2022-03-28 20:46:01 +00:00
JJ Kasper
3d5a9bf5e7
Fix next info test during stable release (#35668) 2022-03-28 15:23:39 -05:00
JJ Kasper
12e1bb7d32
Ensure eslint plugins dont conflict (#35667) 2022-03-28 12:31:30 -05:00
Jiachi Liu
41a2eb2303
Clean up legacy react 18 tests (#35615)
### source changes
* Error dynamic suspense option in non concurrent mode, don't check react root anymore since they should be bound

### tests changes

* Remove duplicated rsc client test
* Merge type checking cases (`next/dynamic`)
* Remove blocking rendering tests cases since we should opt-in Fizz rendering when using React.lazy
* Remove some thrown promises cases, leverage the streaming component we had in RSC test
2022-03-28 12:32:34 +00:00
Shu Ding
bb6ea6399d
Fix hydration issue in the switchable runtime tests (#35616)
In this test we are mainly focusing on the SSR'd result so hydration is't critical, but it will definitely help to get rid of these hydration errors.

## 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-03-27 01:02:17 +00:00
JJ Kasper
3a313a4ca6
Fix create-next-app failing without yarn installed (#35608)
This fixes our package manager detection which was changed slightly in https://github.com/vercel/next.js/pull/34947 for `pnpm` support to ensure the default case still attempts detecting the available package manager if no preference is specified in the command args. This also adds a test case to ensure the install succeeds when we fail to detect a valid `yarn` binary and no preference is set via the `npm_config_user_agent` env variable. 

## 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/35607
Fixes: https://github.com/vercel/next.js/issues/35599
2022-03-26 08:29:52 +00:00
Jiachi Liu
d41f8a5ecf
Update terminal tree view for switchable runtime (#35394)
* Update terminal tree view for switchable runtime

* share PageRuntime type

* fix lint
2022-03-26 02:19:51 +01:00
Shu Ding
4f6bb5e4fa
Revert "Revert "Make concurrent features independent from the global runtime option"" (#35490)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Co-authored-by: Jiachi Liu <inbox@huozhi.im>
2022-03-26 00:05:35 +01:00
Jiachi Liu
4e8e191a6e
RSC: handle commonjs in flight loader (#35563)
We need to handle cjs cases for client/server components when they're compiled to commonjs in some cases.
e.g. if there's an internal `_app.server.js` in nextjs, the assets in the dist files are compiled to cjs by swc. Or any 3rd party libraries are consumed could be cjs only.

### How it works

* Detect the source file is ESM or CJS first by detect if there's any ESM import/export
* Append the new exports or collect exports info based on the module type
2022-03-25 21:17:33 +00:00
CommanderRoot
db2567b01b
chore: replace deprecated String.prototype.substr() (#35421)
.substr() is deprecated so we replace it with .slice() which works similarily but isn't deprecated
Signed-off-by: Tobias Speicher <rootcommander@gmail.com>

Co-authored-by: Steven <steven@ceriously.com>
2022-03-24 17:49:38 -04:00
Steven
ef7b53528f
Fix next info accidentally printing stderr (#35556)
I noticed a few issues that had "Output from `next info`" with the first line as

```
/bin/sh: pnpm: command not found
```

This was because `execSync()` was still printing to stderr when a command was not found.

Changing to `execFileSync()` fixed it so we no longer print to stderr when a command is not found.
2022-03-23 22:33:47 +00:00
JJ Kasper
9fef0d55da
Normalize ssgCacheKey for /index with minimalMode de-duping (#35536)
* Normalize ssgCacheKey for /index

* apply test changes to i18n suite as well
2022-03-23 09:28:04 -05:00
JJ Kasper
72478c5c80
Update next/link error when no children are provided (#35453)
* Update next/link error when no children are provided

* update manifest

* Apply suggestions from code review

Co-authored-by: Balázs Orbán <info@balazsorban.com>
2022-03-22 13:58:55 -05:00
JJ Kasper
a2accb2299
Update trace ignore check to check reasons correctly (#35511) 2022-03-22 00:03:42 -05:00
OJ Kwon
c261924756
feat(telemetry): report swc target triple to telemetry (#35420) 2022-03-21 17:09:03 -07:00
JJ Kasper
da3760bbf5
Use check on prerender test assertion (#35482) 2022-03-21 10:00:07 -05:00
Steven
73b83a0b88
Add test to ensure fs.readFile() works with Output File Tracing (#35338)
Add test for `fs.readFile()`

- Related to https://github.com/vercel/vercel/issues/7256
- Related to https://github.com/vercel/next.js/discussions/32236

Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-03-18 22:51:26 +00:00
JJ Kasper
7ca958de88
Update to latest @vercel/nft and leverage new reason types (#35446)
Currently we ignore any files that are traced and handled by a webpack loader to prevent including webpack specific files although users may attempt reading files directly using `fs` even if they are handled by webpack so this leverages the new reason types in `@vercel/nft` to only ignore if it is solely imported. 

## 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/35338
2022-03-18 21:18:24 +00:00
Jiachi Liu
910c48f52b
test: add document head multi child prod test (#35426)
Add production test for #35424
2022-03-18 10:19:55 +00:00
Jiachi Liu
279f47b9ca
Keep fouc tags for streaming (#35417)
Basically the revert change of #31187

The fouc tag are rendered in first place, and the removing fouc tags script is executed before hydration which is early enough. This will unblock the dev mode of global CSS development

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [x] Errors have helpful link attached, see `contributing.md`
2022-03-18 00:19:03 +00:00
JJ Kasper
4365463fd9
Run tests against node LTS (v16) and current (v17) (#35414)
* Run tests against node LTS (v16) and current (v17)

* update pnp tests
2022-03-17 17:47:59 -05:00
Shu Ding
24f450e8aa
Revert "Make concurrent features independent from the global runtime option" (#35405)
Reverts vercel/next.js#35245
2022-03-17 16:31:46 +00:00
Jiachi Liu
60ad1dee76
Make router able to navigate between rsc pages (#35344)
### Bugfix
Made some changes for the data register buffer flushing in #34631 and #34475 that tried to delete the buffer or flush them only once. But turns out it will break the navigation between RSC pages.


### Enhancements
Simplify the inline response writer and inline response data for the initial render. Since they're only for the initial render, navigations will leverage the serialized data fetched from router and construct the react tree.


## Bug

Fixes #35135

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [x] Errors have helpful link attached, see `contributing.md`
2022-03-16 22:04:34 +00:00
Jiachi Liu
efdb87d134
Drop browser field for edge runtime (#35335)
Related to #31678 

For streaming pages,

Nodejs runtime: setting global runtime to `"nodejs"` will work with default module resolution.
Edge runtime: previously next.js will pick up browser field since it's the "similar" asset (unlike nodejs) to edge runtime but browser specific things like DOM api could breaks cause edge runtime is more like worker without dom runtime.

This PR is to revert the main field resolution behavior. And if you have a library targeting multiple runtime with different fields, ideally is to make it more isomorphic and will be easy to use in edge runtime
2022-03-16 15:14:49 +00:00
Shu Ding
853442dfc3
Make concurrent features independent from the global runtime option (#35245)
This PR depends on #35242 and #35243. It allows the global runtime to be unset, as well as enables static optimization for Fizz and RSC pages in the Node.js runtime. Currently for the Edge runtime pages are still always SSR'd.

Closes #31317.

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

## Documentation / Examples

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


Co-authored-by: Jiachi Liu <4800338+huozhi@users.noreply.github.com>
2022-03-16 12:11:57 +00:00
Jiachi Liu
99aea513bf
enhance: cover re-exported gsp cases for runtime fallback (#35326)
Cover re-exported gsp cases from #35011
2022-03-15 13:14:18 +00:00
LongYinan
2e16d02faa
SWC emotion transform plugin (#34687) 2022-03-15 08:51:15 +01:00
Alex Castle
76bad07bdf
Add new 'raw' image layout (#34339)
This PR adds a new layout mode for images called `raw`, as discussed with the core team a while back. This mode has the following characteristics:
 - No wrapper `span` around the `img` element
 - No sizer svg
 - Almost no styles automatically added to the `img` element
 - `style` parameter is allowed and is passed through to the underlying `img` element

This also adds documentation changes to describe the new component.

There are a few tradeoffs and DX decisions that may warrant discussion/revision before merging. I'll add a few comments to highlight those issues.

- Related to #18637
2022-03-14 10:25:23 -04:00
Jiachi Liu
edce68b40c
Bump styled-jsx to 5.0.1 (#35290)
x-ref: https://github.com/vercel/next-react-server-components/issues/35
x-ref: https://github.com/vercel/styled-jsx/pull/788

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [x] Errors have helpful link attached, see `contributing.md`
2022-03-13 20:31:53 +00:00
Houssein Djirdeh
79016b879f
Adds web worker support to <Script /> using Partytown (#34244)
## Summary

This PR adds a new `worker` strategy to the `<Script />` component that automatically relocates and executes the script in a web worker.

```jsx
<Script 
  strategy="worker"
  ...
/>
```

[Partytown](https://partytown.builder.io/) is used under the hood to provide this functionality.

## Behavior

- This will land as an experimental feature and will only work behind an opt-in flag in `next.config.js`:

  ```js
  experimental: {
    nextScriptWorkers: true
  }
  ```

- This setup use a similar approach to how ESLint and Typescript is used in Next.js by showing an error to the user to install the dependency locally themselves if they've enabled the experimental `nextScriptWorkers` flag.

  <img width="1068" alt="Screen Shot 2022-03-03 at 2 33 13 PM" src="https://user-images.githubusercontent.com/12476932/156639227-42af5353-a2a6-4126-936e-269112809651.png">
- For Partytown to work, a number of static files must be served directly from the site (see [docs](https://partytown.builder.io/copy-library-files)). In this PR, these files are automatically copied to a `~partytown` directory in `.next/static` during `next build` and `next dev` if the `nextScriptWorkers` flag is set to true.

## Checklist

- [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
- [X] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.

This PR fixes #31517.
2022-03-11 22:26:46 +00:00
Shu Ding
2b13c2f7fa
Ensure that pages manifest contains pages of both runtimes (#35243)
Previously we only run `PagesManifestPlugin` in the Node server runtime, because the Edge target doesn't need it as the web server and middleware SSR loader specially handled pages manifest. This cases entrypoints with the Edge runtime configured being missing from there and this PR fixes it.

Part of #31317 and #31506.

## 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-03-11 13:33:40 +00:00
Jiachi Liu
088354d4f7
Render resolved streaming content for static render result (#35221)
* Fix the static streaming render result isn't the resolved streaming rendering content (resolve suspense)
* Update readable stream polyfill to fit the w3c standard
2022-03-10 21:34:40 +00:00
Steven
0355e5f63f
Fix next/image when src is webp but browser doesnt support it (#35190)
* Fix `next/image` when src is webp but browser doesnt support it

* Exclude old sharp since it doesnt support AVIF
2022-03-10 15:02:13 +01:00
Jiachi Liu
9bff48b9d5
Adopt react 18 rc2 (#35161)
* Adopt react 18 rc2

* execute shouldUseReactRoot only once

* update test

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2022-03-09 21:12:36 +01:00
Jiachi Liu
81276e213d
Disable the functions manifest plugin (#35155)
Disable the plugin introduced in #33770, will rewrite when manifest consuimg part becomes stable
2022-03-09 15:22:54 +00:00
JJ Kasper
acbd54322f
Ensure mjs files are transformed with jest (#34698)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2022-03-09 13:49:58 +01:00
Shu Ding
201f98e81a
Per-page runtime (#35011)
Partially implements #31317 and #31506. There're also some trade-offs made with this PR: since we can't know if a certain runtime will be used or not beforehand, we have to start both runtime compilers (Node.js and Edge) and then generate entrypoints correspondingly.

Note that with this PR, the global runtime is still required to use the per-page runtime.

## 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-03-08 20:55:14 +00:00
Naoyuki Kanezawa
9e4724dea2
fix: hard-navigate when preflight request fails (#35145)
fixes https://github.com/vercel/next.js/issues/34199

Also fixes response code to return `500` when showing error page of preflight request failure on dev mode

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
2022-03-08 19:51:08 +00:00
Naoyuki Kanezawa
eb878459de
fix post request hangs when no body is consumed on middleware (#35131)
fixes https://github.com/vercel/next.js/issues/34966

Wait for reading original request body before overwriting the request properties with `originalBody?.finalize()` call since it caused the problem when middleware does not read request body

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
2022-03-08 19:24:58 +00:00
Naoyuki Kanezawa
d141376772
[next] Fix to not call middleware with shallow push, fix middleware call wit… (#35047)
…h query parameter

Fixes https://github.com/vercel/next.js/issues/32655 and fixes https://github.com/vercel/next.js/issues/35006

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
2022-03-08 19:03:14 +00:00
Steven
b25f7f84b1
Fix animated png bypass from Image Optimization API (#35120)
- Fixes #34807
- Related commit 69dad3cdf9

Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-03-07 20:29:11 +00:00
Artur Kornakov
0e5e8881c0
Normalize root path according to trailingSlash option in default next/image loader #21337 (#22453)
* fix(next/image): normalize root path according to trailingSlash option in defaul loader

* test(image-optimizer): trailingSlash support

* chore(next/image): prettier

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-03-07 18:55:39 +01:00
Jiachi Liu
ff6b75027b
Enable import assertion syntax parsing (#33750)
## Feature

Enable import assertion syntax parsing for ecmascript/typescript. Since webpack has already supported it, enable import assertion parsing and leave them to webpack to handle

#### Upgration
* tooling: `@swc/core`, `@swc/cli`, prettier to support importAssertion related flags
* typescript related: `typescript` >= 4.5
* babel related: `@babel/plugin-syntax-import-assertions`
* lint parser: `@typescript-eslint/parser`


Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-03-06 20:41:22 +00:00
Jiachi Liu
7083dcfe44
Generate static html for bots (#35004)
* Generate static html for bots

* fix lint

* refactor error handling against comment

* fix streaming on edge for bots

* inline doResolve
2022-03-03 23:39:26 -08:00
Balázs Orbán
62c33c1eb7
feat: support pnpm with create-next-app (#34947)
* feat: support `pnpm` with `create-next-app`

* test: add `--use-pnpm` tests

* docs: mention `--use-pnpm` flag in docs

* test: remove `only`

* Update test/integration/create-next-app/index.test.ts

Co-authored-by: Steven <steven@ceriously.com>

* chore: add pnpm action setup to tests

* chore: use latest pnpm

* chore: debug

* chore: debug

* fix: fall back to `yarn` instead of `npm`

* test: run all tests

Co-authored-by: Steven <steven@ceriously.com>
2022-03-04 00:49:24 +01:00
io
2c7f8b3d7b
Support colons in Middleware NextResponse.rewrite path (#32543)
* Add failing colon rewrite test

* add test fixture

* better colon rewrite tests

* middleware rewrite colon tests with query parameters

* fix #31523

this addresses the symptom but the real systemic issue is that prepareDestination is called on rewrite/redirect URLs, which have no defined special behavior for colons and they should not be compiled at all

* hack around prepareDestination to skip compiling x-middleware-rewrite

this is a bit nicer than just escaping colons, but ideally we find a way to obviate prepareDestination

* obviate prepareDestination for x-middleware-rewrite handling

* don't clobber rewrite query data

* omit redundant type

* catch up to main

* It looks like newUrl should contain only pathname

Co-authored-by: Naoyuki Kanezawa <naoyuki.kanezawa@gmail.com>
2022-03-03 11:36:53 -08:00
Balázs Orbán
728d82663c
feat: allow dotenv default expansion (#34765)
We currently use `dotenv-expand@5` in `@next/env`, which does not support default expansion. It was added in v6 (https://github.com/motdotla/dotenv-expand/pull/39).

Upgrading to the latest version of `dotenv-expand` and fixing an import, the added test passed.

Fixes #34718

## 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-03-03 16:52:20 +00:00
JJ Kasper
81c50f4a87
Handle de-duping revalidations in minimal mode (#34935)
* Handle de-duping revalidations in minimal mode

* fix type

* remove header check

* update other tests

* update test
2022-03-02 15:06:54 -08:00
JJ Kasper
e51d2627d0
Update to re-use cache while revalidate is erroring (#34931) 2022-03-02 14:09:40 -08:00
Steven
937ab16b78
Fix typescript 4.6.2 randomUUID() (#34976)
This PR fixes the latest version of `typescript` (4.6.2) that was failing with the following:

```
Type error: Overload signatures must all be optional or required.
  207 |       array: T
  208 |     ): T
> 209 |     randomUUID?(): string
      |     ^
  210 |   }
  211 | }
```

https://github.com/vercel/next.js/runs/5376232868?check_suite_focus=true#step:8:106

- Related to https://github.com/PeculiarVentures/webcrypto/issues/44

Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-03-02 21:51:15 +00:00
Jiachi Liu
e3d0d645af
Adopt react 18 rc1 (#34972)
### Changes

* Remove top-level suspense boundary
* Pipe stream resolved from returned promimse of `renderToReadableStream`
* Remove jsx-runtime alias hack

### Test Changes

Since top level suspense boundary is removed, now content are filled in 1st SSR
2022-03-02 21:21:18 +00:00
Shu Ding
1f1632979c
Fix named export missing from client components (#34974)
Closes #33538.

## 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-03-02 20:57:50 +00:00
Steven
65e704daa4
Fix next/image noscript when blur and priority (#34973)
Fixes a bug where browsers with scripts disabled did not work with `<Image placeholder="blur" priority />`.

- Introduced in #32918
2022-03-02 19:59:02 +00:00
Shu Ding
a518036246
Refactor export marks of server components (#34945)
* refactor rsc export marks

* fix failed test
2022-03-02 19:29:54 +01:00
Jiachi Liu
d9d494adaf
Provide page runtime parsing utils (#34922)
* parse runtime config

* add test

* fix typing

* fix lint warning

* change branch purging condition

* dont fallback to global runtime
2022-03-02 09:41:41 -08:00
Gal Schlezinger
7b2fb70a67
Expose WASM bindings in Middleware (#34437)
This PR introduces a way to use WASM in middlewares.
Next.js will find all `.wasm` imports in middlewares and load them as `WebAssembly.Module` objects, which then can be later instantiated.
The metadata will be stored in `middleware-manifest.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

- [ ] Make sure the linting passes by running `yarn lint`
2022-03-02 15:09:36 +00:00
Sacha
b579a35e83
[examples] Update styled-components to use SWC (#34770)
* rename example with-styled-components to with-styled-components-babel

* update with-styled-components references

* update docs on react hydratation erros for styled components

* clone with-styled-components-babel without babel config

* add styledComponents to compiler options in next.config

* replace babel dependency with Next.js SWC compiler

* upgrade example typescript version

example with-typescript-styled-components had a typescript dependency
lower than the recommended version. Upgraded from 4.2.4 to 4.5.5.

* Apply suggestions from code review

* update readme for with-styled-components-babel

remove Notes section since it describes a workaround which is no longer
required to work with `next/link`.

Co-authored-by: Lee Robinson <me@leerob.io>
Co-authored-by: Balázs Orbán <info@balazsorban.com>
2022-03-02 03:43:34 +01:00
JJ Kasper
b6b5250c46
Ensure non-matching API routes can be rewritten (#33966)
This ensures non-matching API routes can be rewritten with i18n configured as currently we bail and render the 404 page when a locale prefixed API route is requested. 

## Bug

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

x-ref: [slack thread](https://vercel.slack.com/archives/CGU8HUTUH/p1643930049224689)
closes: https://github.com/vercel/next.js/issues/28921
2022-03-01 15:53:25 -05:00
Steven
0816b775b8
Fix image optimization invalid internal upstream image (#34899)
This gracefully handles errors when the `url` query string param looks like an internal image because it starts with `/` but it is not pointing to an internal image.

Previously, this was printing an unnecessary stack trace when the upstream content-type was undefined.

Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-03-01 16:38:51 +00:00
Jiachi Liu
57702cb2a9
Only warn styles and scripts under next head in concurrent mode (#34897)
x-ref: #34021 , #34004

Only log each warning once and only trigger in concurrent mode


## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [x] Errors have helpful link attached, see `contributing.md`
2022-02-28 22:39:51 +00:00
JJ Kasper
7f9b476341
Update to use whatwg validator for test (#34891)
The w3c validator seems to be down and this shouldn't block our tests so this uses the whatwg validator instead

x-ref: https://github.com/vercel/next.js/runs/5361585193?check_suite_focus=true
x-ref: https://github.com/vercel/next.js/runs/5356851471?check_suite_focus=true
x-ref: https://github.com/vercel/next.js/runs/5361463120?check_suite_focus=true
2022-02-28 19:24:42 +00:00
Shu Ding
8ba2aec022
Fix flight loader for shared components (#34692)
* fix flight loader for shared components

* add tests

* fix condition
2022-02-28 16:00:28 +01:00
JJ Kasper
ed43c03ebb
Add CLI command typo detection (#34836)
* Add CLI command typo detection

* Apply suggestions from code review

Co-authored-by: Steven <steven@ceriously.com>

* Apply suggestions from code review

* Apply suggestions from code review

Co-authored-by: Steven <steven@ceriously.com>
2022-02-26 07:05:26 -08:00
JJ Kasper
c947c93206
Ensure unstable_revalidate does not error from notFound: true (#34826)
* Ensure unstable_revalidate does not error from notFound: true

* add more cache header tests
2022-02-25 14:17:07 -08:00
JJ Kasper
d118d024f7
Clean-up error when starting next with non-existent dir (#34830) 2022-02-25 14:08:08 -08:00
JJ Kasper
d09fb1dc08
Add warning for Yarn PnP v3 with Node.js < 16.14 (#34818)
* Add warning for Yarn PnP v3 with Node.js < 16.14

* Apply suggestions from code review

Co-authored-by: Steven <steven@ceriously.com>

* Apply suggestions from code review

Co-authored-by: Steven <steven@ceriously.com>

* lint-fix

Co-authored-by: Steven <steven@ceriously.com>
2022-02-25 11:54:12 -08:00
Sukka
3ee458e376
fix(#34030): ignore non-checkable jsx spread attribute (#34473)
## Bug

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

Fixes #34030.

The PR is still WIP as the test case hasn't been added, help or change is welcome.

cc @no-ya @ijjk 

Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-02-25 04:15:25 +00:00
Colin Rice
079b507327
Add API config to allow disabling response size warning (#34700)
Adds an API config option that disables warning a user when their API response body is over 4 megs. This has been added for users who'd like to stream larger amounts of data from their API acknowledging the drawbacks. This config mirrors the existing [`externalResolver` config](https://nextjs.org/docs/api-routes/api-middlewares#custom-config).

Closes: [#33162](https://github.com/vercel/next.js/issues/33162)

Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-02-25 02:04:02 +00:00
Keen Yee Liau
fbb8536956
collect telemetry for ESLint rules (#34564)
This commit adds functionality to track usage of `@next/next/*` ESLint rules and their severity levels.

## 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`
- [x] Integration tests added
- [ ] Documentation added
- [x] 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-02-24 20:43:28 +00:00
Eungyeol
58ab94bef7
feat(create-next-app): add @types/react-dom to TS template (#34623)
* Add @types/react-dom devDependencies

* fix: eslint error

* fix: eslint error 2
2022-02-24 21:04:15 +01:00
Shu Ding
c9863c8794
Reduce the size of web server (#34767)
By moving `setRevalidateHeaders` to a separate file we can shake off the dependency of `etag` and a polyfill for `Buffer` from the web server (which brings hundreds of kilobytes).

## 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-02-24 19:53:17 +00:00
Gal Schlezinger
1a0d149c9f
produce source maps for middlewares (#34409)
This PR will generate source maps for middlewares. It's not under any flag (should it be?)

Closes #34523
2022-02-24 15:56:40 +00:00
Shu Ding
cc5345bba8
Add proper headers to responses in web server (#34723)
This PR adds the `X-Powered-By` and `Content-Type` headers to responses sent by the web server. The latter enables compression for the Edge runtime. Still, the web server doesn't have `Content-Length` and `ETag` as the response is usually dynamic.

Part of #31506.

## 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.
- [ ] 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-02-24 12:43:22 +00:00
Shu Ding
586616c4cb
chore: Move test for streaming and RSC (#34724) 2022-02-23 13:06:28 -06:00
JJ Kasper
99ee2225c1
Normalize image optimizer error status codes (#34699) 2022-02-22 19:29:53 -06:00
JJ Kasper
5f1536b3c5
Lock yarn pnp version in tests (#34688) 2022-02-22 10:29:46 -06:00
Jiachi Liu
f110a3735b
Fix rsc bootstrap buffer missing in the future renders (#34631)
## Bug

If there's upcoming streaming data from server components, should safely skip the bootstrap process. Previously we deleted the buffer then it will cause the buffer is missing in the later re-renders. Now we mark it as empty array, so it can safely skip the boostrap phase

x-ref: #34475

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [x] Errors have helpful link attached, see `contributing.md`
2022-02-21 12:40:59 +00:00
Tobias Koppers
94ad03385b
remove commons chunk config (#34445)
This removes the config for the `commons` chunk.

I think the idea was that modules are that in all pages are put into a `commons` chunk, but that breaks when next/dynamic comes into play, which also creates chunks. So the `totalPages` condition is broken and could lead to too many modules placed into the commons chunk.

Example: 2 pages, each has one next/dynamic. Both on demand chunks include module A. page 1 includes module B and next/dynamic on page 2 includes module B. A and B are placed into commons. commonjs chunk is loaded in page 1 and both next/dynamic. Page 1 would load module A even while it doesn't need it.

## 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-02-19 22:26:54 +00:00
Shu Ding
b701de60cd
Improve type imports in server/render and optimize the Edge SSR loader (#34552)
* reorganize imports

* code refactoring

* remove unused variables

* fix test

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2022-02-19 22:13:48 +01:00
Jiachi Liu
6ed281df8e
Support trailingSlash in middleware SSR (#34544)
## Bug

Fixes #34527 

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [x] Errors have helpful link attached, see `contributing.md`
2022-02-18 22:39:28 +00:00
Steven
a4f5463eb5
Improve next/image warnings to avoid printing more than once (#34562)
Currently, we print warnings during `next dev` for every render of `next/image`, which can quickly fill the console making it really unfriendly to developers trying to read the logs.

This PR changes the behavior so that each unique warning prints at most once.

- Related to #33007 
- Related to #31340
2022-02-18 22:02:03 +00:00
Gal Schlezinger
e251a8b2d8
Add test for multiple cookies coming from middleware (#34465)
This PR adds a test that ensures that we can set multiple cookies in a middleware response
2022-02-18 20:35:22 +00:00
Javi Velasco
8752464816
Allow reading request bodies in middlewares (#34294) (#34519)
This PR brings back @Schniz awesome contribution to bring in bodies to middleware. It was reverted to leave it out of the stable release and to have some time to test it out in canary before officially releasing it. This PR is simply a `cherry-pick` of his original work.

Closes: #30953 
Closes: https://github.com/vercel/next.js/pull/34490

Co-authored-by: Gal Schlezinger <2054772+Schniz@users.noreply.github.com>
2022-02-18 19:43:43 +00:00
Gerald Monaco
204a95586d
Remove useMaybeDeferContent hook (#34506) 2022-02-18 13:07:19 -06:00
Steven
9e77ef4ec6
Fix next/image incorrectly warning for position: absolute parent (#34551)
- Fixes #33007 
- Fixes #31340
2022-02-18 18:44:32 +00:00
Jiachi Liu
ce76d1712e
Leverage existing component checking warning for streaming (#34526)
## Bug

Fixes: #31993

* Remove the simple component checking in middleware ssr
* Leverage existing components checking for Component / App / Document, if any of these component is not valid react type or is undefined nextjs will error in dev mode with redbox. Like above.

<img width="826" alt="image" src="https://user-images.githubusercontent.com/4800338/154668945-bcee24ee-17aa-4afd-acda-9f8b249891ac.png">


- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [x] Errors have helpful link attached, see `contributing.md`
2022-02-18 15:25:10 +00:00
Naoyuki Kanezawa
7c103fac7d
fix process polyfill on middleware (#34426)
Fixes the problem that global `process` variable has only the `env` field.
Also fixed the issue that the `env` field is empty when the `process` module is used as the value of the variable (which happens when the module is contained in a dependency of application).

## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
2022-02-18 08:39:30 +00:00
Balázs Orbán
a74af1f31d
fix: mock image path as next/image expects it (#34350)
The default mock value caused `next/image` to throw an error.

Fixes #33976

## 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-02-18 04:15:57 +00:00
Gerald Monaco
944c734d04
Add unstable_useFlushEffects hook (#34117)
Implements https://github.com/vercel/next.js/issues/30997 with some minor tweaks to the design:

* The hook is moved to Client Components (e.g. `pages/_app` instead of `pages/_document`). This was a silly oversight in the original design: the hook needs to be called during server prerendering.

* `useFlushEffects` instead of `useFlushEffect` as there isn't a particularly safe way to implement the singular semantics as a Client Component hook given the current implementation of server rendering.

---

Fixes #30997
2022-02-18 00:18:28 +00:00
Jiachi Liu
1c167afa58
rsc: clean client buffer cache after flushed (#34475)
## Bug

Fixes #34464

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [x] Errors have helpful link attached, see `contributing.md`
2022-02-17 18:57:53 +00:00
Gal Schlezinger
f0f322c0d1
Remove deprecation for relative URL usage in middlewares (#34461)
* Remove deprecation for relative URL usage in middlewares

* fix tests

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-02-17 09:12:36 -06:00
JJ Kasper
b70397e770
Revert "Allow reading request bodies in middlewares (#34294)" (#34479)
This reverts commit 1edd8519d6.
2022-02-17 08:45:31 -06:00
JJ Kasper
42020114d2
Update font-optimization test snapshot (#34478) 2022-02-17 08:39:45 -06:00
Gal Schlezinger
1edd8519d6
Allow reading request bodies in middlewares (#34294)
Related:

- resolves #30953
2022-02-17 11:32:36 +00:00
Steven
2264d35b64
Fix .svg image optimization with a loader prop (#34452)
* Fix .svg image optimization with a `loader` prop

* Add test

* Revert test back to 266x266
2022-02-16 17:48:17 -06:00
JJ Kasper
59714db16d
Update server-only changes HMR handling (#34298)
* Update server-only changes HMR handling

* Add failing tests for GS(S)P server only changes

* update test

* normalize backslashes

* Update to xor the chunk hashes

* remove test change

* remove other test change
2022-02-16 16:32:24 -06:00
Steven
8a55612c0d
Add image config for dangerouslyAllowSVG and contentSecurityPolicy (#34431)
## Feature

- [x] Integration tests added
- [x] Documentation added
- [x] Errors have helpful link attached, see `contributing.md`



Co-authored-by: Lee Robinson <9113740+leerob@users.noreply.github.com>
2022-02-16 19:28:22 +00:00
Balázs Orbán
9639fe704c
Ensure we don't poll page in development when notFound: true is returned (#34352)
Fixes: #34342

Visiting the following page will call gSSP indefinitely in a loop and logs errors from `on-demand-entries-client`:
```js
const Home = () => null
export default Home
        
export function getServerSideProps() {
  console.log("gssp called")
  return { notFound: true }
}
```

We should not keep fetching the page if it returns 404 as  it can introduce unnecessary data requests.

## 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>
2022-02-16 18:53:48 +00:00
Aman Mittal
634926d8df
Add Error Handing section for ISR (#34360)
* Add Error Handing section for ISR

* Apply suggestions from code review

* update check

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-02-15 14:22:15 -06:00
Jiachi Liu
00ca8df26c
test: add inline flight response reuse test (#34364)
To collect the requests starting from page load, we need to register event listeners before page loading (`page.goto` API invocation). By default webdriver will wait for hydration, so we need to register events inside `browser.loadPage` to ensure we can collect the requests before hydration is done.

### Changes
* Add `beforePageLoad` for next webdriver
* registry page `'request'` event before loading page
* update related tests for agruments change

### Usage

```js
browser = await webdriver(appPort, '/path', {
   waitHydration, // default true
   retryWaitHydration, // default false
   disableCache, // default false
   beforePageLoad, // default undefined
})

```
2022-02-15 18:53:45 +00:00
JJ Kasper
982b65a327
Ensure invalid request to static page is handled correctly (#34346)
* Ensure invalid request to static page is handled correctly

* update test
2022-02-15 11:28:18 -06:00
Tim Neutkens
62b1704e41
Add support for "type": "module" in package.json (#33637)
- [x] Add failing test for development / production
- [x] Add failing test for client-side JavaScript
- [x] Write `.next/package.json` with `"type": "commonjs"
- [x] Fix issue with client-side JavaScript showing `module` is not defined

Production works after these changes. Development breaks on module not existing because of the Fast Refresh loader. Working with @sokra to add alternatives to what is being used in the loader to webpack so that it can be updated.

Fixes #23029, Fixes #24334



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

- [ ] Make sure the linting passes by running `yarn lint`
2022-02-15 16:24:11 +00:00
Alex Castle
f516304649
Remove experimental image optimization feature (#34349)
This PR removes the experimental `optimizeImages` flag. This feature was designed to automatically add preload tags for images, but I was never able to get it to do a very good job of selecting the images that actually need preloading.

This feature never graduated from experimental and in fact we never even publicized it as an experimental feature for people to try.

Additionally, even if someone was using this feature, it wouldn't have a functional effect, only a performance effect (removal of some preloads).

For those reasons, I believe it is safe to remove this functionality and that it is not a breaking change.
2022-02-15 01:36:51 +00:00
Shu Ding
2f7951892e
fix double render in strict mode (#34333)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2022-02-14 22:35:05 +01:00
Shu Ding
468833e0b4
Fix <RouteAnnouncer/> shouldn't announce initial path under strict mode and React 18 (#34338)
As the comment mentioned, React 18 with Strict Mode enabled might cause double invocation of lifecycle methods. This makes the `<RouteAnnouncer/>` being non-empty for the initial page, which is a bug (it should only announce page change whenever a navigation happens).

## 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-02-14 19:18:39 +00:00