Commit graph

2418 commits

Author SHA1 Message Date
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