Commit graph

1948 commits

Author SHA1 Message Date
Tim Neutkens
628bb397b3
Fix bug with getServerSideProps when swcLoader is enabled (#29760)
Ported from #29185

These are all related to `swcLoader`:
- Fixes commonjs code being output as ESM
- Fixes bug with `getServerSideProps` not getting querystrings and added tests for it
- Disable SWC on Babel test suites
- Disable SWC on no-anon-default-export test suite
- Disable SWC on page-config test suite (pending porting of the Babel plugin)
- Ensure `sourcesContent` is part of the sourcemap



## 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
2021-10-09 14:39:53 +00:00
Tobias Koppers
3e22b22afc
Hmr DX improvements (#29753) 2021-10-09 11:51:37 +02:00
Gustavo Edinger
9b22406e36
fix: Prevent image redirection when trailingSlash is set (#29640)
* fix: Prevent image redirection when trailingSlash is set

* test: Trailing slash test for next/image

* lint-fix

Co-authored-by: Gustavo Edinger <gbe@nect.com>
Co-authored-by: JJ Kasper <jj@jjsweb.site>
Co-authored-by: Steven <steven@ceriously.com>
2021-10-07 11:10:26 -05:00
Tim Neutkens
351d225fc5
Remove isWebpack5 checks (#29677)
* Remove isWebpack5 checks

* Remove next-babel-loader (replaced by babel-turbo-loader), hotSelfAccept, and BuildStatsPlugin

* Remove cacache file

* Remove unused variable

* remove old test

* lint-fix

* update babel-loader tests

* lint-fix

* update compiled

Co-authored-by: jj@jjsweb.site <jj@jjsweb.site>
2021-10-06 18:46:46 -05:00
JJ Kasper
a20b0d59f5
Ensure conditional resolve alias does not affect server (#29673)
This ensures we don't add the no-op resolve alias when rewrites aren't used for the server resolving since it is still needed while tracing server files. 

## 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/pull/25538#issuecomment-936101951
2021-10-06 17:16:01 +00:00
Tim Neutkens
aa8a885599
Remove webpack 4 support (#29660)
Co-authored-by: jj@jjsweb.site <jj@jjsweb.site>
2021-10-06 17:40:01 +02:00
Steven
5e29723b05
Bump squoosh to the latest version (#29506)
Bump `squoosh` to the latest version, currently commit [cad09160](cad09160b6).

Ideally, we would use the version published to npm but it hasn't been published in [two months](https://www.npmjs.com/package/@squoosh/lib?activeTab=versions) and we have a patch (#23565) that isn't available upstream.

This also is a precursor to getting support for AVIF.

- Fixes #27092
- Fixes #26527 
- Reapplies the patch from #23565
2021-10-06 14:47:48 +00:00
Jonathan Wu
affbc15898
Fix conflicting paths grammar (#29658) 2021-10-05 22:22:46 -05:00
Keen Yee Liau
53628fba69
Create TelemetryPlugin for collecting feature usage metrics (#29145)
This commit creates a new Webpack `TelemetryPlugin` to gather information
about usage of certain features, for example `next/image` and `next/script`.
2021-10-05 14:31:48 -05:00
JJ Kasper
ebc1b0e559
Fix missing trace items and migrate required files test (#29649) 2021-10-05 13:52:19 -05:00
Tobias Koppers
15822516e7
fixes #29553 (#29611)
fixes #29553

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
2021-10-04 23:57:27 +00:00
JJ Kasper
458e34d680
Ensure all package.json files are traced correctly (#29539)
This fixes cases where not all `package.json`s were being added to the traces correctly while using webpack's resolving with the `outputFileTracing`. The specific case notice while testing has been added as an integration test to ensure it is working as expected.
2021-10-01 10:45:10 +00:00
Jackson Hardaker
ffd88aa739
Fix custom app file regex (#29525)
* Add lodash.escaperegexp

* Add compiled lodash.escaperegexp

* Refactor to escape special characters

* Test for build paths containing a special character

* Replace lodash.escaperegexp with previously compiled dep

* Revert yarn.lock change

* Remove backslash replace

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

* lint-fix

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2021-09-30 16:10:20 -05:00
JJ Kasper
38ac55dd20
Update output tracing resolving (#29473) 2021-09-29 12:38:21 -05:00
Tobias Koppers
f57b8d2a9e
fix test/integration/app-document-remove-hmr flake (#29486) 2021-09-29 12:28:45 +02:00
JJ Kasper
a71addf2e4
Ensure initial imports are included in traces correctly (#29437) 2021-09-28 12:04:16 -05:00
JJ Kasper
7bbaff74c4
Ensure blurDataURL is correct in dev with basePath (#29436)
Follow-up to https://github.com/vercel/next.js/pull/29307 this ensures the `blurDataURL` is correctly prefixed with the `basePath` in development since we use the `_next/image` endpoint to generate the placeholder in dev mode. 

## 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/29289#issuecomment-927758204
2021-09-27 21:13:23 +00:00
Steven
2271cd841d
Fix onLoadingComplete() callback when image src is Data URL (#29367)
Fixes #29363 

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
2021-09-26 15:03:07 +00:00
Jiachi Liu
741ef9032c
Experimental: hook version of reportWebVitals (#28769)
### Experimental

Introduce `next/vitals` and `useExperimentalWebVitalsReport` API which is not limited by `_app`.

`pages/index.js`
```jsx
import { useExperimentalWebVitalsReport } from 'next/vitals'

export default function Index() {
   useExperimentalWebVitalsReport((metric) => {
    // handle metric...
  })
  return 'sup'
}
```
2021-09-24 18:35:33 +00:00
JJ Kasper
5dbb8704cc
Ensure static image works correctly with basePath (#29307)
This ensures we prefix the `src` for static images with the `basePath` correctly, this also copies over the static image tests to the basePath image-component suite. 

## 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/29289
2021-09-23 23:26:51 +00:00
Casper
9343b67c11
feat: allow setting custom tsconfig file (#28104)
Ability to provide a custom tsconfig file. 

**Example Usage:**

```js
// next.config.js
module.exports = {
	typescript: {
		tsconfigPath: "myconfig.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.
- [x] Related issues linked using [`fixes #23972 (discussion)`](https://github.com/vercel/next.js/discussions/23972)
- [x] Integration tests added
- [x] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [x] Make sure the linting passes
2021-09-23 22:52:05 +00:00
JJ Kasper
faa39038ef
Update font-optimization test snapshot (#29305) 2021-09-22 15:51:50 -05:00
Steven
9c86953745
Rename experimental tracing to outputFileTracing (#29267)
Renaming this prop for clarity before we move this out of experimental
2021-09-21 22:18:12 +00:00
Tobias Koppers
4f212ee91d
the way towards webpack 5 typings (#29105)
Co-authored-by: sokra <sokra@users.noreply.github.com>
2021-09-21 19:17:16 +02:00
JJ Kasper
b4d8aa8c48
Fix default static /500 with i18n (#29250) 2021-09-21 16:23:23 +02:00
JJ Kasper
d5b1d595c5
Fix basePath: false not being honored for client-side redirect (#29235)
* Fix basePath: false not being honored for client-side redirect

* update test

* fix remove flakey exit
2021-09-21 09:23:13 -05:00
JJ Kasper
50c75282cd
Fix resolving href with query and matching as (#29246) 2021-09-21 16:21:27 +02:00
JJ Kasper
8e52126ea6
Migrate prerender tests to new set-up (#29245) 2021-09-21 16:21:05 +02:00
JJ Kasper
5b963422c0
Fix array query value has matching (#29216) 2021-09-19 20:32:30 -05:00
Flo
76dee14db4
Fix #11107 - don't prefetch preloaded modules (#22818)
This PR proposes a fix for https://github.com/vercel/next.js/issues/11107 (JS modules are loaded twice). A more detailed explanation of the investigation that led to this PR can be found in the issue's comments (https://github.com/vercel/next.js/issues/11107#issuecomment-791780168).

## Replicability

To identify that the issue replicates on any given project, you need to 
1. look at the network tab (first/clean load of site, so preferably ⌘+⇧+R on an incognito tab), 
2. sort by "name", and filter requests by `mime-type:application/javascript` (selecting "JS" in the devtools filters will actually show all "script" types, but ignore all "javascript" types)
3. look for pairs of identical calls with one originating from initial HTML (`preload` of priority "high" originating from "(index)" or "([page name])")  and another one from a script (`prefetch` of priority "lowest" originating from a .js file), where neither of the files is served from the cache.

Here's a screenshot of an example of what to look for:
<img width="601" alt="Screen Shot 2021-03-07 at 09 59 18" src="https://user-images.githubusercontent.com/1325721/110234627-cf1c6d00-7f2b-11eb-9cd7-749bf881ba56.png">


The issue was reproduced easily on the following projects:
- On [nextjs.org](https://nextjs.org/) where duplicates add up to ~70kB of transferred javascript out of 470kB (14.9%).
- On [vercel.com](https://vercel.com/) where duplicates add up to ~105kB of transferred javascript out of 557kB (18.8%).
- On [tiktok.com](https://tiktok.com/en) where duplicates add up to ~514kB of transferred javascript out of 1556kB (33%).
- In my own project using `"next": "^10.0.1"` (private repo) where duplicates add up to about 5% of total transferred javascript.
- In the issue's comments, a developer reported a replication using `"^10.0.7"` on a [public repo](https://github.com/SidOfc/sidneyliebrand.io).


## Some information about the fix

- Both `preload` and `prefetch` values for `<link rel="x">` behave similarly, with the difference being in network priority level (preload is high priority, prefetch is lowest priority).

- Next.js uses `<link rel="preload">` in its initial HTML but then *only* uses `<link rel="prefetch">` for the rest of the lifetime of the page. 

- However, when Next.js detects that a script should be requested in advance, it only checks for matching `<link rel="prefetch">` and not `<link rel="preload">` (which have higher priority and are present earlier in the DOM, thus have a greater likelihood of being already loaded). 

This PR aims to fix that oversight.

## Potential issues (none AFAIK)

As far as I can tell by looking through the codebase, **there is no downside** not to add a `prefetch` when a `preload` is already in the DOM. No other script looks for a `<link>` based on its `rel` attribute.
2021-09-19 17:51:04 +00:00
Andrew Hurle
88f27ef947
Fix bug where returning { notFound: true } from GSP broke next export (#24481)
* Fix bug where returning `{ notFound: true }` from GSP broke `next export`

We could just as easily omit the notFoundRoutes check, but I didn't want
to mask other potential bugs that would result in missing files

* update check

* move check

Co-authored-by: jj@jjsweb.site <jj@jjsweb.site>
2021-09-18 10:20:45 -05:00
Tobias Koppers
797dabe351
add support for new URL() (#28940)
Currently `new URL()` for server assets is completely broken because of the `publicPath` that is used for them too. `new URL()` for SSR is broken on windows as it's using absolute urls on the windows filesystem. And `new URL()` is using an incorrect filename

* Place all `asset`s correctly in `/_next/static/media` with `[name].[hash:8][ext]`
* Added a separate runtime chunk for api entries, without `publicPath`
* Introduce separate layer for api entries, which uses server-side URLs.
* Otherwise new URL() will return a faked relative URL, that is identical in SSR and CSR
* Disables react-refresh for api entries

Fixes #27413



## 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
- [ ] 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
2021-09-17 19:20:09 +00:00
Tobias Koppers
fa9ee197a4
suggest incremental typescript for typescript >= 4.4.2 (#29169)
This is now safe to enable since it no longer causes performance regressions
2021-09-17 15:42:27 +00:00
JJ Kasper
e313398468
Update trace ignores for next import (#29119) 2021-09-15 15:00:52 -05:00
Janicklas Ralph
73408211aa
Remove inert font tag in font optimization (#28869)
* Remove inert font tag in font optimization

* Fix lint

* Remove inert font tag during font optimization

* Fix lint

* Fix lint

* Fix lint

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2021-09-15 11:43:13 -05:00
JJ Kasper
49c99cc323
Fix host segment replacing for custom routes (#29090)
This fixes segments inside of the host of the destination failing to parse with url.parse due to the unexpected colon by escaping the colon for segments and then unescaping them after we have parsed the URL.

## Bug

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

x-ref: https://github.com/vercel/vercel/pull/6713
2021-09-14 20:13:46 +00:00
Kara
41484f62cc
Throw error if res is accessed after gSSP returns (#29010)
* Throw error if res is accessed after gSSP returns

Currently it's possible to access the `ServerResponse` through `context.res`
in `getServerSideProps()`. If one was to store that response and mutate
its headers or status code after gSSP returns (e.g. during rendering), it
would currently happen to work because of when headers are sent. However,
this is an anti-pattern that relies an implementation detail of the framework
and shouldn't be allowed. This will be particularly important once Next.js
starts to support basic streaming (two-part flush: routing then data) because
then the headers will be sent as soon as gSSP returns, which explicitly breaks
this pattern.

With this commit, the framework now throws an error in development mode if
the ServerResponse is accessed after gSSP returns.

* fixup! Throw error if res is accessed after gSSP returns
2021-09-13 17:10:46 -05:00
Konstantin Popov
16c3e6f613
Fix minor typo in index.test.js (#29065)
Fix minor typo:

suits -> suites
2021-09-13 14:56:56 -05:00
JJ Kasper
e49829bb8e
Fix webpack version and safari test and update compiled (#29059)
* Fix webpack version and safari test and update compiled

* Update compiled again
2021-09-13 10:56:07 -05:00
JJ Kasper
a92a5caec2
Update test set-up to leverage playwright when able to (#28634)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2021-09-13 14:36:25 +02:00
Gerald Monaco
1f99c3009f
Use Writable instead of Observable (#29007)
Use `Writable` instead of `Observable` and remove the `zen-observable` dependencies. I initially opted to use `Observable` for simplicity and fast iteration, but we should really just use `Writable` directly (or some other stream in the future).

React's streaming SSR has some [specific requirements](https://github.com/reactwg/react-18/discussions/66#discussioncomment-944266) on the stream API. Rather than trying to also squeeze a `Readable` in here, which might be more standard for node apps, I've just followed React's lead. By limiting ourselves to just `Writable`, it ought to be easier to adopt a different stream type in the future if desired.

The React `pipeToNodeWritable` API requires us to pass a stream immediately, but we don't actually have a `ServerResponse` to give it until `RenderResult.pipe(...)` is called later. For that reason, we pass React a `Writable` that we will simply forward to `res` later. This mechanism of deferring is `NodeWritablePiper`, which is just a function that can be called with `ServerResponse` (or another `Writable`, as we now do to render to string for static results) to have content written to it. `NodeWritablePiper` takes a `next` argument so that we can chain both synchronous and asynchronous pipers together.

Also does some clean up and adds another streaming test for backpressure.
2021-09-11 00:17:56 +00:00
Kara
c27e3a41dc
Update gSSP type to support props as a promise (#28999)
In a previous PR, `getServerSideProps` was altered to support returning
`props` as a promise. This change updates the TS types to permit promises
as well, so you can write type `GetServerSideProps<Props>` instead of
`GetServerSideProps<Promise<Props>>`. e.g.:

```typescript
type Props = {
  data: string
}

export const getServerSideProps: GetServerSideProps<Props> = async (
  context
) => {
  return {
    props: (async function () {
      return { data: 'some data' }
    })(),
  }
}
```

## Feature

- [x] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`
2021-09-10 19:36:40 +00:00
JJ Kasper
a00de0c2f0
Ensure cache-control is correct for notFound: true with revalidate (#28973)
This ensures we have the correct `cache-control` header when `revalidate` is used with `notFound: true` on `getStaticProps` or `getServerSideProps` pages. 

## Bug

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

Fixes: https://app.clubhouse.io/vercel/story/23445
2021-09-10 08:15:13 +00:00
JJ Kasper
6674e977b7
Fix create-next-app tests from example change (#28972) 2021-09-09 15:21:56 -05:00
JJ Kasper
f4c6cd68d8
Fix ensurePage race condition (#28939)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2021-09-09 10:14:30 +02:00
JJ Kasper
b71df190e5
Ensure timed out prefetches are cleaned up correctly (#28899)
This applies the fix from the awesome investigation done in https://github.com/vercel/next.js/issues/28797 by @jayphelps and adds a test to ensure this is working as expected. It seems that the `route-loader` has a race condition while prefetching and if a script is executed before we have created a current "future" entry to resolve the entry stays in a pending state causing routes to hang so this handles the condition by ensuring pending/errored entries do not stay around. 

## 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/28797
Fixes: https://github.com/vercel/next.js/issues/27783
2021-09-08 06:37:04 +00:00
Gerald Monaco
620ca1b06b
Update concurrent tests and enable experimental streaming (#28892)
Updates the React 18 concurrent tests to support streaming, by using webdriver (instead of cheerio) to support dynamic updates, and being more explicit about SSR vs. hydrated content.

Also enables streaming support by setting `supportsDynamicHTML: true` in `pipe(...)` for non-bot user agents.
2021-09-07 22:34:21 +00:00
Perry Olsson
3b55a37c81
Webpack rule to block importing images into _document (#28475) 2021-09-06 13:41:18 +02:00
Houssein Djirdeh
4141aaefa5
[ESLint] Support single-file linting in next lint (necessary for lint-staged) (#28042)
Co-authored-by: Tim Neutkens <timneutkens@me.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2021-09-06 13:05:40 +02:00
Pablo Espinosa
a8088bfd67
feat: Adding generic typing for previewData (#28668)
on GetServerSidePropsContext and GetStaticPropsContext

As discussed on #21574 having a generic type will give it more flexibility and remove linting errors.

## 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 #21574 
- [ ] 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`
2021-09-03 21:27:17 +00:00
JJ Kasper
14a999ed73
Ensure build trace handles mixed modules (#28770) 2021-09-03 11:30:00 -05:00
Jiachi Liu
7f09df3483
Fix typings of dynamic suspense (#28740)
x-ref: https://github.com/vercel/next.js/pull/27611#issuecomment-911743160
2021-09-02 16:14:48 +00:00
Anderson Leite
e00b946785
router-is-ready test. Clean up unused vars. (#28723)
Variable `isDev` is not used in both tests.
The tests run dev/prod modes based on the different test scenarios.

## Bug

- [x] Integration tests clean up

## Documentation / Examples

- [x] Make sure the linting passes
2021-09-02 15:16:53 +00:00
Tim Neutkens
9a56fdba82
Use consistent postcss version for all transforms (#28529)
Co-authored-by: JJ Kasper <jj@jjsweb.site>
2021-09-02 08:45:35 +02:00
Jiachi Liu
ed9b8863b4
fix: should allow nullable param for res.end (#28694)
## Bug
Fixes #28693

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
2021-09-01 17:01:00 +00:00
JJ Kasper
9a6542ba68
Ensure build trace is correct with extra entries (#28667)
* Ensure build trace is correct with extra entries

* lint-fix

* fix check on windows
2021-09-01 10:56:04 -05:00
Eungyeol
c1dbc12609
Do not have the required package error fix (#28662)
The following error occurred 
when I created a project with the typecript template of createp-next-app 
and did the 'next build'.

```shell
It looks like you're trying to use TypeScript but do not have the required package(s) installed.

Please install @types/node by running:

        yarn add --dev @types/node

If you are not trying to use TypeScript, please remove the tsconfig.json file from your package root (and any TypeScript files in your pages directory).
```

This issue was resolved by adding @types/node.
So I added @types/node to the devDependencies of the create-next-app typecript template.
2021-09-01 02:01:55 +00:00
Tobias Koppers
f6d8a112df
fix esm externals edge case with "module" condition (#28612)
prefer commonjs externals even if "module" condition is used in package.json



## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
2021-08-31 08:32:33 +00:00
JJ Kasper
ff9dcc6a47
Ensure custom app regex is correct for Windows (#28631)
* Ensure custom app regex is correct for Windows

* lint-fix

* update test for ie

* update test

* lint-fix
2021-08-30 20:09:48 -05:00
Kara
9be387c7f4
getServerSideProps should support props value as Promise (#28607)
Previous to this change, getServerSideProps could only return plain objects
for props, e.g.:

```javascript
export async function getServerSideProps() {
  return {
    props: {
      text: 'some value',
    }
  }
}
```

With this commit, the props object can also be a Promise, e.g.

```javascript
export async function getServerSideProps() {
  return {
    props: (async function () {
      return {
        text: 'promise value',
      }
    })(),
  }
}
```

For now, the framework simply waits for the results of the props Promise to resolve,
but this small change sets the groundwork for later allowing props to be streamed (cc @devknoll).

## Feature

- [x] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. -- *This is part of @devknoll's ongoing work to support streaming.*
- [ ] 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. *not sure if this applies here*
- [ ] Errors have helpful link attached, see `contributing.md`
2021-08-30 19:52:15 +00:00
Steven
7afc97c574
Add CSP to Image Optimization API (#28620)
Add CSP header to Image Optimization API
2021-08-30 16:51:47 +00:00
Anderson Leite
8711c5ca53
Tests: Remove unnecessary await (#28594)
'await' has no effect on the type of this expression.ts(80007)

## Bug

- [X] Integration tests clean up

## Documentation / Examples

- [x] Make sure the linting passes
2021-08-29 06:50:00 +00:00
JJ Kasper
f1dbc9260d
Ensure dev server side errors are correct (#28520) 2021-08-27 14:29:30 +02:00
Gerald Monaco
2cc2cb4f77
Support for functional Document components (#28515) 2021-08-26 10:05:01 -05:00
Steven
d8093ec4b4
Update warning when parent styles break next/image (#28517)
- Follow up to #28221 
- Fixes #27644
2021-08-26 00:09:04 +00:00
Hunter Tunnicliff
877f982924
Use recommended pattern in testing example (#28404)
* Use recommended pattern in testing example

Since the official linter for testing library, `eslint-plugin-testing-library` recommends using `screen` to write queries, this MR updates the testing library example to follow the pattern recommended by the linter.

> DOM Testing Library (and other Testing Library frameworks built on top of it) exports a screen object which has every query (and a debug method). This works better with autocomplete and makes each test a little simpler to write and maintain.

> This rule aims to force writing tests using built-in queries directly from screen object rather than destructuring them from render result. Given the screen component does not expose utility methods such as rerender() or the container property, it is correct to use the render returned value in those scenarios.

See the `prefer-screen-queries` rules docs for more info: https://github.com/testing-library/eslint-plugin-testing-library/blob/main/docs/rules/prefer-screen-queries.md

* Update devDependencies

* Install and configure test linting

* Use recommended pattern in test

* Update test names for consistency

* Update docs

* Set jest environment in each file

* Use root true in `with-jest` eslint config

* Ensure nested .eslintrcs are not loaded for repo lint

Co-authored-by: jj@jjsweb.site <jj@jjsweb.site>
2021-08-25 12:33:57 -05:00
JJ Kasper
ead10f1f81
Fix handling for 204 status code with a body (#28479)
This ensures we handle 204 and 304 status codes correctly in API routes.  

## 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/28464
2021-08-25 15:52:43 +00:00
JJ Kasper
706547e0c3
Ensure error is shown correctly for empty headers field (#28430)
* Ensure error is shown correctly for empty headers field

* Apply suggestions from code review

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

Co-authored-by: Steven <steven@ceriously.com>
2021-08-24 19:26:33 -05:00
Anderson Leite
4d5eaf0efb
Tests: Adds test to data-nimg data attribute based on layout prop. (#28444)
Adds tests to the Image component to verify that the correct data is being exposed.
Based on #27899 and #28312

## 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
2021-08-24 20:36:49 +00:00
Janicklas Ralph
fd1c56e66a
next/script fix duplicate scripts (#28428)
* Fix #27747

* Fix lint error

* Add data attribute to script component

* Fix #28036

* Fix tests

* Fix tests

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2021-08-24 11:07:38 -05:00
JJ Kasper
005b13f1ac
Move unit tests to one folder and migrate them to TypeScript (#28427)
* Move unit tests to one folder

* Migrate unit tests to TypeScript

* add test types to lint

* Ensure ts(x) tests are run with util

* Add tsx extension to jest config

* bump
2021-08-24 07:52:45 -05:00
JJ Kasper
ece79a4e00
Update test config to leverage swc (#28400)
This updates our `jest` configuration to no longer use `babel-jest` and instead uses `@swc/jest` which is much faster. This also updates to the latest version of `jest`, fixes our `tsconfig.json` used for tests (previously types in `node_modules` weren't resolved correctly), and ensures `next/dist` isn't un-necessarily transpiled in `jest`. 

Timings for `yarn testheadless test/unit/` on CI
- before: 3m 30s - 4m ([example run](https://github.com/vercel/next.js/runs/3394701995))
- after: under 1m ([example run](https://github.com/vercel/next.js/pull/28400/checks?check_run_id=3395161621))

Timings for `yarn testheadless test/unit/` locally on m1 mac 
- before: 90.16 seconds
- after: 29.92 seconds
2021-08-23 18:36:56 +00:00
Houssein Djirdeh
80921b6a54
enables eslint caching by default (#28349)
Co-authored-by: JJ Kasper <jj@jjsweb.site>
2021-08-23 12:56:21 -05:00
Janicklas Ralph
26255a685d
Add data attribute to script component (#28310)
Add data attribute `data-nscript` to the script component
2021-08-20 20:48:48 +00:00
hiro
a9c1bd797d
Fixed typos that existed on some files (#28314)
* fix: naviagtion -> navigation

* fix: compatability -> compatibility
2021-08-19 21:54:13 -05:00
stefanprobst
da4203d032
Add eslint rule for id attribute on inline next/script (#27853)
This adds a new ESLint rule to `eslint-plugin-next` to check that `next/script` components with inline content have the required `id` attribute.

Also adjusted the code example for inline scripts in the `next/script` docs, which were actually missing an `id` attribute.
And also updated the `next/scripts` integration test to also have the required `id` attribute.

Unsure about the required heading levels in the errors .md document (other examples have h1 and h4??)

## 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
- [x] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [x] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes
2021-08-19 20:08:04 +00:00
JJ Kasper
9b09b92a14
Ensure adding _app/_document HMRs correctly (#28279)
This is a follow-up to https://github.com/vercel/next.js/pull/28227 to ensure `_app` and `_document` HMR correctly when you start the dev server and then add `_app` and `_document`. 

## Bug

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

x-ref: https://github.com/vercel/next.js/issues/27888
2021-08-19 08:12:12 +00:00
Steven
53f0973aba
Fix next/image blur placeholder when JS is disabled (#28269)
This PR does a few things:

- Moves `<noscript>` usage below the blur image since so that the `<noscript>` image renders on top of the blur image
- Remove the `isVisible` check for `<noscript>` since we can't rely on client-side JS
- Add `loading=lazy` to the `<noscript>` image to take advantage of native lazy loading (can't rely on JS lazy loading)

Fixes #28251
2021-08-19 04:26:07 +00:00
JJ Kasper
15e8019263
Update generating next-server dependencies (#28223)
* Update generating next-server dependencies

* Update tests

* ensure stale cache is not used
2021-08-18 10:41:40 -05:00
JJ Kasper
17d7e59339
Fix HMR when custom _app or _document is removed (#28227)
This adds the fallback webpack alias handling to handle a custom `_app` or `_document` being removed in development gracefully. 
 
## 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/27888
2021-08-18 11:01:02 +00:00
Steven
ce187563ef
Add warning when parent styles break next/image (#28221)
Fixes #27644
2021-08-18 02:05:10 +00:00
Jiachi Liu
7ea7c23866
Document usage of suspense option of next/dynamic (#28210)
## Documentation / Examples

- [x] Make sure the linting passes
- [x] Errors have helpful link attached, see `contributing.md` (for #28165, #27611)
- [x] Update test case
2021-08-18 01:21:22 +00:00
Chris Lloyd
52c2f8b4dd
Avoid fs write next-env.d.ts on read-only filesystems (#28206)
Next.js currently writes the TS type declarations on startup, regardless of the existing content of the file. This is good for ensuring the file content stays consistent. However, if the file content is already correct, this will perform an unnessecary write.

When running Next in read-only filesystems (such as the Bazel sandbox) this can cause the build to fail even if the content of the type declaration file is already correct.

This fixes this by only writing the contents of the file if the current contents don't match.

## Test Plan

Added an integration test for the general behavior of writing `next-env.d.ts`.
2021-08-18 00:41:51 +00:00
dave
1b2e0799c3
fix development mode bug with pages with "+" and other special characters (#28122)
* add encodeURIComponent so certain characters don't bug out (fixes #22099)

* add integration test for pr #28122
2021-08-17 12:13:33 -05:00
JJ Kasper
5544adc481
Update to latest babel versions (#28174) 2021-08-17 09:18:08 +02:00
JJ Kasper
24b09ad4f8
Add entrypoint tracing (#25538)
This adds tracing entrypoints directly after they have have been transpiled to allow us to trace before the webpack runtime has been added to the modules. This should allow for more accurate tracing of entrypoints and allow the trace step to be cached. 

## Bug

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


x-ref: https://github.com/vercel/next.js/issues/24700
x-ref: https://github.com/vercel/next.js/issues/26200
x-ref: https://github.com/vercel/next.js/issues/23894
x-ref: https://github.com/vercel/next.js/issues/25431
2021-08-16 19:29:11 +00:00
Jiachi Liu
531342691d
Enable pure client suspense in blocking rendering (#28165)
Do not fallback to loadable component when `reactRoot` is enabled but without `concurrentFeatures`. Thus we can enable pure client suspense:

`fallback` is always rendered on server side, but client side can work with fully functional suspense.

Closes #28117
2021-08-16 15:06:39 +00:00
Brian Muenzenmeyer
49c3e0a201
fix(tests): fixes typo in basic integration test (#28158)
## 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

- [x] Make sure the linting passes


While reading the code I noticed this typo.
2021-08-16 14:35:18 +00:00
JJ Kasper
039735350c
Add proper error when failing to load next.config.js (#28099)
This adds a proper error when we fail to load a user's `next.config.js` as the default node error can be confusing on its own and makes it seem like something failed internally in Next.js. We can expand on the included error doc added and potentially also add better syntax errors by parsing with acorn when we fail to load this file in the future. 

<details>

<summary>screenshot</summary>

<img width="962" alt="Screen Shot 2021-08-13 at 21 46 09" src="https://user-images.githubusercontent.com/22380829/129432211-6d858062-eea0-4bb9-8725-5bde98bdc47b.png">

</details>
2021-08-14 13:52:18 +00:00
JJ Kasper
169785253e
Fix revalidate for initial notFound: true paths (#28097)
This fixes revalidation not occurring correctly when `notFound: true` is returned during build, additional tests have been added to ensure this is working correctly for dynamic and non-dynamic pages returning `notFound: true` during build and then revalidating afterwards.  

## 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/21453
2021-08-14 13:11:40 +00:00
Gerald Monaco
500b3f6e15
Remove duplicate doctypes (#28089)
* Remove duplicate doctypes

* Fix lint

* Add test for DOCTYPE

* Fix lint
2021-08-13 19:12:02 -05:00
stefanprobst
daadfd347f
Handle blob urls in image component (#27975)
This PR resurrects #23622 which has not been updated in a while. Makes the `Image` component handle `blob:` object urls.

closes #23622
fixes #19291

credits: @sdn90 

## 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
2021-08-13 22:03:20 +00:00
Jiachi Liu
d14da39fd6
Support suspense in next dynamic (#27611)
### Changes
#### Feature
* Adopt `React.lazy` into `next/dynamic`, enable it when `options.suspense` is `true`
* Support `next/dynamic` with `suspense=true` in SSR and SSG

#### Tests

| Scenario | Case | Behavior |
|:----:|:----:|:----:|
| basics | react 17 or 18 by default | dev/build error or pass |
| blocking rendering | `reactRoot: true` + `concurrentFeatures: false` | dev/build pass |
| concurrent rendering | `reactRoot: true` + `concurrentFeatures: true` | dev/build pass | 


## Feature

- [x] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`
2021-08-13 21:08:45 +00:00
Anderson Leite
f95e5fdfb6
Refactor development-logs removing duplicated code. (#28049)
Hi, this is small refactor for the development-logs.js test.
The same code to verify the browser logs is written 3 times.
Actually, the only difference is the path and then the expect result to confirm whether the logs are showing or not.
Moved the triplicated code to a `getLogs$(path)` and matched the expect results.
2021-08-13 12:43:07 +00:00
Steven
b11bd49239
Fix image optimization encoding url (#28045)
- Fixes #27973 
- Reverts #27671 


The problem with PR #27671 is that it was encoding too often when it really only needed to solve the bug for `next build && next start` since `next dev` was already working.

This PR uses the alternative solution mentioned here https://github.com/vercel/next.js/issues/27210#issuecomment-890305204
2021-08-13 00:31:51 +00:00
Tobias Koppers
8bbb1cd353
use a shared worker pool for collecting page data and static page generation (#27924)
this avoid loading all code twice and hopefully improving performance
2021-08-12 19:54:49 +00:00
Anderson Leite
27ccd3cb38
Tests: Execute development-logs tests. (#27996)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2021-08-12 14:35:54 +02:00
Tim Neutkens
ebb6a30370 Revert "Add warning during next build when sharp is missing (#27933)"
This reverts commit 51a2a028dd.
2021-08-11 17:47:16 +02:00
Steven
51a2a028dd
Add warning during next build when sharp is missing (#27933)
Follow up to #27346 

![image](https://user-images.githubusercontent.com/229881/128935917-ca6da384-91f4-43d3-8059-4e06220fbc19.png)
2021-08-11 04:03:57 +00:00
C. Lewis
3c837ed175
test(next): add tests for Node-like hashbang support (#27906)
* update to webpack 5.50.0

* feat: use shebang loader shim for now

* chore: snapshot formatting change

* chore: remove unneeded SSR test

* chore: test all file extensions

* chore: remove shebang loader from Webpack config

* chore: revert unnecessary changes

* Update test/integration/hashbang/test/index.test.js

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

* chore: revert changes to yarn.lock

Co-authored-by: Tobias Koppers <tobias.koppers@googlemail.com>
Co-authored-by: Steven <steven@ceriously.com>
2021-08-10 21:41:02 -04:00
Janicklas Ralph
43393d53be
Fix next/script unhandled promise rejection (#27903)
## Bug

- [x] fixes #27747
- [x] Integration tests added
2021-08-10 17:41:26 +00:00
JJ Kasper
fa01a1593e
Update client error to show link in console (#27789)
* Update client error to show link in console

* Apply suggestions from code review
2021-08-05 10:38:06 -05:00
Houssein Djirdeh
7a1c9eb17e
[ESLint] Introduce a new setup process when next lint is run for the first time (#26584)
This PR introduces an improved developer experience when `next lint` is run for the first time.

### Current behavior

`eslint-config-next` is a required package that must be installed before proceeding with `next lint` or `next build`:

![image](https://user-images.githubusercontent.com/12476932/123468791-43088100-d5c0-11eb-9ad0-5beb80b6c968.png)

Although this has helped many developers start using the new ESLint config, this has also resulted in a few issues:

- Users are required to install the full config (`eslint-config-next`) even if they do not use it or use the Next.js plugin directly (`eslint-plugin-next`).
  - #26348

- There's some confusion  on why `eslint-config-next` needs to be installed or how it should be used instead of `eslint-plugin-next`.
  - #26574
  - #26475
  - #26438

### New behavior

Instead of enforcing `eslint-config-next` as a required package, this PR prompts the user by asking what config they would like to start. This happens when `next lint` is run for the first time **and** if no ESLint configuration is detected in the application.

<img src="https://user-images.githubusercontent.com/12476932/124331177-e1668a80-db5c-11eb-8915-38d3dc20f5d4.gif" width="800" />

- The CLI will take care of installing `eslint` or `eslint-config-next` if either is not already installed
- Users now have the option to choose between a strict configuration (`next/core-web-vitals`) or just the base configuration (`next`)
- For users that decide to create their own ESLint configuration, or already have an existing one, **installing `eslint-config-next` will not be a requirement for `next lint` or `next build` to run**. A warning message will just show if the Next.js ESLint plugin is not detected in an ESLint config. 

  <img width="682" alt="Screen Shot 2021-06-25 at 3 02 12 PM" src="https://user-images.githubusercontent.com/12476932/123473329-6cc4a680-d5c6-11eb-9a57-d5c0b89a2732.png">

---

In addition, this PR also:

- Fixes #26348
- Updates documentation to make it more clear what approach to take for new and existing ESLint configurations
2021-08-04 21:53:15 +00:00
JJ Kasper
bce06f500d
Update has query encoding when used in path (#27762)
This is a follow-up to https://github.com/vercel/next.js/pull/26963 which after discussion changes to interpolate the decoded variant of the value into the path. 

x-ref: https://github.com/vercel/next.js/issues/24775

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
2021-08-04 20:31:12 +00:00
JJ Kasper
4ab41efdbf
Add handling for repeated slashes (#27738)
This adds handling for repeated forward/back slashes in Next.js, when these slashes are detected in a request to Next.js we will automatically remove the additional slashes redirecting with a 308 status code which prevents duplicate content when being crawled by search engines. 

Fixes: https://github.com/vercel/next.js/issues/13011
Fixes: https://github.com/vercel/next.js/issues/23772
Closes: https://github.com/vercel/next.js/pull/15171
Closes: https://github.com/vercel/next.js/pull/25745
2021-08-03 15:06:26 +00:00
stefanprobst
5ded742395
move next/script to pages/_app in script loader integration tests (#27626) 2021-08-03 14:01:03 +02:00
Steven
46e7658f7e
Add next.config.js option to override default keepAlive (#27709)
Follow up to #27376 so users can disable keep-alive.

See comment https://github.com/vercel/next.js/pull/27376#issuecomment-885415623
2021-08-03 00:38:42 +00:00
Steven
b05cdb1f64
Add naturalWidth/naturalHeight to onLoadingComplete() callback (#27695)
Resolves #27213
2021-08-02 23:14:38 +00:00
JJ Kasper
b3c959b2c2
Enforce source/destination limit for custom routes (#27703)
This ensures we enforce a limit for `source`/`destination` values on rewrites, redirects, and headers since these being too long can affect routing performance. 

Closes: https://github.com/vercel/next.js/issues/27696
2021-08-02 22:34:44 +00:00
stefanprobst
63aeddbbe0
URI-encode url parameter in image optimizer (#27671)
fixes #27210
maybe related: #19668

currently, the image optimizer returns 400 when an image url contains non-ascii characters. this pr uri-encodes the `url` query parameter to fix it. also see https://github.com/vercel/next.js/issues/27210#issuecomment-890305204

## 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
2021-08-02 17:03:45 +00:00
Jiachi Liu
a6e478f9ed
Use require alias to resolve react 18 for testing (#27601)
For test only, previously the react-dom is still been resolved as react 17

## 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
2021-07-29 20:06:13 +00:00
stefanprobst
0833f83c86
Fix eslint config next/core-web-vitals (#27567)
fixes what i messed up in #27363. cf. https://github.com/vercel/next.js/pull/27363#issuecomment-888495697

also added an integration test for extending from `next/core-web-vitals` eslint config

## 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
2021-07-28 19:07:54 +00:00
Tim Neutkens
c7e2a1df6a
Use SWC for Next.js core client files (#27196)
Replaces Babel with SWC for Next.js core client-side files.

## 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
2021-07-28 15:10:51 +00:00
Paweł Tymczuk
36b81f989c
Fix: Added the content-disposition header (#27521)
In this PR I've added the `Content-Disposition` header to the response of the image `/_next/image` route. That header is used by the browser when showing the dialog for the `Save image as...` action. 

There are some differences between the browsers, ex:
When requesting the image `test.jpg`,  the response header `Content-Type: image/webp` - in FF the filename from the `Save image as...` dialog would be `test.webp` but in Chrome `test.jpg` even if the `Content-Disposition: inline; filename="test.webp"` is present in the headers.  The same about png images, the rest types are fine.  It looks like FF is checking the `Content-Type` for the extension but the Chrome does not and is doing another type of check.

Fixes #26737

## Bug

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

## Documentation / Examples

- [x] Make sure the linting passes
2021-07-27 23:22:48 +00:00
Sojin Park
23ac4351f4
fix: Make router ready in case of custom _app getInitialProps (#27473)
From https://github.com/vercel/next.js/pull/20628,  when the page is rendered server-side, `Router`'s `isReady` field needs to be initially set to `true`. However, when `_app` has custom `getInitialProps`, it seems that it is not the case, even though the page is rendered on the server. 

This leads to a bug that `Router.isReady` is never set to `true`.

This pull request fixes the problem by fixing the initial calculation logic of `isReady` of `Router`.

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

- [x] Make sure the linting passes
2021-07-26 20:25:55 +00:00
brijendravarma
74b159c850
Updated the Error message describing the alternative and added styles… (#14652)
The error message indicates better alternatives and added styles.css sample snippet for good visibility.

![Global_error_msg](https://user-images.githubusercontent.com/38159218/85950309-ac3bc100-b979-11ea-9a8d-4a356cb8007c.JPG)
![CSS-Global](https://user-images.githubusercontent.com/38159218/85950319-b2ca3880-b979-11ea-829a-24335fcfc93d.JPG)
2021-07-25 04:53:33 +00:00
Michał Bundyra
7fe8a001e2
ESLint: custom directories from next.config.js (#26401)
Attempt to fix #26393

~~Sorry, I wasn't able to run tests on local, but I hope at least test should be valid.~~
Edit: Tests are working correctly on my local :) 

fixes #26393



## Bug

- [x] Related issues linked using `fixes #26393`
- [x] Integration tests added
2021-07-25 04:11:29 +00:00
Houssein Djirdeh
078cfb59f9
[ESLint] Adds --format flag to next lint (#27052)
Adds `--format` support to `next lint` to allow defining of additional formatters. Fixes #26387.
2021-07-24 01:35:56 +00:00
Steven
9065cdf836
Add warning when next/image component has style prop (#27441)
We've never supported the `style` prop as seen in the docs https://nextjs.org/docs/api-reference/next/image#other-props

TS users already get a build error but JS users were left in the dark.

This PR adds a warning so its clear during `next dev`.
2021-07-23 22:53:27 +00:00
JJ Kasper
c54f168d9a
Add config check for invalid duplicate locale domains (#27451) 2021-07-23 17:16:14 -05:00
stefanprobst
daf54bb2b0
[eslint] move core-web-vitals config to eslint-plugin-next (#27363)
this pr moves the "core-web-vitals" config from `eslint-config-next` to `eslint-plugin-next`.

Fixes: #27292

## 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.
- [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 / Examples

- [ ] Make sure the linting passes
2021-07-23 17:58:53 +00:00
Yubin
4e74db2d55
Add lazyBoundary prop to Image component (#27258)
This PR adds `lazyBoundary` prop on Image Component.
This feature is to load the images earlier.
I'm not good at English. So, I couldn't explain enough in the documentation what `lazyBoundary` is.

Feature request: https://github.com/vercel/next.js/discussions/24552

## Feature

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

## Documentation / Examples

- [x] Make sure the linting passes
2021-07-23 14:44:38 +00:00
Alex Castle
1b733423d6
Use Sharp if available for Image Optimization (#27346)
* Use sharp for image transformations when available

* Refactor resizeImage and add sharp warning

* only show sharp warning once per instance

* Modify sharp error message

* Add documentation for optional sharp dependency

* Update docs/basic-features/image-optimization.md

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

* Import types for sharp

* Update lockfile

* Add testing against sharp

* use fs-extra for node 12

* Rename test sharp path variable

* Apply suggestions from code review

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

* update squoosh specific test

* Apply suggestions from code review

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

* update tests

* Apply suggestions from code review

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

Co-authored-by: Steven <steven@ceriously.com>
Co-authored-by: JJ Kasper <jj@jjsweb.site>
2021-07-22 18:11:17 -05:00
JJ Kasper
888c7002d6
Fix external redirect with i18n domains (#27415)
This corrects a case when redirecting with i18n locale domains configured the locale domain would be prefixed on external redirects un-necessarily. 

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

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [x] Errors have helpful link attached, see `contributing.md`
2021-07-22 18:32:12 +00:00
Steven
79ed8e13b0
Add keepAlive to node-fetch polyfill (#27376)
Fixes #27109 

This PR adds a default `agent` as described in the [`node-fetch` docs](https://github.com/node-fetch/node-fetch#custom-agent).

We should see about 2x perf according to some [benchmarks](https://github.com/Ethan-Arrowood/undici-fetch/blob/main/benchmarks.md#fetch).
2021-07-22 14:34:33 +00:00
Jamie
7c408e7a0f
Fix ISR page re-rendering after revalidate expiry (Fork of #24807) (#27335)
Fixes: #24806 
Fixes: #26689
Fixes: #27325
Closes: #24807

@tommarshall has done us a huge favor with his PR https://github.com/vercel/next.js/pull/24807 which outlines exactly the issue and a pragmatic solution.

I'm not trying to "steal their work", however, the PR seems to have been stuck for some months. I think there's huge value in this for myself and others as essentially **ISR is broken** for people running Next.js at scale 😱 

This PR has cherry-picked @tommarshall's fine fix and added some integrations tests around page revalidation and the edge case when the cache size is exhausted.

✏️ Edits are enabled, so feel free great Vercel staff and other maintainers to improve my bad tests or surrounding code 🙇 

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
2021-07-20 17:01:42 +00:00
Steven
5cd37d9b32
Fix placeholder=blur inside <noscript> (#27311)
We shouldn't be setting `placeholder=blur` styles when JS is disabled because we'll have no way to know when the image is loaded and it will be stuck in blur permanently as mentioned in [this comment](https://github.com/vercel/next.js/pull/19052#issuecomment-882886068).

This PR avoids blur styles on the `<noscript>` version of the image.
2021-07-20 01:23:16 +00:00
Steven
b123942694
Fix minimumCacheTTL so it doesn't affect browser caching (#27307)
In a previous PR (#27200), we added `minimumCacheTTL` to configure the time-to-live for the cached image. However, this was setting the `max-age` header.

This PR ensures that `minimumCacheTTL` doesn't affect browser caching, only the upstream header can affect browser caching.

This is a bit safer in case the developer accidentally caches something that shouldn't be and the cache needs to be invalidated. Simply delete the `.next/cache/images` directory.

- Related to #19914
- Related to #22319
2021-07-19 22:38:03 +00:00
Janicklas Ralph
dda23f5d9b
Fix inline scripts being duplicated when used with next/script component (#27218)
Fixes inline scripts being duplicated when used with `next/script` component

## Bug

- [x] fixes #26860 
- [x] Integration tests added


## Documentation / Examples
 Updated docs to indicate that `id` is needed for inline scripts
2021-07-16 18:58:34 +00:00
Houssein Djirdeh
6645248d41
[ESLint] Remove error when file patterns are unmatched + ESLint setup changes (#27119)
Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
2021-07-16 20:19:08 +02:00
Thomas Marshall
ccb62f8636
Add x-forward headers to external rewrites (#17557)
* Add x-forward headers to external rewrites

This commit configures the proxy used for external rewrites to include
x-forward headers [1]. This is particularly useful for incremental
adoption, where some routes will be handled by Next.js and others by a
different website. For example, a Rails app will use the
X-Forwarded-Host header to determine which host to use for URL
generation and redirects [2].

[1]: 91fee3e943/lib/http-proxy.js (L31)
[2]: 41139f6ba2/actionpack/lib/action_dispatch/http/url.rb (L221-L227)

* Handle image-optimizer case

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2021-07-16 10:11:12 -05:00
Tobias Koppers
f9795fdd26
improve static generation UX (#27171)
#### improve export spinner

update at least once a minute in non-tty
update progress regularly when using the spinner
decrease frequency of the spinner (windows console output is expensive)

#### restart static page generation and collecting page data worker pools when hanging

when for 1 minute no activity happens on the worker pool, restart it
log a warning for hanging jobs

#### add page generation duration to summary tree

![image](https://user-images.githubusercontent.com/1365881/125750454-8845f1b1-faf0-4598-b7a4-ea796b884691.png)

for `[+n more pages]` is will show `(avg 321 ms)` when the average is over the threshold.
It will allocate 8 lines for preview pages (instead of 4) when they contain slow pages

## Feature

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

## Documentation / Examples

- [ ] Make sure the linting passes
2021-07-16 09:21:44 +00:00
Janicklas Ralph
3b388c346c
Fix Script beforeInteractive on navigation (#26995)
## Bug

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


## Documentation / Examples

- [x] Make sure the linting passes
2021-07-15 22:51:01 +00:00
Steven
8151a7e0dc
Add minimumCacheTTL config for Image Optimization (#27200)
- Closes #23328  
- Related to #19914 
- Related to #22319 


## Feature

- [x] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [x] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [x] Errors have helpful link attached, see `contributing.md`
2021-07-15 19:55:12 +00:00
Jiachi Liu
71665b2437
Fix gsp generation with file extension (#27144)
Fixes #11831 
Fixes #12212

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
2021-07-15 18:50:17 +00:00
Steven
437ad9ff6a
Fix css minify incorrectly duplicating variables (#27150)
Fixes #26902 

See 507963a480
2021-07-14 21:16:11 +00:00
JJ Kasper
8c3c2b7ea2
Update redirect regexes to not match _next (#27143)
This updates redirects' regexes to not match `/_next` paths since this is currently unexpected and can easily cause a multi-match redirect to break loading client-side assets. This also fixes custom-routes not matching correctly when `trailingSlash: true/false` is used

## Bug

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

x-ref: https://github.com/vercel/next.js/discussions/24683
x-ref: [slack thread](https://vercel.slack.com/archives/CGU8HUTUH/p1626159845474000)
2021-07-13 19:38:14 +00:00
Gerald Monaco
cb8da5778e
Replace withCoalescedInvoke with ResponseCache (#26997)
By itself, `withCoalescedInvoke` with a separate `this.incrementalCache.set(...)` isn't really suitable for streaming responses. Since streaming is asynchronous, updating the cache separately introduces a gap where another origin request for the same resource could be made.

This could potentially be addressed by moving the cache update, but then `IncrementalCache` itself would need to be made to support streaming, in addition to the many other responsibilities it has. In this case, it seemed best to just use composition to add another caching layer in front of it, which is a familiar and understandable concept. Eventually, we might want to move this cache to the HTTP layer, which will also be simpler with this change.

As an added bonus, `renderToResponseWithComponents` becomes significantly simpler, and we delete some duplication.
2021-07-12 19:47:39 +00:00
Steven
9777707d67
Add test for placeholder=blur with assetPrefix (#27120)
Follow up to https://github.com/vercel/next.js/pull/27061#pullrequestreview-703527621
2021-07-12 18:58:20 +00:00
Steven
31c3f33639
Enhance next dev performance with placeholder=blur (#27061)
This PR changes the implementation of `placeholder=blur` when using `next dev` so that it lazy loads on-demand.

This will improve the developer experience for web apps with many blurred images.
2021-07-10 20:27:14 +00:00
Tobias Koppers
7a8da9741d
add support for esm externals (#27069)
add `experimental.esmExternals: boolean | 'loose'` config option

remove `output.environment` configuration in favor of `target`

|                          | `esmExternals: false` (default) | `esmExternals: 'loose'` | `esmExternals: true` |
| ------------------------ | ------------------------------- | ----------------------- | -------------------- |
| import cjs package       | `require()`                     | `require()`             | `require()`          |
| require cjs package      | `require()`                     | `require()`             | `require()`          |
| import mixed package     | `require()` ***                 | `import()`              | `import()`           |
| require mixed package    | `require()`                     | `require()`             | `require()`          |
| import pure esm package  | `import()`                      | `import()`              | `import()`           |
| require pure esm package | Error **                        | `import()` *            | Error **             |
| import pure cjs package  | `require()`                     | `require()`             | Resolving error      |
| require pure cjs package | `require()`                     | `require()`             | `require()`          |

cjs package: Offers only CJS implementation (may not even have an `exports` field)
mixed package: Offers CJS and ESM implementation via `exports` field
pure esm package: Only offers an ESM implementation (may not even have an `exports` field)
pure cjs package: CommonJs package that prevents importing via `exports` field when `import` is used.

`*` This case will behave a bit unexpected for now, since `require` will return a Promise. So that need to be awaited. This will be fixed once the whole next.js bundle is ESM. It didn't work at all before this PR.
`**` This is a new Error when trying to require an esm package.
`***` For mixed packages we prefer the CommonJS variant to avoid a breaking change.

## Feature

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

## Documentation / Examples

- [ ] Make sure the linting passes
2021-07-10 16:49:02 +00:00
Michiel Van Gendt
d22ecd97f4
Include message body in redirect responses (#25257)
### Description
The redirect responses from the redirect function do not contain a message body. This is in conflict with the RFCs below and causes Traefik (a reverse proxy) to invalidate the responses. In this pull request, I add a response body to the redirect responses.

### References
- https://datatracker.ietf.org/doc/html/rfc7230#section-3.3
> All 1xx (Informational), 204 (No Content), and 304 (Not Modified) responses must not include a message-body. All other responses do include a message-body, although the body may be of zero length.

- https://datatracker.ietf.org/doc/html/rfc7231#section-6.4.3
> The server's response payload usually contains a short hypertext note with a hyperlink to the different URI(s).

- traefik/traefik#4456
- https://github.com/auth0/nextjs-auth0/pull/399
2021-07-09 16:32:48 +00:00
Steven
1a8ad14089
Rename next/image dangerously-unoptimized to custom and warn when applicable (#26998)
Since we are no longer accepting new built-in loaders, users may wish to use a different cloud provider.

So this PR renames `dangerously-unoptimized` to `custom` to handle this case as well as the intention of `next export`.

If the user doesn't add a `loader` prop, we throw an error.
If the user adds a `loader` prop but it doesn't return the width, we print a warning.

- Follow up to #26847 
- Fixes #21079 
- Fixes #19612 
- Related to #26850
2021-07-08 19:35:19 +00:00
Steven
b6c590bce1
Loosen next/image TS types for src (#26996)
### Description
This changes the strict TS types to a looser implementation such that the user can pass `src` without TS errors.

### Pros vs Cons
- **Pros**: better support for wrapping `next/image` so that TS won't report false errors
- **Cons**: using `src: string` without `blurDataURL` will no longer show TS errors and instead fail with a runtime error

### Issues
- Fixes #26892 
- Related to #26991
2021-07-07 21:31:30 +00:00
destruc7i0n
12aa56123b
Fix hash change events not firing with i18n (#26994)
My last PR (#26205) made the hash change events not fire when in i18n was enabled, as seen in #26853. This PR fixes that and adds a test for this case.

fixes #26853 

## 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
2021-07-07 20:54:56 +00:00
Darsh Patel
226e81c733
Add dangerously-unoptimized loader for next/image (#26847)
* add support for static loader

* update existing test

* add test

* add prettier-ignore

* update docs

* apply suggestions from review

* remove un-needed normalize

* Apply suggestions from code review

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

* update test

Co-authored-by: JJ Kasper <jj@jjsweb.site>
Co-authored-by: Steven <steven@ceriously.com>
2021-07-07 15:20:16 -05:00
Steven
23a47b9f87
Loosen next/image TS types for width and height (#26991)
### Description
This changes the strict TS types to a looser implementation such that the user can always pass `width` and `height` (even when `layout=fill`) without TS errors.

### Pros vs Cons
- **Pros**: better support for wrapping `next/image` so that TS won't report false errors with `layout=fill`
- **Cons**: omitting width/height when using other `layout` will no longer show TS errors and instead fail with a runtime error

### Issues
- Fixes #26531 
- Fixes #25440
2021-07-07 19:15:31 +00:00
Alex Castle
8066e423a7
Don't lazy-load already-loaded image in client-side transition (#26968)
fixes #19074 
This change disables image lazy-loading when both of the following are true:
1) A image is being rendered following a client-side page transition
2) The image has been previously loaded during this session.

Before this change, all images with lazy-loading enabled have a visible flicker during client-side page transitions, even though they're already loaded.

With this change, there's are two performance risks:

1) There's a chance that some offscreen images will have lazy-loading disabled unnecessarily because they were previously loaded. I think the performance hit here is pretty negligible and the situation is unlikely to come up very often.

2) There's a chance a different-sized version of the image will be selected by the browser, but lazy-loading will be disabled anyway. This seems even more unlikely to me, and anyway the performance hit from a stray un-lazy-loaded image (on a client-side transition) is very minor.

In both cases, I think the performance risk is outweighed by the UX improvement of getting rid of the image flicker on page transition.
2021-07-07 17:51:16 +00:00
JJ Kasper
c53b60a885
Fix forward slash encoding while interpolating (#26963) 2021-07-06 16:28:43 -05:00
Alexander
f8269fd4a6
Fix: (rewrites) incorrect parsing of destination query (#26619)
fixes #26609

## Bug

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

## Documentation / Examples

- [x]  Make sure the linting passes
2021-07-06 21:20:53 +00:00
Theo Strahlen
38a4e56cfa
(next/image): Merge query string params in imgix loader (#26719)
If the `Image` src url had existing query params, the imgix loader would simply append another query string with `?` causing both query strings to break.

This PR adds a way to safely merge query strings if needed using [URLSearchParams](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams).

## Bug

- [X] fixes #26288
- [X] Integration tests added
2021-07-06 19:51:50 +00:00
Gerald Monaco
2795b79959
Add initial ResponsePayload support (#26938)
Refactors the internals of `next-server` to use `ResponsePayload` instead of `string | null` and manual `sendPayload` calls. This is the first step toward streaming support.

I split `renderToResponseWithComponents` into a separate `renderToResponseWithComponentsInternal` function for ease of review: GitHub's diff rendering was highly misleading, making it seem as though more of the function had changed. The separate function just makes the actual change clearer: we split `renderToHTMLWithComponents` into two promises; one that represents the actual render result, and one that represents all of the work (including background work for e.g. revalidation) that needs to be done as part of generating the result.

These changes make it easier to bubble up a `ResponsePayload`, instead of sometimes calling `sendPayload` out-of-band, centralizing all payload handling in `sendResponse` and eventually a similar function for public APIs that return a string. This centralization will make it much easier to handle a response that needs to be streamed, which is coming soon in another PR.
2021-07-06 09:41:51 +00:00
Maia Teegarden
b8f3a6d2d9
5MB -> 4MB body size limit (#26887)
This decreases the body size limit that triggers a warning from 5MB -> 4MB, which provides a little more wiggle room. Certain things like using base64 on body, headers, path, etc can cause the response to be larger than initially calculated. 

Initial PR: https://github.com/vercel/next.js/pull/26831
2021-07-02 23:17:56 +00:00
JJ Kasper
a6965961bd
Ensure API route errors are propagated in minimal mode (#26875)
This ensures when an error occurs in an API route while using minimal mode the error is bubbled so it can be handled at the top-level 

## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
2021-07-02 20:54:53 +00:00
Maia Teegarden
538095c936
Warn when response body is larger than 5mb (#26831)
This PR adds a warning when api responses exceed 5mb since this will end up failing once deployed. In a future version this scenario will throw an error.

## Bug

- [x] Integration tests added

## Documentation / Examples

- [x] Make sure the linting passes
2021-07-02 19:27:33 +00:00
Alex Castle
277061943a
Don't emit duplicate image files (#26843)
fixes #26607

This change makes it so the image loader plugin only emits a file while processing an image import for the client. The final generated image URL was already the same in SSR and CSR anyway, so this change doesn't have any functional impact.

I also changed the name of the static page in the image component tests, since it was causing some conflicts with the static assets folder.
2021-07-02 11:27:32 +00:00
Tim Neutkens
270487d797
Make sure 404 pages do not get cached by a CDN when using next start (#24983)
Co-authored-by: Jiachi Liu <inbox@huozhi.im>
Co-authored-by: JJ Kasper <jj@jjsweb.site>
2021-07-02 10:40:13 +02:00
Steven
03b61778ba
Fix immutable header for image with static import & unoptimized (#26836)
Fixes #26587
2021-07-01 22:14:42 +00:00
Steven
0562cc77bc
Add additional tests for image type detection (#26832)
Adding additional tests. Follow up to #26705
2021-07-01 20:53:26 +00:00
Joachim Viide
d670198e7c
Add "Vary: Accept" header to /_next/image responses (#26788)
This pull request adds "Vary: Accept" header to responses from the image optimizer (i.e. the /_next/image endpoint).

The image optimizer prefers re-encoding JPG files to WebP, but some browsers (such as Safari 14 on Catalina) do not yet support WebP. In such cases the optimizer uses the Accept header sent by the browser to send out a JPG response. Thus the optimizer's response may depend on the Accept header.

Potential caching proxies can be informed of this fact by adding "Vary: Accept" to the response headers. Otherwise WebP data may be served to browsers that do not support it, for example in the following scenario:
 * A browser that supports WebP requests the JPG. The optimizer re-encodes it to WebP. The proxy caches the WebP data.
 * After this another browser that doesn't support WebP requests the JPG. The proxy sends the WebP data to the browser.

- [x] Integration tests added
- [x] Make sure the linting passes
2021-07-01 19:59:16 +00:00
Steven
93f625428b
Add onLoadingComplete() prop to Image component (#26824)
This adds a new prop, `onLoadingComplete()`, to handle the most common use case of `ref`.

I also added docs and a warning when using `ref` so we recommend the new prop instead.
 
- Fixes #18398 
- Fixes #22482
2021-07-01 18:51:20 +00:00
JJ Kasper
3c994abc29
Update snapshot for font-optimization test (#26823)
This fixes the `font-optimization` test failing from the links/content changing slightly in the snapshot. 

## 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-07-01 17:10:01 +00:00
Jiachi Liu
e89b8e466a
fix: detect loop in client error page (#26567)
Co-authored-by: Tobias Koppers <tobias.koppers@googlemail.com>
Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
2021-07-01 13:54:54 +02:00
Jiachi Liu
c51598268a
Leverage blocked page for _error (#26748)
## Enhance

simplify detection for visiting `_error`

x-ref: #26610
2021-07-01 00:08:36 +00:00
JJ Kasper
be60ef525f
Stabilize relay-analytics test (#26782) 2021-06-30 17:52:40 -05:00
JJ Kasper
010a31cf41
Update azure tests (#26779) 2021-06-30 17:03:43 -05:00
Nils Schönwald
551b6149ce
Fix blurred image position when using objectPosition (#26590)
## Bug

fixes #26309

## Documentation / Examples

see #26309

- [ ] Make sure the linting passes
2021-06-30 21:58:26 +00:00
Steven
2373320fc8
Add upstream max-age to optimized image (#26739)
This solves the main use case from Issue #19914.

Previously, we would set the `Cache-Control` header to a constant and rely on the server cache. This would mean the browser would always request the image and the server could response with 304 Not Modified to omit the response body.

This PR changes the behavior such that the `max-age` will propagate from the upstream server to the Next.js Image Optimization Server and allow browser caching. ("upstream" meaning external server or just an internal route to an image)

This PR does not change the `max-age` for static imports which will remain `public, max-age=315360000, immutable`.

#### Pros:
- Fewer HTTP requests after initial browser visit
- User configurable `max-age` via the upstream image `Cache-Control` header

#### Cons:
- ~~Might be annoying for `next dev` when modifying a source image~~ (solved: use `max-age=0` for dev)
- Might cause browser to cache longer than expected (up to 2x longer than the server cache if requested in the last second before expiration)

## Bug

- [x] Related issues linked using `fixes #number`
2021-06-30 21:26:20 +00:00
JJ Kasper
b046a0595e
Disable build-output size specific tests (#26769)
* Disable build-output size specific tests

* remove size-limit test

* lint-fix
2021-06-30 15:49:49 -05:00
Jiachi Liu
ddc0e793fc
Support new hydrate API in latest react 18 alpha release (#26664)
* fix: react 18 new hydration API

* support react 18

* compat latest react only, fix resolved version

* fix tests

* Some changes based on https://github.com/reactwg/react-18/discussions/5

* fix test

Co-authored-by: Tim Neutkens <timneutkens@me.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2021-06-30 17:03:32 +02:00
Tim Neutkens
5b9ad8da90
Move next-server directory files to server directory (#26756)
* Move next-server directory files to server directory

* Update tests

* Update paths in other places
2021-06-30 13:44:40 +02:00
Tim Neutkens
136b754396
Move code shared between server/client to "shared" folder (#26734) 2021-06-30 11:43:31 +02:00
Houssein Djirdeh
15afd97729
[ESLint] Adds --max-warnings flag to next lint (#26697)
Adds `--max-warnings` flag to `next lint` to enable setting of a maximum warning threshold.

Fixes #26671
2021-06-29 10:12:23 +00:00
hiro
956bc2f387
Fix typo on "occured" to "occurred" (#26709)
* fix: typo occured -> occurred

* fix: typo occured -> occurred

* fix: typo occured -> occurred

* fix: typo occured -> occurred

* lint-fix


Co-authored-by: JJ Kasper <jj@jjsweb.site>
2021-06-28 23:02:20 -05:00
Steven
eabecf3d0a
Fix image content type octet stream 400 (#26705)
Fixes #23523 by adding image content type detection

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
2021-06-28 23:52:04 +00:00
JJ Kasper
5b2c845e57
Ensure API routes are not available under the locale (#26629)
This ensures API routes are not available under the locale path since API routes don't need to be localized and we don't provide the locale to the API in any way currently so the user wouldn't be aware if the localized API route was visited instead of the non-localized. 

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

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
2021-06-28 13:56:40 +00:00
JJ Kasper
c2f0653bd3
Correct statusCode when visiting _error directly (#26610)
This fixes non-stop reloading when visiting `_error` directly in development caused by the `statusCode` being 200 unexpectedly while HMR returns the page as `invalid` which triggers `on-demand-entries` to reload the page. 

## Bug

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

Fixes: https://github.com/vercel/next.js/issues/8036
x-ref: https://github.com/vercel/next.js/pull/8033
2021-06-28 12:50:53 +00:00
JJ Kasper
ae0dbe5e2c
Fix GSP redirect cache error (#26627)
This makes sure we don't attempt flushing cache info to disk for `getStaticProps` `redirect` items with `revalidate`

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

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
2021-06-28 12:23:23 +00:00
Tim Neutkens
170dc0dc33
Add check for ObjectExpression when iterating on <link> tags for font optimization (#26608)
Fixes #26547



## 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-06-25 14:51:53 +00:00
JJ Kasper
18a333e672
Separate node polyfill test from basic suite (#26550)
* Separate node polyfill test from basic suite

* update test
2021-06-24 13:11:09 -05:00
destruc7i0n
be62f023b6
Fix props not updating when changing the locale and keeping hash (#26205)
Currently, there is only a `hashChangeStart` and subsequent `hashChangeComplete` event and no props update (which would be used to get translations, etc.).
Happy for any feedback

fixes #23467

## 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-06-23 19:04:31 +00:00
Brandon Bayer
755a1b412c
Strongly type Router.events.on and Router.events.off (#26456)
This strongly types `Router.events.on` and `Router.events.off`. Previously the event type was `string` but now it's `'routeChangeStart' | 'beforeHistoryChange' | 'routeChangeComplete' | 'routeChangeError' | 'hashChangeStart' | 'hashChangeComplete'`


## Bug

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

Closes #25679
Closes #23753
Closes #15497
2021-06-22 18:43:09 +00:00
JJ Kasper
917a9acc2c
Update to only add image import types when enabled (#26485)
* Update to only add image import types when enabled

* add type check to test
2021-06-22 11:56:21 -05:00
Rob Vermeer
27d78a5d41
Fix domain locales not available on client (#26083)
* bug: Fix domain locales not available on client

* Add test case

* update tests

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2021-06-22 11:55:52 -05:00
Jiachi Liu
fb5fb7f21f
fix: ignore invalid accept-language header (#26476)
Fixes #22329

## Bug

- [x] Related issues linked using fixes #22329
- [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-06-22 15:05:54 +00:00
Tim Neutkens
88ed5269b5
Add runtime to hotUpdateMainFilename (#26256)
Updates the hotUpdateChunk to include `[runtime]` for web workers support.

Fixes #26152
Fixes #19865
Fixes #26144

## 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-06-18 17:12:20 +00:00
Houssein Djirdeh
ce4f1e889e
[ESLint] Adds --quiet flag, TypeScript resolver and bug fixes (#26280) 2021-06-18 15:17:53 +02:00
Steven
c35b01a631
Omit svg static imports if custom webpack config is defined (#26281)
This PR does a couple things:

1. Omit svg static imports if the user has defined custom webpack config with svg rule
2. Change TS type to `any` for svg imports to avoid conflicts with other plugins

The idea is that some users want to use `next/image` with static imports for most image types but not for svg and instead inline those images with a plugin.

- Fixes #25950  
- Fixes #26130 
- Fixes #26176 
- Fixes #26196 
- Fixes #26067 


## Bug

- [x] Related issues linked using Fixes #26130 
- [x] Integration tests added
2021-06-18 00:40:22 +00:00
Gerald Monaco
14f01a1af2
Automatically use createRoot for React@>=18 (#26279)
Also logs a message when defaulting, and a warning when using a prerelease build of `react-dom` (e.g. the React 18 alpha) which are not officially supported.

Note: I've done this in `webpack-config.ts` instead of the Next.js config, as we don't actually want you to be able to opt-out *without* downgrading back to React 17, and so it ought to be entirely removed from the config eventually.
2021-06-17 23:59:28 +00:00
JJ Kasper
76f0b3585f
Update to latest TypeScript version and de-dupe versions (#26285)
* Update to latest TypeScript version and de-dupe versions

* Update version test
2021-06-17 17:43:25 -05:00
Taehun Jeong
51022d5819
Fix Show error when user put wrong values in width or height (#26166)
## Bug

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

fixes #26135

## 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 #26135 `
- [ ] 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-06-17 20:17:31 +00:00
JJ Kasper
ef379f1500
Ensure has query encoding is normalized (#25732)
* Ensure has query encoding is normalized

* fix type error
2021-06-17 10:52:11 -05:00
JJ Kasper
598b1ef11b
Fix long URLs causing 400s with dynamic routes/rewrites (#26221)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2021-06-17 10:59:46 +02:00
Marco Valsecchi
22676abb31
Fix next/image noscript src path with loaders (#24011)
In the `noscript` img version the correct `src` and `sizes` attributes are overwritten by not necessary inline declaration; in particular using the loaders the `src` attribute not take the right absolute path. I found this issue using a custom loader and because my site didn't indexing any images on the Google image search.

Fixes #24277
2021-06-16 20:53:40 +00:00
Antoine Chalifour
70dffd444d
fix: use a client-side navigation when redirecting to a rewriten URL (#25990)
This PR is an attempt to fix #25943. The implementation is only a proposal and I'll be happy to take any feedback about it :)

Fixes: #25943

## 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-06-16 19:50:10 +00:00
JJ Kasper
8610ba4b5e
Fix eslint version check for older versions (#26212) 2021-06-16 14:16:01 -05:00
Jonathan Wilsson
82bad10a29
Fix babel-loader failing on JSON5 syntax (#26194)
## 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: https://github.com/vercel/next.js/issues/26163
2021-06-16 17:26:43 +00:00
Janicklas Ralph
353bfaa0f7
Script component docs (#25471)
* Script component docs

* Update docs with examples and feedback changes

* Fix typo

* Add example

* Update text

* Apply suggestions from code review

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2021-06-15 09:20:29 -05:00
JJ Kasper
5a78f59aeb
Add lint checking events (#26089)
* Add lint checking events

* remove extra log

* Update check

* Update version check
2021-06-14 20:31:40 -05:00
Vitaly Baev
66cb786df0
fix: don't create .eslintrc if package.json contains eslintConfig (#26025)
* fix: don't create .eslintrc if package.json contains eslintConfig

* tests: added integration tests for next lint

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2021-06-14 15:57:18 -05:00