Commit graph

252 commits

Author SHA1 Message Date
JJ Kasper
26aacb04fb
Ensure minimalMode previousCache expire time is capped (#35954) 2022-04-07 11:32:45 -05: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
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
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
JJ Kasper
12e1bb7d32
Ensure eslint plugins dont conflict (#35667) 2022-03-28 12:31:30 -05: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
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
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
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
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
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
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
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
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
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
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
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
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
JJ Kasper
b70397e770
Revert "Allow reading request bodies in middlewares (#34294)" (#34479)
This reverts commit 1edd8519d6.
2022-02-17 08:45:31 -06:00
Gal Schlezinger
1edd8519d6
Allow reading request bodies in middlewares (#34294)
Related:

- resolves #30953
2022-02-17 11:32:36 +00:00
Jiachi Liu
477134d8c9
Enable dynamic HTML in minimal mode (#34222)
Follow up for #34068

Let minimalMode render HTML by streaming facilities
2022-02-11 17:43:39 +00:00
Balázs Orbán
46e32ae184
feat: copy .env file in standalone mode (#34143)
Ref: #33897

I took a naive approach and simply added `.env` to the files that need to be copied.

Do we want to include `.env.production` as well? Ref: https://nextjs.org/docs/basic-features/environment-variables#loading-environment-variables

(I haven't tested what happens if the file does not exist on copy.)

Other files like `.env.*local` or `.env.{test,development}` don't make sense to copy.

## 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-02-10 17:48:14 +00:00
JJ Kasper
28f65ff411
Fix image-optimizer requires in next-server (#34141) 2022-02-09 12:37:55 -06:00
Tim Neutkens
40329a70a5
Add check for resolveWeak to next/dynamic (#33908)
Fixes #33476

I've added the test for this but it passes either way, even when the change to loadable.js is not made. On the reproduction I was able to reproduce it consistently and it's fixed with this change. 



## 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-08 14:02:53 +00:00
Sanna Jammeh
e0c7794208
Add decoratorMetadata flag if enabled by tsconfig (#32914)
fixes #32913
Adds support for decorator metadata in SWC when enabled through ts/jsconfig.

## 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: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-02-06 16:48:09 +00:00
Hannes Bornö
8aa3620a16
Babel & next-swc: Fix exporting page config with AsExpression (#32702)
fixes #20626

No changes needed in next-swc, see comments from @kdy1 below.

Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-02-05 21:15:49 +00:00
JJ Kasper
f841307fa0
Fix parsing params for i18n optional route in minimal mode (#33896)
This fixes our parsing of params with i18n for optional catch-all routes and ensures a regression test catches this case.

## 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/30631
2022-02-02 19:02:03 +00:00
Tim Neutkens
3bac02e032
Enable jest hoist transform when using next/jest (#33731)
Fixes #32539

Implements what was shared at https://github.com/vercel/next.js/issues/32539#issuecomment-1023139083.



## 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-01-31 16:15:15 +00:00
Balázs Orbán
0d642f1264
feat: make compress configurable in standalone mode (#33717)
Fixes #33696

## 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-01-27 02:13:10 +00:00
JJ Kasper
e8c15e5991
Ensure fetch polyfill is loaded in next-server (#33616) 2022-01-24 15:38:54 -06:00
JJ Kasper
f5fb18198c
Ensure optional value normalizing is correct for index (#33547)
This fixes a case where optional catch-all route values aren't normalized to an array properly when the `index` value is passed. An additional test case has been added to prevent regressing on this. 

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

## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
2022-01-21 23:16:24 +00:00
JJ Kasper
25d064f812
Pre-compile more dependencies (#32742)
This ncc's some remaining dependencies bringing us under 20 install time dependencies (including nested dependencies), this also reduces install size by another `2.75 MB`. A follow-up PR will investigate a custom install script for our swc packages to allow us to remove the `optionalDependencies` which is slowing down install time as well. 

x-ref: https://github.com/vercel/next.js/pull/32679
x-ref: https://github.com/vercel/next.js/pull/32627
x-ref: https://github.com/vercel/next.js/issues/31887
x-ref: https://github.com/vercel/styled-jsx/pull/770
2022-01-17 15:17:22 +00:00
JJ Kasper
389432048c
Update check for fallback pages during export (#33323)
This fixes our check for fallback pages during `next export` as we are currently erroring even when the erroneous pages are not included in the `exportPathMap`. This also adds additional tests to certify the expected behavior for the error. 

## 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/29135
2022-01-17 14:44:45 +00:00
Gal Schlezinger
e69500462d
middlewares: limit process.env to inferred usage (#33186)
Production middlewares will only expose env vars that are statically analyzable, as mentioned here: https://nextjs.org/docs/api-reference/next/server#how-do-i-access-environment-variables

This creates some incompatibility with `next dev` and `next start`, where all `process.env` data is shared and can lead to unexpected behavior in runtime.

This PR fixes it by limiting the data in `process.env` with the inferred env vars from the code usage. I believe the test speaks for itself 🕺 

<!--
## 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-01-12 13:09:24 +00:00
Gal Schlezinger
4aa9879dcc
Allow dependencies to use environment variables in middlewares (#33141)
After discussing with @sokra, seems that the proposed solution is split in two:

* We need to make sure that the `process` polyfill uses `global.process` if available. This is because middlewares are bundled using `browser` target and therefore `process.env.MY_ENV` gets shimmed into `require('process').env.MY_ENV`.

* Allow `process.env` to be statically analyzed for dependencies so they will be exported to the manifest.

Related issues:

* should fix #33043.
2022-01-10 18:45:00 +00:00
Tobias Koppers
f0ad19aef6
use a separate webpack runtime for middleware (#33134)
it should not leak into the client runtime

cc @javivelasco 



## 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-01-10 17:41:53 +00:00
Simon Kirsten
6f5bfc1b40
Fix middleware at root in standalone mode (#33053)
Fixes [a small bug](https://github.com/vercel/next.js/pull/32967#issuecomment-1006277236) that caused the build to crash if a _middleware is present at the root of the project and standalone mode is enabled.
2022-01-06 16:20:43 +00:00
JJ Kasper
e01ef297e7
Ensure middleware is output in standalone mode (#32967) 2022-01-03 18:47:18 -06:00
JJ Kasper
2a5c21b65c
Update to filter loader specific files from traces (#32267)
* Update to filter loader specific files from traces

* remove debug log
2021-12-14 10:41:10 -06:00
JJ Kasper
769d68047b
Ensure conf type for createServer is not changed (#32134)
This reverts the type for the `conf` field in `ServerOptions` isn't changed to require all `NextConfig` values as this is a breaking change from what was previously required. We should investigate making sure this field is normalized when it is provided via a user. 

## 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/32123
x-ref: https://github.com/vercel/next.js/pull/31858
2021-12-04 22:57:54 +00:00
JJ Kasper
cc9e1ea3a1
Fix middleware types with skipLibCheck: false (#32025)
This ensures type checking passes correctly for middleware types when `skipLibCheck: false` is set in `tsconfig.json`. This also moves the `middleware-types` to be an isolated test to ensure it isn't relying on any monorepo dependencies. 

## Bug

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

Fixes: https://github.com/vercel/next.js/issues/31992#issuecomment-984174872
2021-12-02 18:49:49 +00:00
JJ Kasper
be03a1d17b
Remove .only and ensure jest lint rules apply for all tests (#31456) 2021-11-15 12:46:12 -06:00
JJ Kasper
6b89fbf12d
Ensure asPath is correctly normalized in minimalMode with i18n (#31281)
This ensures the `asPath` and `req.url` values are normalized correctly for fallback pages with i18n in minimal mode. This also copies the minimal mode test suite to run against i18n as well. This also fixes an issue where rewrite params weren't passed correctly on the client when no params were already used in the destination. 

The provided reproduction has been deployed against this patch [here](https://nextjs-error-repro-9zdu3sp5r-ijjk-testing.vercel.app/page/test-page) show it working. 

## 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/27563
Fixes: https://github.com/vercel/next.js/issues/30203
2021-11-11 20:11:50 +00:00
JJ Kasper
eb7b40171a
Add initial standalone build handling (#31003)
* Add initial standalone handling

* apply suggestions

* Apply suggestions from code review

Co-authored-by: Steven <steven@ceriously.com>
2021-11-09 11:03:20 -06:00
JJ Kasper
fab345d952
Ensure decode error in minimal mode responds with 400 not 500 (#31037)
This ensures we handle decode failures in minimal mode as a 400 response (bad request) instead of a 500 (server error). 

## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
2021-11-05 23:39:52 +00:00
JJ Kasper
097fb3ca07
Revert incremental config to fix missing types (#30644)
* Revert incremental config to fix missing types

* Add failing test
2021-10-29 23:16:11 -05:00
JJ Kasper
9eceb95596
Move outputFileTracing config up (#30295)
* Move outputFileTracing config up

* remove old nftTracing config

* remove old config

Co-authored-by: Steven <steven@ceriously.com>
2021-10-25 23:22:45 -05:00
JJ Kasper
7054096b76
Move tracing next-server to next build (#30190)
As discussed this moves tracing `next-server` into `next build` since the pre-trace at publish time isn't able to reliably give us file locations since `node_module` file locations can vary based on installation. This also adds caching the trace so that we only need to retrace `next-server` when a lockfile changes. 

A follow-up PR will add documentation for these traces explaining how they can be leveraged. 

## Bug

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

## Feature

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

## Documentation / Examples

- [ ] Make sure the linting passes by running `yarn lint`
2021-10-22 23:49:38 +00:00
JJ Kasper
ebc1b0e559
Fix missing trace items and migrate required files test (#29649) 2021-10-05 13:52:19 -05:00