Commit graph

1702 commits

Author SHA1 Message Date
Tobias Koppers
08baf526ff
improve react-loadable-plugin (#24281)
Co-authored-by: JJ Kasper <jj@jjsweb.site>



## Bug

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


Closes: https://github.com/vercel/next.js/issues/22741
2021-04-21 11:18:05 +00:00
Brandon Bayer
8ccfff10ae
fix types of next-webdriver (#23995)
This does not touch any next.js code. This improves the integration test setup by properly typing next-webdriver.
2021-04-20 18:40:51 +00:00
Gerald Monaco
1f5f0d313a
Fix metrics measurements under new root API (#24110)
Previously, we weren't recording most (all?) of the Next.js measurements like `Next.js-hydration` in Concurrent Mode. This was mainly because the new API doesn't accept a callback.

Instead of special casing this, I've refactored it so that the measurements are just recorded when Root first flushes (via `useLayoutEffect`), which should be more or less the same timing for the old API.

Concurrent Mode is a little trickier for two reasons:

1. Flushes might be (slightly) delayed due to time-slicing and prioritization
2. Selective hydration might skew measurements in cases where full hydration is aborted

I don't have a good answer for those yet, so they'll need to be addressed when the time comes.
2021-04-20 15:37:32 +00:00
JJ Kasper
e532c58c23
Ensure locale cookie does not error with similarly named cookie (#24182)
This ensures we don't error when a cookie with a similar name to the `NEXT_LOCALE` cookie is present. 

## Bug

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

Fixes: https://github.com/vercel/next.js/issues/23787
Closes: https://github.com/vercel/next.js/pull/23788
2021-04-20 13:41:14 +00:00
Tobias Koppers
cc246cdc41
add css to the stats-app (#24228)
add a page with CSS to the stats app

We should compare stats for CSS too
2021-04-19 17:42:40 +00:00
JJ Kasper
65588083db
Ensure query for static pages with rewrites is updated correctly (#24189)
This updates the query refreshing on the client to also refresh when rewrites are used and the page is static since additional query values can be provided from rewrites that are relied on client-side. An additional test has been added in the custom-routes suite to ensure this is working correctly. 

## Bug

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

Fixes: https://github.com/vercel/next.js/issues/23490
Fixes: https://github.com/vercel/next.js/issues/22931
Fixes: https://github.com/vercel/next.js/issues/21062
2021-04-18 10:00:04 +00:00
JJ Kasper
6e7245cddb
Add error for getStaticPaths on non-dynamic page (#24188)
Noticed in this issue the reproduction was using `getStaticPaths` on a non-dynamic page incorrectly although we don't currently show an error for this. 

## Bug

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

x-ref: https://github.com/vercel/next.js/issues/22931
2021-04-18 09:31:40 +00:00
JJ Kasper
a153b63240
Ensure locale is not duplicated from differing casing (#24187)
This ensures we don't attempt adding a locale to a path when the locale is already present but in a different casing, this also ensures we successfully remove the locale if the casing differs in the path. Additional tests have been added in the `i18n-support` suites to ensure this is working correctly. 

## Bug

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

Fixes: https://github.com/vercel/next.js/issues/23553
2021-04-18 09:01:01 +00:00
umarsenpai
9fcfce3463
Fix serving Images through external rewrite with Image component (#21001)
This PR fixes the issue described here: https://github.com/vercel/next.js/issues/20909

The _req passed to getRequestHandler doesn't have `on` function which is required by http-proxy. It throws the error e.on is not a function. We should also wait for buffer to finish writing before sending the response. 

Fixes: https://github.com/vercel/next.js/issues/20909
Closes: https://github.com/vercel/next.js/issues/24177
2021-04-17 21:03:08 +00:00
JJ Kasper
7d77a19af2
Fix fallback: false triggering 404 before rewrites (#24121)
This fixes dynamic pages with `fallback: false` that don't have a matching path causing a 404 before rewrites are checked unexpectedly. This ensures we treat `fallback: false` pages as a match only if they also have a matching static path so that fallback rewrites can be triggered correctly. An additional test suite as been added to ensure this is working as expected. 

## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
2021-04-16 15:07:24 +00:00
James George
4b8e539628
test(create-next-app): use latest examples (#24048)
Update CNA test suite to consume [vercel-learn-starter](https://github.com/vercel/next-learn-starter) as the example repo.

## Bug

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

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

## Documentation / Examples

- [ ] Make sure the linting passes
2021-04-16 13:39:34 +00:00
Martin Alix
b2ee0a93fe
Fix IE11 incompatibility due to string litterals (#23784)
Fixes #22270

## Bug

- [X] Related issues linked using `fixes #number`
- [  ] Integration tests added
2021-04-15 16:34:52 +00:00
JJ Kasper
35258650ac
Update with-electron test (#24036)
* Use ssh for git regexr dependency

* remove .git from dep

* update

* update test

* update step

* update install

* remove dep temporarily

* remove extra change

* move deps to specific test
2021-04-15 10:21:32 -05:00
Tobias Koppers
1c2ee7c6b8
improve pr stats action (#24086)
* add cache build duration tracking
* default = webpack 5
* better hash handling
* allow to opt-out of webpack5 via `future.webpack5: false`
2021-04-15 11:46:56 +00:00
JJ Kasper
1797fc50ab
Fall back to default components when a top-level error occurs (#24079)
This fixes an internal server error showing when a top-level error occurs in `_app` in development instead of the dev overlay. This includes the failing test case from https://github.com/vercel/next.js/pull/24069 and also ensures the overlay is cleared when the error is corrected. 

## Bug

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

Fixes: https://github.com/vercel/next.js/issues/24070
Closes: https://github.com/vercel/next.js/pull/24069
2021-04-15 10:19:19 +00:00
Gerald Monaco
cb7ef3feb5
Add react@experimental testing (#23359) 2021-04-13 19:16:45 +02:00
JJ Kasper
4d291bd810
Use regex lexer for gathering named groups from has (#23626)
This is a follow-up to https://github.com/vercel/next.js/pull/23588 to update to use a regex lexer to gather the named regex groups instead of attempting to gather them through executing the regex since it can fail to gather the regex groups when they are using specific matching. This also ensures we don't pass the value as a segment when value is defined and it doesn't use a capture group. Additional tests are added to cover these cases and documentation updated to reflect this. 

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

## Bug

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

## Documentation / Examples

- [x] Make sure the linting passes
2021-04-13 12:34:51 +00:00
Shu Ding
b610db830e
Add request deduplication to image optimizer (#24000)
This PR adds the deduplication logic to image optimizer so the cache will be reused as much as possible if there're multiple concurrent requests.

Fixes #23436.

## Bug

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

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

## Documentation / Examples

- [ ] Make sure the linting passes
2021-04-12 22:38:51 +00:00
Tim Neutkens
2dba861ea3
Enable webpack5 by default (#23810)
- Enable webpack 5 by default for apps without custom webpack configuration

Fixes #23143



## Bug

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

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

## Documentation / Examples

- [ ] Make sure the linting passes
2021-04-12 17:52:43 +00:00
JJ Kasper
ec62ea6134
Ensure minimal mode SSR 404 handling is correct (#23996) 2021-04-12 11:31:51 -05:00
JJ Kasper
f02363e0c4
Ensure no-op rewrite matches dynamic route with i18n correctly (#23860)
This ensures we match dynamic routes correctly when applying `check: true` behavior with i18n so that no-op rewrites match dynamic routes correctly. 

## Bug

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

Fixes: https://github.com/vercel/next.js/issues/23854
2021-04-12 09:42:01 +00:00
James George
428a7de5b5
test(create-next-app): suppplying --use-npm prefers npm for installation (#23880)
This PR aims at updating the `create-next-app` test suite to include a test case for the `--use-npm` flag.

## Bug

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

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

## Documentation / Examples

- [ ] Make sure the linting passes
2021-04-12 09:12:00 +00:00
JJ Kasper
348115036c
Ensure no-op export returns without error (#23752)
This ensures we don't reach the invariant from trying to create the export progress with no items during `next build` or `next export` by returning immediately when we notice there are no paths being exported. Additional tests have been added to ensure these cases don't error. 

## Bug

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

Fixes: https://github.com/vercel/next.js/issues/23724
2021-04-06 17:12:23 +00:00
JJ Kasper
45b8c88521
Ensure fallback rewrites dont match over pages with i18n (#23674)
This ensures we are checking the filesystem correctly when i18n is used to prevent fallback rewrites from being applied even when a page is matched. Additional tests have been added to ensure these cases are being handled. 

## Bug

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

Fixes: https://github.com/vercel/next.js/issues/23577
2021-04-06 10:25:04 +00:00
JJ Kasper
55c6b7aba2
Ensure basePath is not applied for external GSSP redirect (#23673)
This ensures we don't attempt prepending the `basePath` for external (http://) `getStaticProps`/`getServerSideProps` redirects. Additional tests to cover this case have been added in the `gssp-redirect` test suites to prevent regression.

## Bug

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

Fixes: https://github.com/vercel/next.js/issues/23623
2021-04-06 10:02:13 +00:00
Felipe Lima
c2c1b96544
Fix webpack5 cache distDir (#23718)
## Bug

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

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

## Documentation / Examples

- [ ] Make sure the linting passes

Fixes: #23716
2021-04-06 08:32:29 +00:00
Janicklas Ralph
8fdcc52854
Font optimization (#21676)
Enable font optimization by default
2021-04-05 17:47:03 +00:00
JJ Kasper
88fd76f4d2
Ensure default fallback values are correct with i18n (#23675)
This ensures we don't parse the default params when auto-exporting dynamic routes with i18n since the page and path aren't equal when localized. This adds an additional test case to ensure we don't regress on this behavior in the `i18n-support` test suites.

## Bug

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

Fixes: https://github.com/vercel/next.js/issues/23167
2021-04-04 14:09:20 +00:00
Shu Ding
2ed54cddfa
Update decoder to correctly handle grayscale PNGs (#23393)
This PR updates the Squoosh PNG decoder, which fixes #22929 in GoogleChromeLabs/squoosh#971.

## Bug

- [x] Fixes #22929
- [x] Integration tests added

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

## Documentation / Examples

- [ ] Make sure the linting passes
2021-04-01 15:16:26 +00:00
JJ Kasper
65c22167c8
Ensure has segments are allowed in destination (#23588)
This ensures we gather segments from the experimental has field when validating segments used in the destination to prevent the invalid segments in the destination error from showing incorrectly. This usage has been added to the custom-routes test suite to ensure the segments are passed correctly from the has field. 

Fixes: https://github.com/vercel/next.js/issues/23415

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
2021-04-01 09:15:28 +00:00
Joe Haddad
eecc3342cb
Temporarily remove experimental ESLint integration (#23521)
This pull request **temporarily** removes ESLint, as it was not landed in accordance with our standard experimental policies. We are fully committed to landing this change again.

This is being reverted because:

- Next.js has very strict goals for its install size. This feature resulted in adding over 17MB, or a 43.6% increase.
- The feature was not first landed under the `experimental` key in `next.config.js`, rather, it was added under the stable namespace (top-level)
- Using the feature doesn't do a "guided setup" like TypeScript, it should ask you to "bring your own" dependencies for ESLint
- It uses a undesirable ESLint plugin name: `plugin:@next/next/recommended`. This should read out as strictly `next`, or as short as we can get it.
- Does not provide actionable warnings (missing link to resolve issue)
- Does not follow appropriate console output styling. We need to revisit how these are presented.

To re-land this, we need to ensure the following minimums are met:
- Very minor change in install size
- Fully experimental (i.e. flagged) with warnings
- Finalized package name and configuration shape, preferably so we can do ` { extends: 'next' } `.
2021-03-30 08:26:35 +00:00
Tim Neutkens
2ec2ea8786
Make eslint opt-in until it lands on stable (#23509) 2021-03-29 17:58:55 +02:00
Tim Neutkens
46fa9b6421
Temporarily remove the automatic opt-in for webpack5 (#23497) 2021-03-29 13:42:04 +02:00
Tim Neutkens
b34a0c98fa
Update err.sh links to use nextjs.org/docs/messages instead (#23353) 2021-03-29 10:25:00 +02:00
JJ Kasper
d130f63c41
Add handling fo beforeFiles, afterFiles, and fallback rewrites (#23407)
This adds support for returning an object from `rewrites` in `next.config.js` with `beforeFiles`, `afterFiles`, and `fallback` to allow specifying rewrites at different stages of routing. The existing support for returning an array for rewrites is still supported and behaves the same way. The documentation has been updated to include information on these new stages that can be rewritten and removes the outdated note of rewrites not being able to override pages. 



## Bug

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

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

## Documentation / Examples

- [ ] Make sure the linting passes
2021-03-26 15:19:48 +00:00
Shu Ding
98211405a6
Make sure the image optimization endpoint only response with images (#23366)
If the upstream MIME type isn't prefixed with `image/`, the endpoint should directly response with a 400 error.

## Bug

- [x] Fixes #23312
- [x] Integration tests added

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

## Documentation / Examples

- [ ] Make sure the linting passes
2021-03-24 17:59:00 +00:00
JJ Kasper
75c721c583
Add has route field (#22341)
This adds support for a `has` field to `rewrites`, `redirects`, and `headers` to allow matching against `header`, `cookie`, and `query` values. Documentation and additional tests for the feature is also added in this PR. 

Closes: https://github.com/vercel/next.js/issues/22345
2021-03-24 16:50:16 +00:00
Joe Haddad
437c35f121
feat: automatically enable webpack 5 (#22323)
Co-authored-by: Tim Neutkens <timneutkens@me.com>
Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
2021-03-24 14:10:10 +01:00
Houssein Djirdeh
e5ef60fecb
Add ESLint to Next.js (#22437)
For #22228

This PR:

- Adds ESLint to toolchain
  - Included by default for builds (`next build`)
  - Can be enabled for development (`next dev`)
  - Custom formatter built for output
- Adds appropriate tests
- Adds two documentation pages
2021-03-23 21:32:42 +00:00
Tim Neutkens
c219c1d9ce
Add polyfills for node_modules that are covered in webpack 4 to webpack 5 (#23316)
Brings back the remaining Node.js module polyfills to not break existing apps upgrading from webpack 4 to webpack 5.

Fixes #23169



## Bug

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

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

## Documentation / Examples

- [ ] Make sure the linting passes
2021-03-23 20:59:42 +00:00
Bruno Crosier
48dd9954d8
Add fallback for <Image /> component when JavaScript is disabled in browser (#19052)
The current `<Image />` component does not fallback gracefully when JavaScript is disabled in the client / browser.

You can test this with the [official Next/Image example](https://csb-4k0kr-p8ya8f304.vercel.app/), by disabling JavaScript in the browser's DevTools. Video demo: https://streamable.com/frkvw9

This PR aims to fix this behaviour by using `<noscript></noscript>` tags to conditionally display a standard `<img>` element using the `props` passed to `<Image />` when JavaScript is disabled.

For browser sessions where JavaScript is enabled, this will not cause an increase in network requests, so there should be no downside.

One area where this PR is a bit "hacky" is that it uses a negative `margin-top` to counteract `sizerStyle.paddingTop`. From what I can tell, `sizerStyle.paddingTop` is generated on the server side, where we can not know ahead of time whether JavaScript is enabled in the browser - hence why I've opted for this solution. 

Fixes #19223
Fixes #21214
2021-03-23 19:25:00 +00:00
Shu Ding
c8680a344f
Remove visibility: hidden from the image component (#23278)
This PR removes the `visibility` style property change from next/image. It was previously added in #18195 to fix a bug that when no `src` is set, and that bug is not valid anymore as all images will always have `src` (and a fallback too).

It also fixes the problem that screen readers ignore elements with `visibility: hidden`.

Fixes #23201.

## Bug

- [x] Related issues #23201
- [ ] Integration tests added

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

## Documentation / Examples

- [ ] Make sure the linting passes
2021-03-22 19:20:52 +00:00
Shu Ding
89ec21ed68
Fix wrong source path resolved from the stack frame to not expose internal code (#23203)
Currently Next.js exposes internal code in the error overlay if certain errors were created from the user code. Some examples were attached in #20776.

We can clearly see that the path is wrong (`../next-server`), it should be `./node_modules/next/dist/next-server`:

![CleanShot 2021-03-19 at 01 33 04](https://user-images.githubusercontent.com/3676859/111670728-1ae7e400-8853-11eb-9213-3b359798900e.png)

The root cause is the `__nextjs_original-stack-frame` middleware resolves the file path with the following code:

```js
path.resolve(
  rootDirectory,
  getSourcePath(sourcePosition.source)
)
```

where `rootDirectory` is the **app root**, but `sourcePosition.source` comes from the module path, which is relative to the path of the `next` binary, not the app root. 

That explains why we see `../next-server` from the error above, because it's relative to `./node_modules/next/bin/next`.

Because of that, the resolved result will never have `node_modules` in its path and it won't be filtered by the error overlay in the UI. Here's a screenshot of the frame object in the UI:

![CleanShot 2021-03-18 at 23 01 29@2x](https://user-images.githubusercontent.com/3676859/111670062-65b52c00-8852-11eb-9293-3a6e5b7c4b9b.png)

And the filter we use to determine if a frame is expanded or not only depends on `body.originalStackFrame`:

```js
expanded: !Boolean(
  body.originalStackFrame?.file?.includes('node_modules') ?? true
)
```

So this PR also adds `source.file` check to ensure they will be ignored (not necessary because we fixed the path resolving).

Fixes #20776.
2021-03-20 19:34:45 +00:00
Shu Ding
32c435d819
Experimental feature for allowing importing Typescript files outside of the root directory (#22867)
This PR attempts to provide an option to allow importing TS/TSX from outside of the current Next.js project root directory. Although this goes against the design decision that no source code should be imported from outside of root and [might bring tons of issues](https://github.com/vercel/next.js/issues/19928#issuecomment-741596557), it will still be helpful in some monorepo use cases.

This PR assumes that the external files are following the same language syntax rules and under the same tooling versions as the source code inside your project root. And it's also not allowed to enable the `baseUrl` feature in the external directory (as the project should only have 1 import base URL).

X-ref: #9474, #15569, #19928, #20374.
2021-03-19 16:43:46 +00:00
Sam Ko
e71014609e
Fix invalid console.error link (#23213) 2021-03-19 09:22:19 +01:00
JJ Kasper
b6bb110aca
Ensure process exits after build completes (#23207)
This ensures we exit the build process after the build completes even if timers/connections are left open since this can cause the process to hang indefinitely. This was the previous behavior although got changed un-intentionally in e27b7e996d

This updates our production test with an open timer to ensure it doesn't block the process from completing.
2021-03-19 08:06:28 +00:00
Tobias Koppers
e019ef6acc
update webpack, fix runtime location, fix undeclared variable, omit env vars from cache version (#23113)
* this will fix problems with serverless target which doesn't use a runtime chunk
* It also omit env vars from contributing to cache version as webpack will handle that now
* It moves the webpack-runtime chunk from ./chunks back to ./
2021-03-17 08:32:45 +00:00
Shu Ding
1bf4cf3e76
Upgrade jest-worker (#23077)
This PR upgrades `jest-worker` and `jest-cli` to the latest pre-release version, also removed `jest-circus` which is included in Jest by default. `jest-worker@next` includes a fix for memory leak that we need (https://github.com/facebook/jest/pull/11187). 

Fixes #22925. This will also improve the OOM issue for `next dev` #15855.
2021-03-16 21:08:35 +00:00
Shu Ding
85499b5375
Revert "Revert "[a11y] Route Announcements"" (#23086)
Reverts vercel/next.js#23082
2021-03-15 20:18:11 +00:00
Shu Ding
732c49cdc8
Revert "[a11y] Route Announcements" (#23082)
Reverts vercel/next.js#20428 temporarily to move this feature into the next canary release.
2021-03-15 19:09:24 +00:00