Commit graph

5577 commits

Author SHA1 Message Date
Tim Neutkens
3a6bd135dd v12.1.7-canary.16 2022-05-25 11:46:55 +02:00
JJ Kasper
b68d9eafa4
Rename app paths folder (#37146) 2022-05-25 11:46:26 +02:00
Shu Ding
cc254cc19c
Use customized chunk loading implementation (#37163)
Follow-up PR for #37134, this PR adds back the hash in each chunk's filename. This `chunks` in the flight manifest will now be `chunkId:chunkFilename` with this PR, and `globalThis.__next_chunk_load__` then handles the chunk registration (uses chunkId) and chunk loading (uses chunkFilename). (Q: how can we port this to React?)

We can't use `[contenthash]` but only `[chunkhash]` because at the stage of generating the flight manifest, the content isn't finalized and the hash changes after that.

## 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-24 22:04:27 +00:00
JJ Kasper
780be60d23
v12.1.7-canary.15 2022-05-24 15:50:04 -05:00
d-suke
13747476b8
should render the correct sizes passed when a noscript is rendered (#37161)
## Bug

- [x] Fixes #36807
- [x] Unit tests added

Please review this PR.

As shown in [this Issue](https://github.com/vercel/next.js/issues/36807), the noscript element does not render sizes correctly during SSR.
This change adds `noscriptSizes` to the props passed to `ImageElement` to generate the same `sizes` and `srcset` as the normal img tag that is actually rendered in the browser.
2022-05-24 19:25:05 +00:00
JJ Kasper
18dc7e1a49
v12.1.7-canary.14 2022-05-24 13:34:36 -05:00
stefanprobst
1cd76b9e66
Avoid anonymous function in next/link (#37154)
Avoid anonymous function in `next/link` so DevTools show `Link` instead of `Anonymous`:

Before:

![Screenshot_20220524_123016](https://user-images.githubusercontent.com/20753323/170018947-2d9bdd58-5311-4bba-ab6b-4dc9547092f6.png)

After:

![Screenshot_20220524_122946](https://user-images.githubusercontent.com/20753323/170018968-2993a24a-5518-4de1-b7a4-75cc6d6562f2.png)

## 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-24 16:00:22 +00:00
Shu Ding
2a89c1926d
Fix client component hydration (#37134)
This PR makes sure that chunks of client components can be loaded via `__webpack_chunk_load__`, and hydrated correctly inside `viewsDir`.

Side note: we have to get rid of `[contenthash]` from the chunk filename because of a conflict currently which can be resolved later.

## Bug

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

## Feature

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

## Documentation / Examples

- [ ] Make sure the linting passes by running `yarn lint`
2022-05-24 14:54:26 +00:00
Tim Neutkens
e636234b2c v12.1.7-canary.13 2022-05-24 12:21:19 +02:00
Donny/강동윤
a463553da2
Update swc (#37149)
* Update swc

* Update test refs

* Update test refs
2022-05-24 00:56:45 -05:00
Donny/강동윤
76fbae93fc
Update swc (#37148) 2022-05-23 23:50:25 -05:00
JJ Kasper
b77ac14529
v12.1.7-canary.12 2022-05-23 19:29:03 -05:00
Andrew Matthews
f1d1c46b99
Fix example extraction when branch name contains slash (#37140)
* convert slashes to dashes for accurate filename

* Apply suggestions from code review

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-05-23 18:54:07 -05:00
Sukka
e57e2753f1
fix(typescript): worker execution failed with custom next.config.js (#37125)
## Bug

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

The PR fixes #37122, an issue introduced by #37105.

`next.config.js` might/will include functions (custom `webpack`, `generateBuildId`, `exportPathsMap`, etc.) that are not able to pass from the main thread to a worker. The PR fixes the issue by only passing primitive args to the worker.
2022-05-23 20:30:48 +00:00
Sukka
d64512f02f
chore(devDeps): bump @vercel/ncc to 0.33.4 (#37113)
## 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`

`yarn dev` failed (exit 1) on Node.js 17 & Node.js 18:

```
ncc_amp_optimizer failed because error:0308010C:digital envelope routines::unsupported
[...]
ncc_next__react_dev_overlay failed because error:0308010C:digital envelope routines::unsupported
```

The issue was reported to `@vercel/ncc` (https://github.com/vercel/ncc/issues/805) and fixed by https://github.com/vercel/ncc/pull/868, and `@vercel/ncc@0.33.2` includes the fix. However, Next.js still uses `@vercel/ncc@0.33.1` in `devDependencies`.

The PR bump `@vercel/ncc` to the latest version (which is 0.33.4).
2022-05-23 20:02:44 +00:00
JJ Kasper
2b93e38d67
Add libc field to swc packages (#37131) 2022-05-23 14:18:40 -05:00
Steven
0ac0f594dc
Bump @vercel/nft to 0.19.1 (#37129)
Bump `@vercel/nft` to 0.19.1 https://github.com/vercel/nft/releases/tag/0.19.1

Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-05-23 18:33:55 +00:00
Jiachi Liu
fc06fe6562
Remove process.cwd usage from path polyfill (#37130)
Avoid process usage detection warning for edge runtime bundle
2022-05-23 17:56:00 +00:00
Tim Neutkens
1b4e2ccd63 v12.1.7-canary.11 2022-05-23 13:35:21 +02:00
Sukka
d1122f8282
perf: run type check and eslint in parallel (#37105) 2022-05-23 11:25:09 +02:00
Damien Simonin Feugas
4e6b6a5b86
feat(middleware): issues warnings when using node.js global APIs in middleware (#36980) 2022-05-23 11:07:26 +02:00
Charles Stover
f9ed7954bf
Support TS exactOptionalPropertyTypes (fixes #35280) (#35281)
fixes #35280

Before:

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

After:

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

* lint-fix

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

* update type

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

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

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

- [ ] Related issues linked
fixes #32656



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

## Bug

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

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

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

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

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

  // ...
}
```

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

---

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

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

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

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

Fixes #25560



## Bug

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


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

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


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

* Document openAnalyzer option

* add type

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

* Revert "improve getStaticProps error message"

This reverts commit 60544afac1e971d62f3273e2b5600d8b28d94764.

* apply suggestion

* rm .only

* update test

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

* Update package.json

* update type

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



## Bug

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

## Feature

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

## Documentation / Examples

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


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

* Add test

* update test

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

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

In addition, it reduces the bundle size.

* ensure formatting matches

* update test

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

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



## Bug

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

## Feature

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

## Documentation / Examples

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

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

Fixes #36823 
Closes #33084

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

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


## Bug

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

## Feature

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

## Documentation / Examples

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


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

## Bug

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

## Feature

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

## Documentation / Examples

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

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

## Feature

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

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

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

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

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

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

* lint-fix

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

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

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

* Fix merge error/check and add test

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

## Documentation / Examples

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

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [x] Docs updated
2022-05-20 18:07:20 +00:00
Javi Velasco
036ffa7057
Extract and refactor getPageStaticInfo (#37062)
Extract config parsing
2022-05-20 14:24:00 +02:00