Commit graph

1215 commits

Author SHA1 Message Date
Tobias Koppers
2c2ac2e868
reduce the number of write syscalls by buffering (#23863)
buffer the output of bfj to avoid 1000s of small write calls
2021-04-09 21:43:30 +00:00
Tim Neutkens
a561dd9cdb
Resolve new babel loader through require.resolve (#23819) 2021-04-08 16:15:42 +02:00
Dale Bustad
c2dfe40296
Babel fast mode (#23760)
@timneutkens it'd be great to get your input.

These changes introduce a new Babel loader that eliminates much of the existing overhead, resulting in better HMR speeds. 
 Multithreading is still in flight, and may be omitted if speed improvements end up being negligible.  For now, the new loader is hidden behind an `experimental` flag.

Items to be completed before this PR is ready to merge:

- [x] reconfigure `ncc` to precompile the parts of `@babel/core` and `@babel/traverse` that we're accessing directly
- [x] change `@babel/core/...` imports to `ncc`ed version
- [x] ~~measure multithreading (not currently pushed) functionality, and include the functionality depending on the results~~ I'll open a separate PR for this
- [x] ensure TypeScript is happy with all imports as final step (`--no-verify` was used to bypass)

There will be two follow-up PRs:
- loader support for projects with custom `.babelrc`
- multithreaded loader (should the change we warranted after measurement)
2021-04-08 12:03:02 +00:00
JJ Kasper
55c6b7aba2
Ensure basePath is not applied for external GSSP redirect (#23673)
This ensures we don't attempt prepending the `basePath` for external (http://) `getStaticProps`/`getServerSideProps` redirects. Additional tests to cover this case have been added in the `gssp-redirect` test suites to prevent regression.

## Bug

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

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

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

## Feature

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

## Documentation / Examples

- [ ] Make sure the linting passes

Fixes: #23716
2021-04-06 08:32:29 +00:00
Janicklas Ralph
8fdcc52854
Font optimization (#21676)
Enable font optimization by default
2021-04-05 17:47:03 +00:00
Joe Haddad
eecc3342cb
Temporarily remove experimental ESLint integration (#23521)
This pull request **temporarily** removes ESLint, as it was not landed in accordance with our standard experimental policies. We are fully committed to landing this change again.

This is being reverted because:

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

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



## Bug

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

## Feature

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

## Documentation / Examples

- [ ] Make sure the linting passes
2021-03-26 15:19:48 +00:00
JJ Kasper
a6c0d76ebb
Run server client/server builds serially (#23371)
Previously we special cased serverless builds and ran the client/server builds serially to allow the server build to load manifests produced in the client. To help with memory usage and for consistency this updates server mode to build in the same way.  

## 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-03-24 20:50:49 +00:00
JJ Kasper
75c721c583
Add has route field (#22341)
This adds support for a `has` field to `rewrites`, `redirects`, and `headers` to allow matching against `header`, `cookie`, and `query` values. Documentation and additional tests for the feature is also added in this PR. 

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

This PR:

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

Fixes #23169



## Bug

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

## Feature

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

## Documentation / Examples

- [ ] Make sure the linting passes
2021-03-23 20:59:42 +00:00
Tobias Koppers
8c72806ace
add separate progress output for typechecking (#23226)
## Bug

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

## Feature

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

## Documentation / Examples

- [ ] Make sure the linting passes

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

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

X-ref: #9474, #15569, #19928, #20374.
2021-03-19 16:43:46 +00:00
Tobias Koppers
b267635d63
rename to NEXT_WEBPACK_LOGGING (#23186)
as vercel doesn't allow env vars starting with _
2021-03-18 12:53:41 +00:00
Tobias Koppers
a408416299
get files from entrypoints instead of from chunks (#23174) 2021-03-18 11:14:58 +00:00
Tobias Koppers
75c62cb74c
add env var to enable advanced webpack logging and profiling (#23178)
This allows to use `__NEXT_WEBPACK_LOGGING` to enable verbose webpack logging output to investigate into performance and cache problems.

`__NEXT_WEBPACK_LOGGING=1` enables some basic logging

`__NEXT_WEBPACK_LOGGING=infrastructure` enables only infrastructure logging

`__NEXT_WEBPACK_LOGGING=profile-client` enables deep profile output of the client build

`__NEXT_WEBPACK_LOGGING=profile-server` same for the server

`__NEXT_WEBPACK_LOGGING=profile-client,infrastructure` combines multiple things
2021-03-18 09:46:07 +00:00
Tobias Koppers
e019ef6acc
update webpack, fix runtime location, fix undeclared variable, omit env vars from cache version (#23113)
* this will fix problems with serverless target which doesn't use a runtime chunk
* It also omit env vars from contributing to cache version as webpack will handle that now
* It moves the webpack-runtime chunk from ./chunks back to ./
2021-03-17 08:32:45 +00:00
Shu Ding
1bf4cf3e76
Upgrade jest-worker (#23077)
This PR upgrades `jest-worker` and `jest-cli` to the latest pre-release version, also removed `jest-circus` which is included in Jest by default. `jest-worker@next` includes a fix for memory leak that we need (https://github.com/facebook/jest/pull/11187). 

Fixes #22925. This will also improve the OOM issue for `next dev` #15855.
2021-03-16 21:08:35 +00:00
JJ Kasper
9afcdfcbc4
Ensure i18n index prefetch is correct with trailingSlash (#22746)
This fixes index data route loading for i18n with `trailingSlash: true` enabled and also fixes prerendering `asPath` values not containing a trailingSlash when enabled. 


Fixes: https://github.com/vercel/next.js/issues/17813
Fixes: https://github.com/vercel/next.js/issues/22747
2021-03-14 12:58:34 +00:00
JJ Kasper
7e63bd7d54
Ensure export only triggers when static pages are present (#22996)
This makes sure we don't trigger the export step if we aren't exporting any static pages during a build. This also adds an invariant to ensure we don't attempt creating a progress with 0 items.

Fixes: https://github.com/vercel/next.js/issues/22994
2021-03-12 08:36:28 +00:00
Dale Bustad
e27b7e996d
Telemetry-compatible tracing (#22713)
A number of changes here.  I recommend viewing the diff with the <a href="?w=1">whitespace flag enabled</a>.

- OpenTelemetry is replaced with a custom and lightweight tracing solution.
- Three trace targets are currently supported: console, Zipkin, and NextJS.
- Tracing is now governed by environment variables rather than `--require instrument.js`.
  + `TRACE_TARGET`: one of `CONSOLE`, `ZIPKIN`, or `TELEMETRY`; defaults to `TELEMETRY` if unset or invalid.
  + `TRACE_ID`: an 8-byte hex-encoded value used as the Zipkin trace ID; if not provided, this value will be randomly generated and passed down to subprocesses.

Other sundry:

- I'm missing something, probably a setup step, with the Zipkin target.  Traces are captured successfully, but you have to manually enter the Trace ID in order to view the trace - it doesn't show up in queries.
- I'm generally unhappy with [this commit](235cedcb3e).  It is... untidy to provide a telemetry object via `setGlobal`, but I don't have a ready alternative.  Is `distDir` strictly required when creating a new Telemetry object?  I didn't dig too deep here.

As noted, there are a lot of changes, so it'd be great if a reviewer could:

- [ ] pull down the branch and try to break it
- [ ] check the Zipkin traces and identify possible regressions in the functionality

Closes #22570
Fixes #22574
2021-03-10 21:00:20 +00:00
JJ Kasper
e84571d8e3
Add appDir field to server files manifest (#22915)
This adds an `appDir` field to the `required-server-files` manifest signifying where the app source is located. 

x-ref: https://github.com/vercel/next.js/issues/22847
2021-03-09 18:41:57 +00:00
JJ Kasper
d951b2385f
Update /500 page exporting when _error has custom GIP (#22887)
This updates to not automatically export `/500` from `_error` if a custom `getInitialProps` is used since logic may be used inside of this method that causes the export to fail. Users can still opt-in to the static `/500` by adding a `pages/500.js` file. 

This also refactors checking `_app` for custom `getInitialProps` to outside of the static check loop to prevent a potential race condition where we could run this check multiple times un-necessarily.  

Fixes: https://github.com/vercel/next.js/issues/22815
2021-03-09 09:55:28 +00:00
JJ Kasper
1435de15bc
Ensure component load order (#22731)
This ensures we load `_document` then `_app` and then the page's component in all cases which matches behavior between the serverless target and the default server target.  Additional tests to ensure this order is followed has been added to prevent regression. 

Fixes: https://github.com/vercel/next.js/issues/22732
2021-03-03 19:20:48 +00:00
JJ Kasper
b80fdfb828
Update webpack server chunks output (#22697)
This updates to output server chunks to a nested folder to prevent bundling the entire folder when tracing. This also fixes the webpack 5 tests not actually using webpack 5 since https://github.com/vercel/next.js/pull/22583 since the webpack 5 enabling check didn't account for the test environment variable used to enable webpack 5. This also clears up some deprecation warnings from webpack 5 in the mini-css-extract-plugin.

Fixes: https://github.com/vercel/next.js/issues/21297
2021-03-03 09:37:24 +00:00
Janicklas Ralph
a107dcb732
Experimental script loader changes (#22038)
Making experimental script work in _document.js - Fixes for server to client transition
Adding additional test for _document.js
2021-03-02 19:17:33 +00:00
Joe Haddad
04f37d0978
fix: load webpack hook before config is required (#22583)
This pull request ensures the webpack hook is installed before an attempt is made to load the configuration.

This pull request is tested by the PnP tests, which should now be passing as a result of this change.

---

Fixes #21679
2021-02-27 06:19:35 +00:00
Jan Potoms
1ebc9bbb5e
Load next.config.js async (#22578)
Just the conversion of config loading from sync to async from https://github.com/vercel/next.js/pull/22153

cc @Timer
2021-02-27 00:29:32 +00:00
lindsaylevine
b1a1c80e7c
bug (#21943): remove incorrect rewrite of parsedUrl.pathname in serverless handler (#22445)
Fixes https://github.com/vercel/next.js/issues/21943

i confirmed in a personal test repo that this solves the issue of infinite 307s on root level non-default locales :)  let me know what else this needs if anything! thanks for the time/help @ijjk ❤️
2021-02-25 18:43:51 +00:00
Joe Haddad
775bdc341e
fix: correctly handle fallbacks for webpack 5 (#22497)
Co-authored-by: JJ Kasper <jj@jjsweb.site>
2021-02-24 10:25:57 -06:00
JJ Kasper
51e0752f87
Add generating static 500 status page (#22139)
This adds generating a static 500 status page when a `pages/500.js` file is added similar to how we handle generating static 404 pages when `pages/404.js` is present. This allows showing a customized error page when a 500 error occurs in an optimal way.
2021-02-22 16:29:50 +00:00
Tim Neutkens
9ab98bc956
Reduce webpack watcher aggregate timing (#22418)
Reduces the time the watcher waits for events coming in before compiling.
2021-02-22 14:06:49 +00:00
Tim Neutkens
3cef2e10ed
Delay server compilation until client compilation is done in development (#22187)
Co-authored-by: JJ Kasper <jj@jjsweb.site>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2021-02-19 11:10:19 +01:00
Joe Haddad
99a4ea6e9a
feat(next/image): remove sharp for wasm variant (#22253)
This pull request removes the native `sharp` dependency (which doesn't work on some Linux variants, nor **M1 Mac**) and replaces it with a wasm equivalent.

It also reduces Next.js' installed size by 27.3 MB.

The code is adapted from the [Squoosh CLI](https://github.com/GoogleChromeLabs/squoosh).

This PR still supports:

- Rotation normalization
- Resizing
- PNG
- JPEG
- Webp

However, it (temporarily) removes support for:
- Resizing Gifs
- Resizing Tiff

(these formats still get served and rendered correctly by the image component)

---

Fixes #20456
Closes #20738
Closes #21762
2021-02-18 10:23:24 +00:00
Janicklas Ralph
cf6bc446ea
Experimental feature - fix optimizeCss flag for serverless deployments (#21790) 2021-02-17 22:52:43 +00:00
Kristoffer K
89edd34ff8
fix: register webpack hook earlier and use absolute paths (#21877) 2021-02-16 09:51:52 +01:00
Tim Neutkens
83657b6bce
Check if parentspan is provided in profiler (#22061)
Co-authored-by: Dale Bustad <dale@divmain.com>
2021-02-12 11:17:38 +01:00
JJ Kasper
55e4a3d1ad
Only create locale domain links if on locale domain (#22032)
This updates to only create locale domain links if the current hostname is a locale domain to prevent making links unvisitable in development and preview environments where the configured locale domains don't point to the current build. 

Closes: https://github.com/vercel/next.js/issues/21211
Closes: https://github.com/vercel/next.js/issues/22011
2021-02-11 10:18:24 +00:00
JJ Kasper
5febe218a6
Add nccing AMP optimizer (#21980)
This adds ncc'ing the AMP optimizer package to speed up install times and cache the runtime. 

Closes: https://github.com/vercel/next.js/issues/20404
2021-02-11 09:55:56 +00:00
Tim Neutkens
6b99bda3e3
Fix profiling plugin for next build (#21989)
Makes sure `yarn trace build` works.
2021-02-09 23:21:38 +00:00
Tim Neutkens
44fa86e384
Make sure all modules are included in the stats file (#21942) 2021-02-07 20:06:41 +01:00
Tim Neutkens
6387f368dc
Update reasons array to use module id instead of identifier (#21895)
Missed this then changing the modules array to rely on `module.id`
2021-02-05 16:39:46 +00:00
Tim Neutkens
15d02f6559
Make experimental stats file approximately 90% smaller (#21858)
Tested against some smaller apps. Will have a high impact for larger apps.
2021-02-04 19:21:54 +00:00
Guy Bedford
234e1c9601
feat: Implement webpack require hook (#21802)
This implements the compatibility require hook as per https://github.com/vercel/next.js/issues/21789.

The hook is applied at the point of webpack initialization. In addition the separate packages are exposed for the various webpack subrequires.

The test then ensures instance equality for the basic require hook from the next.js config file.

I suspect this might have bad interactions with Yarn Pnp support, but maybe we will be lucky.
2021-02-04 08:49:42 +00:00
JJ Kasper
6d80e6e5f3
Add version for stats (#21823)
Adds versioning for the stats output
2021-02-03 20:46:35 +00:00
JJ Kasper
523537178c
Add stats config option (#21761)
This adds a config to output webpack's stats
2021-02-02 15:39:39 +00:00
Janicklas Ralph
8f21c283b2
Experimental feature changes (#21646)
Adding test for experimental-serverless-trace + fix for the same
2021-01-29 13:53:07 +00:00
Dale Bustad
652a1e8915
Improvements to webpack tracing, including hot-reload (#21652)
@timneutkens I think this is ready for a review.

I've made some changes to the original design that _seem_ to have paid off.  The parenting relationships for traces of normal builds are applied more uniformly, resulting in more intelligible traces:

<img width="900" alt="Screen Shot 2021-01-29 at 12 53 47 AM" src="https://user-images.githubusercontent.com/5016978/106253732-ba321880-61cc-11eb-98fd-d45af5078273.png">

Hot-reloading is surfaced now, too.  I will note, however, that we will want to dig in deeper and find out where the large portion of time at the beginning of hot-reload is spent.  Example:

<img width="894" alt="Screen Shot 2021-01-29 at 12 53 28 AM" src="https://user-images.githubusercontent.com/5016978/106253828-e057b880-61cc-11eb-967d-46eaff31ecef.png">

Where did those 180 ms go?  At the least, we can now track how long a hot-reload takes, and have a place to start with further investigation.
2021-01-29 10:32:26 +00:00
JJ Kasper
87ed37d51c
Ensure prerender-manifest contains all i18n revalidate values (#21404)
This insures we add entries for each locale version of a non-dynamic SSG page since they can have unique revalidate values. This requires a version bump in the `prerender-manifest` since the static routes now contain additional values which need to be handled separately. 

Fixes: https://github.com/vercel/next.js/issues/21568
2021-01-27 11:24:00 +00:00
Ryan
8798c40c96
Require only build directory to be writeable for build (#20977)
Allows building without permission to write to the application directory, useful for containers and sandboxes.
2021-01-25 12:09:22 -05:00
Chulki Lee
fc34f89a80
Fix hostname message in dev/start (#20409) 2021-01-25 16:13:12 +01:00
Joe Haddad
74b6389bd6
ci: fix webpack 5 enabling for tests (#21436)
* ci: fix webpack 5 enabling for tests

* refactor: move default location

* Disable incompatible suite
2021-01-22 11:20:53 -06:00
JJ Kasper
5b70802f61
Preserve asPath while resolving rewrites (#21410)
* Preserve asPath while resolving rewrites

* remove un-needed alias

* Add new alias

* Add return type for resolve rewrites
2021-01-21 17:40:23 -06:00
Joe Haddad
47ec677127
chore: compile css-loader (#21357)
This PR compiles `css-loader` to resolve a peer dep warning.
2021-01-20 05:47:25 +00:00
Joe Haddad
55b8502dd0
chore: compile style-loader dep (#21355)
This PR compiles `style-loader` to resolve a peer dep warning.

---

Closes #21359
2021-01-20 05:25:46 +00:00
Joe Haddad
ab158c0aee
chore: compile resolve-url-loader (#21351)
Closes #21166
2021-01-19 20:08:24 +00:00
Tim Neutkens
85624d6164 Remove console.log 2021-01-19 09:44:03 +01:00
Tim Neutkens
f8fecf57c3
Fix webpack 5 warning + disabling of profiling (#21276)
Noticed that there was a specific warning when using webpack 5.
2021-01-18 16:38:00 +00:00
Tobias Koppers
b02df3f487
improve splitChunks config for webpack 5 (#21208) 2021-01-17 20:05:47 +01:00
Tobias Koppers
9c4d368459
use webpack resolve api to resolve in externals config (#21205) 2021-01-17 20:02:20 +01:00
Gerald Monaco
cd5ea7db1f
Bump minimum suggested React version (#21046)
* Upgrade React version warning

* Fix font/stylesheet plugin

* Fix size-limit tests

* Fix build-output test

* Add tests for React 16

* Fix react-dom version
2021-01-14 22:29:57 -05:00
Guy Bedford
005a8abe39
feat: Webpack loader inlining (#21127)
This picks up on the inlining work in https://github.com/vercel/next.js/pull/20598 to also include webpack loader inlining optimizations.

This includes:
* The dependencies of sass-loader
* resolve-url-loader

And for added benefit:
* babel-plugin-transform-define
* babel-plugin-transform-react-remove-prop-types

style-loader and css-loader didn't inline easily. Perhaps we can come back to these ones.
2021-01-15 01:51:45 +00:00
Guy Bedford
bddb02286f
feat: webpack inlining with configuration for v4 / v5 (#20598) 2021-01-13 20:59:08 -05:00
JJ Kasper
9caca2784c
Add proper error when conflicting paths are detected (#20918)
This helps catch conflicting paths returned from `getStaticPaths` with a friendly error

<details>

<summary>
Preview of error
</summary>


<img width="962" alt="Screen Shot 2021-01-08 at 5 03 04 PM" src="https://user-images.githubusercontent.com/22380829/104074719-6e481100-51d6-11eb-9397-938aee3ae30b.png">
<img width="962" alt="Screen Shot 2021-01-08 at 5 03 41 PM" src="https://user-images.githubusercontent.com/22380829/104074722-6f793e00-51d6-11eb-90f6-7cdf9882bf00.png">

</details>




Closes: https://github.com/vercel/next.js/issues/19527
2021-01-11 20:50:17 +00:00
Joe Haddad
d0e28549af
feat(css): add strictPostcssConfiguration flag (#20914)
This pull request adds `future.strictPostcssConfiguration`, allowing users to opt-into the more strict PostCSS configuration loading.

This stricter PostCSS configuration loading ensures that CSS can be cached across builds.
2021-01-11 17:19:56 +00:00
Kristoffer K
1c75bf789b
perf(next): use require.resolve instead of resolve (#19518)
**What's the problem this PR addresses?**

- ~~https://github.com/vercel/next.js/pull/18768 started to ncc babel and thus it's version of resolve which breaks PnP support~~
Babel replaced `resolve` with the builtin `require.resolve` and a polyfill for older node versions in https://github.com/babel/babel/pull/12439 which was upgraded in https://github.com/vercel/next.js/pull/20586
- `next` unnecessarily bundles the `resolve` package when `require.resolve` is builtin and can do the same job

**How did you fix it?**

- ~~Avoid running `resolve` through ncc~~
Added a test for https://github.com/vercel/next.js/issues/19334 (closes https://github.com/vercel/next.js/issues/19334)
- Replace `resolve` with `require.resolve`
2021-01-11 14:43:08 +00:00
Kristoffer K
4e3eb733c8
fix(next): always enable absoluteRuntime when running under webpack (#19538)
**What's the problem this PR addresses?**

In https://github.com/vercel/next.js/pull/18921 I enabled `absoluteRuntime` for everyone (it was only enabled for PnP users) but didn't consider that people used the babel preset outside of the webpack build.

Fixes https://github.com/vercel/next.js/issues/19448 - ~~Since it doesn't contain a repro I can't be certain but based on feedback from @koshea in https://github.com/vercel/next.js/pull/18921#issuecomment-733744645 I'll assume @RossMcMillan92 is doing the same thing, because when next is building it doesn't leave absolute paths as external.~~
Confirmed in https://github.com/vercel/next.js/pull/18921#issuecomment-734224014

**How did you fix it?**

Only enable `absoluteRuntime` when the preset is running under `babel-loader`
2021-01-11 14:21:58 +00:00
Hyeon Kim (김지현)
552aa9df1a
Prevent unpredictable dependency hosting by explicitly resolve module path on webpack.ProvidePlugin (#20971)
ProvidePlugin replaces certain identifiers with another modules. As a result, 'buffer' and 'process' modules are added as implicit dependencies to all Next.js plugins. This can be problematic. With "Plug'n'Play" strategy, it don't work at all since they fail-fast with implicit dependencies. With "node_modules" strategy, it might seem OK but actually it can be result into unpredictable behavior since in uses dependency [hoisting](https://yarnpkg.com/advanced/lexicon#hoisting).

For example, currently users cannot use next-auth plugin with Plug'n'Play strategy:

![image](https://user-images.githubusercontent.com/4435445/103481517-d5547700-4e1e-11eb-9f23-bc2c9939418e.png)

This patch let Next.js properly handles such cases with `require.resolve`.

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

###### References:
- https://github.com/nextauthjs/next-auth/pull/1034
2021-01-11 12:31:31 +00:00
Tim Neutkens
90ad2cbc44
Update profiling approach to cover webpack runs (#20900) 2021-01-09 20:12:13 -05:00
JJ Kasper
991ad9225a
Update error for mis-matching path in getStaticPaths (#20767)
This updates the error shown when a path doesn't match the dynamic route in `getStaticPaths` to not include the `locale` since this isn't considered when matching against the dynamic route.
2021-01-06 10:27:32 +00:00
Joe Haddad
58ea3bb479
fix(next/babel): read env from caller, not process (#20679)
This PR fixes a bug where `next/babel` would accidentally enable development transforms for a production build (`next build`).

This is tested by the two updated unit tests (which removed a workaround for this bug, and one now properly enables dev transforms).

---

Fixes #18929
Fixes #19001
x-ref #19046
x-ref #17032
2021-01-02 00:36:16 +00:00
Joe Haddad
984ac96dc6
chore: remove old traces of next/data experiment (#20678)
This PR removes some left over traces of the `next/data` experiment, as it has been superseded by RSC.
2021-01-01 22:23:42 +00:00
Joe Haddad
2c75fa0d9e
fix(source map): correctly generate source maps (#20672)
Fixes #20500
2021-01-01 20:30:50 +00:00
JJ Kasper
9c8d04654e
Ensure all entries are cleared from cache on runtime change (#20652) 2021-01-01 12:39:39 -05:00
JJ Kasper
5324e8b6ee
Ensure SSG data 404 handles correctly for non-notFound (#20622)
Follow-up to https://github.com/vercel/next.js/pull/20594 this ensures non-notFound SSG data 404s do cause a hard navigation as this signals a new deployment has occurred and a hard navigation will load the new deployment's version of the page. 

Closes: https://github.com/vercel/next.js/issues/20623
2020-12-30 22:35:02 +00:00
JJ Kasper
75509164ab
Ensure domain locales are redirected client-side (#20562)
This ensures we detect domain specific locales and redirect them client-side. Tests have been added in the `i18n` suite to ensure the domain redirect is applied correctly during a client-side navigation

Fixes: https://github.com/vercel/next.js/issues/19174
2020-12-30 06:44:07 +00:00
Tim Neutkens
5c5108fe0d
Add profiling to webpack loaders (#20392)
Follow-up to #20357 with additional tracers.
2020-12-29 21:21:35 +00:00
Joe Haddad
61e7dea918
deps: upgrade various deps (mainly babel) (#20586)
Fixes #20585
Closes #20406 as it duplicates Babel dependencies
Closes #18926 as it's outdated
2020-12-29 20:10:08 +00:00
JJ Kasper
eb8e038ddb
Clean up webpack 5 version error (#20578) 2020-12-29 12:35:22 -05:00
Luke Fender
f2f9090a50
Ignore emacs lockfiles (#20497)
Fixes: https://github.com/vercel/next.js/issues/15278

> Bug report

> When using next dev with emacs, as you develop, emacs creates symbolic link files starting with .# as lock files. Next.js seems to attempt to load these but fails, spewing out errors constantly.

Prevents dev server from crashing when emacs creates lockfiles

tested with:

- GNU Emacs 27.1
- OSX 11.1
- Node v15.4.0
2020-12-29 16:12:36 +00:00
JJ Kasper
c93c9fcc78
Add error for invalid webpack 5 version (#20558)
Closes: https://github.com/vercel/next.js/issues/20545
2020-12-29 04:43:57 +00:00
JJ Kasper
c98db81bf4
Remove import type syntax from core files (#20379)
This removes `import type` usage from our core files since `import type` requires a higher TypeScript version than currently expected.

Fixes: https://github.com/vercel/next.js/issues/19300
2020-12-28 22:04:51 +00:00
JJ Kasper
1203b9082b
Ensure path encoding is handled consistently for prerendered pages (#19135)
This ensures we handle encoding/decoding for SSG prerendered/fallback pages correctly. Since we only encode path delimiters when outputting to the disk we need to match this encoding when building the `ssgCacheKey` to look-up the prerendered pages. This also fixes non-ascii prerendered paths (e.g. 商業日語) not matching correctly. 

This does not resolve 👉  https://github.com/vercel/next.js/issues/10084 and further investigation will be needed before addressing non-ascii paths for non-SSG pages. 

The encoding output was tested against https://tst-encoding-l7amu5b9c.vercel.app/ to ensure the values will match correctly on Vercel. 

Closes: https://github.com/vercel/next.js/issues/17582
Closes: https://github.com/vercel/next.js/issues/17642
x-ref: https://github.com/vercel/next.js/pull/14717
2020-12-28 20:08:58 +00:00
Joe Haddad
5f311cddd2
fix Fast Refresh tests with webpack@5 (#20543) 2020-12-28 14:18:51 -05:00
Joe Haddad
64c1f726e0
Fix webpack 5 terser compat (#20378)
This PR fixes webpack 5 compatibility with older betas.
2020-12-22 02:53:23 +00:00
JJ Kasper
788183e8d3
Ensure only backslashes are in pages-manifest with i18n (#20376)
This ensures the pages-manifest only includes forward slashes and not backslashes when adding i18n page references, this also adds tests ensuring we don't regress on this in the i18n-support test suite. 

Fixes: https://github.com/vercel/next.js/issues/20330
2020-12-22 01:51:51 +00:00
Joe Haddad
260ab51974
temporary: re-flag font optimization (#20372)
There's currently two bugs with the font optimization, but we'd really like to ship a stable version.

To unblock the stable release, we're **temporarily** reflagging this. It'll be unflagged on canary again!
2020-12-21 19:26:00 +00:00
Tim Neutkens
a9f1975738
Update experimental profiling (#20357)
Adds profiling for terser and css-minimizer. Will move the old profiler to this new system as well.
2020-12-21 16:02:41 +00:00
Tim Neutkens
72fae8bed4
Move productionBrowserSourceMaps out of experimental (#20267)
Makes https://www.npmjs.com/package/@zeit/next-source-maps a built-in feature so that it can be deprecated.
2020-12-17 15:04:17 +00:00
JJ Kasper
e819e00d0c
Add required server files manifest (#20035)
This keeps track of required server files in a manifest file
2020-12-16 20:46:55 +00:00
Tim Neutkens
5d5383b263
Update font-stylesheet-gathering-plugin to be webpack 5 compatible (#20229)
Solves the following warning:

> (node:1484) [DEP_WEBPACK_MAIN_TEMPLATE_REQUIRE_FN] DeprecationWarning: MainTemplate.requireFn is deprecated (use "__webpack_require__")
2020-12-16 14:35:50 +00:00
Tim Neutkens
8ed132deb6
Update import to prevent loader from erroring in webpack 5 (#20211)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2020-12-16 08:56:14 +01:00
Tim Neutkens
81e67ce95e
Update terser-webpack-plugin to support webpack 4 (#20089)
Solves some of the cache warnings when using webpack 5
2020-12-12 20:28:53 +00:00
Tim Neutkens
4bca939ff7
Remove aliases that are no longer needed (#19937)
Fixes #19939
2020-12-07 22:35:28 +00:00
Pepijn Senders
3f730fc7b1
Improve way cache version string is created (#19763)
Nitpicky change, but the version string contained a double `|`, implying that there might be an empty value between `process.env.__NEXT_VERSION` and the environment variables.
2020-12-04 14:08:02 +00:00
JJ Kasper
42385f48db
Ensure i18n custom routes resolves correctly (#19766)
This ensures i81n custom routes are resolving correctly, it also corrects redirects for default locales when `locale: false` is not used, and this also simplifies the resolving for custom routes with i18n in `next-server` adding types for the i18n config. This also adds additional tests to prevent regression and starts leveraging a shared `NextConfig` type to allow us to share types for config values. 

Fixes: https://github.com/vercel/next.js/issues/19521
Fixes: https://github.com/vercel/next.js/issues/19403
Fixes: https://github.com/vercel/next.js/issues/19302
Fixes: https://github.com/vercel/next.js/issues/19227
2020-12-04 10:14:55 +00:00
Prateek Bhatnagar
57e156bc49
Making font optimization as default (#19758)
- Making font optimizations as default
- Re-enabling tests
- Fixes #19159
2020-12-04 09:52:54 +00:00
Jeff Escalante
b86a1731e1
Error Message Clarity (#16052)
* make the error message more clear if webpack config comes back undefined

* Update check and add test

* bump

* Update build-output test

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2020-12-01 15:58:52 -06:00
Janicklas Ralph
c8cd77a856
Script loader component (#18281) 2020-12-01 19:10:16 +01:00
Janicklas Ralph
6e4632efe1
Css optimizations (#16539)
Co-authored-by: JJ Kasper <jj@jjsweb.site>
2020-12-01 19:02:07 +01:00
Guy Bedford
9dd5ff2baa
fix: Revert #18921 and inline absolute babel runtime only for YarnPnp (#19542)
This reverts #18921 and ensures that the Babel runtime is only inlined as an absolute path when using PnP as before, but then including the correction this resolution as implemented by @merceyz only in the PnP cases, while keeping the diff to a minimum.
2020-11-25 22:28:39 +00:00
JJ Kasper
899a29cade
Break up the serverless loader into typed handlers (#19511)
This breaks up the `serverless-loader` into typed handlers to allow for easier maintenance and better type-checking/linting. 

Closes: https://github.com/vercel/next.js/issues/19071
2020-11-25 19:56:18 +00:00
JJ Kasper
8193df5309
Fix serverless with next start error case (#19288)
This fixes the case where we were returning page data when rendering `/_error` in `serverless` mode with `next start`

Closes: https://github.com/vercel/next.js/issues/19068
2020-11-19 16:25:54 +00:00
Joe Haddad
30c2dfdc47
Remove old modern mode experiment (#19275)
This PR removes the modern mode experiment because:

- It does not yield meaningful bundle size wins when compared to other initiatives we've taken
- It's not compatible with webpack 5 (which we're upgrading to)
- It's currently broken and causes most apps to malfunction
- There's no champion currently owning the experiment

We can re-introduce this in the future when we'd like to make it a default for all Next.js apps.

Note: **Next.js still supports Differential Loading (`nomodule`) and does it by default.** This PR strictly removes the experimental modern _syntax_, and does not disable our existing modern/legacy polyfilling.

---

Fixes #19200
Fixes #18960
Fixes #14707
Fixes #14465
2020-11-18 18:30:00 +00:00
Joe Haddad
61c3db7368
Fix minifying inline CSS comments (#19167)
We accidentally regressed back in 9.5 and dropped support for inline CSS comments. PostCSS always parses these as pass-through (and not a syntax error), which can cause problems when minifying.

Browsers do a similar thing and ignore the comments.

To ensure we generate valid CSS, this adds support for stripping the CSS comments from the build.

--- 

Fixes #15589
Closes #17130
2020-11-14 15:03:04 +00:00
JJ Kasper
1e61b69e31
Add locale: false for custom-routes + i18n (#19164)
This mirrors the `basePath: false` behavior for custom-routes with `locale: false` to allow users to configure the locales manually (`locale: false`) or have the locales be handled automatically for custom-routes. 

Fixes: https://github.com/vercel/next.js/issues/18927
Fixes: https://github.com/vercel/next.js/issues/18795
2020-11-14 03:35:42 +00:00
Joe Haddad
415d7fd75e
Respect next/babel user provided runtime option (#19136) 2020-11-13 02:41:54 -05:00
JJ Kasper
4866c47d9d
Ensure optional catchall prerendered indexes and i18n (#19116)
This ensures root optional-catch-all index routes with i18n are output to the correct location and are also loaded from the `prerender-manifest` correctly. 

Fixes: https://github.com/vercel/next.js/issues/19095
2020-11-12 18:50:32 +00:00
JJ Kasper
54b70425ab
Ensure i18n with basePath works properly (#19083) 2020-11-12 00:26:48 -05:00
JJ Kasper
41866a135c
Add experimental Next.js plugin version locking (#19084) 2020-11-11 23:59:57 -05:00
JJ Kasper
d1036539d6
Ensure params and locale are parsed correctly in fallback mode (#19063)
This fixes a few things related to optional catch-all routes and i18n. The first thing is it ensures the correct data route is generated on the client so that the locale isn't duplicated for an optional catch-all route, the next is it ensures the browser history is updated correctly when only a locale change is occurring, and then it also ensures we handle the locales and normalizing for fallback optional catch-all pages correctly.

Tests have been added to ensure these cases are covered properly and we don't regress on them, these changes were also tested on Vercel [here](https://next-js-bug-i18n-root-params-nybg44l0b.vercel.app/)

Fixes: https://github.com/vercel/next.js/issues/18633 
Fixes: https://github.com/vercel/next.js/issues/19059
2020-11-11 20:33:44 +00:00
Steven
917d594ca8
Print error during next export with default image loader (#19032)
Fixes #18356
2020-11-11 15:46:48 +00:00
Kristoffer K
d40d7d6562
fix(next): resolve absolute path to @babel/runtime (#18921)
**What's the problem this PR addresses?**

https://github.com/vercel/next.js/pull/18768 started to ncc `@babel/plugin-transform-runtime` which broke its Yarn PnP support since the version of `resolve` it uses can't be patched by Yarn.

Fixes https://github.com/yarnpkg/berry/runs/1359235077?check_suite_focus=true#step:5:79

cc @guybedford

**How did you fix it?**

Resolve the absolute path to `@babel/runtime` so it doesn't have to go through `resolve`

---

Fixes https://github.com/vercel/next.js/issues/19026
2020-11-11 15:18:33 +00:00
JJ Kasper
48acc479f3
Ensure basePath behavior with GS(S)P redirect (#18988)
This ensures we match the `basePath` handling for redirects in `next.config.js` with redirects from `getStaticProps` and `getServerSideProps` and also adds a separate test suite to ensure GS(S)P redirects with `basePath` work correctly

Fixes: https://github.com/vercel/next.js/issues/18984
Closes: https://github.com/vercel/next.js/pull/18892
2020-11-11 07:13:18 +00:00
JJ Kasper
a429a47fe0
Ensure correct defaultLocale is provided for locale domain (#19040)
This ensures we use the `defaultLocale` for a locale domain when rendering non-static pages. Static pages will initially contain the global `defaultLocale` and then be updated on the client since we don't currently prerender a version of the pages for each locale domain. 

Closes: https://github.com/vercel/next.js/issues/18970
2020-11-11 02:09:45 +00:00
Lyderic Dutillieux
50400f7eeb
Fixed wrong function name in error message (#19034)
Changed function name from "getStaticProps" to "getStaticPaths" in Exception message thrown when 'paths' is invalid.
2020-11-10 23:53:08 +00:00
Guy Bedford
8221c180a5
ncc 0.25.0 upgrade and fixes (#18873)
This upgrades to ncc@0.25.0 and fixes the previous bugs including:

* ncc not referenced correctly in build
* Babel type errors
* node-fetch, etag, chalk and raw-body dependencies not building with ncc - these have been "un-ncc'd" for now. As they are relatively small dependencies, this doesn't seem too much of an issue and we can follow up in the tracking ncc issue at https://github.com/vercel/ncc/issues/612.
* `yarn dev` issues

Took a lot of bisecting, but the overall diff isn't too bad here in the end.
2020-11-06 02:33:14 +00:00
Guy Bedford
4dbb65d0f1
yarn dev regression fix, ncc revert (#18861)
This fixes the current regression with an ncc revert for now.

I will continue to follow up with the ncc upgrade in https://github.com/vercel/next.js/pull/18860.
2020-11-06 00:47:31 +00:00
Guy Bedford
64850a8348
ncc Babel inlining (#18768)
This adds inlining for Babel and the Babel plugins used in next.

This is based to the PR at https://github.com/vercel/next.js/pull/18823.

The approach is to make one large bundle and then separate out the individual packages from that in order to avoid duplications.

In the first attempt the Babel bundle size was 10MB... using "resolutions" in the Yarn workspace to reduce the duplicated packages this was brought down to a 2.8MB bundle for Babel and all the used plugins which is exactly the expected file size here.

This will thus add a 2.8MB download size to the next package, but save downloading any babel dependencies separately, removing a large number of package dependencies from the overall install.
2020-11-05 14:23:01 +00:00
JJ Kasper
a5cb28d907
Ensure redirects are handled properly from cache (#18806)
This updates the GS(S)P redirect handling to make sure to handle redirects correctly when coming from the incremental-cache. Additional tests have been added to ensure the redirects work correctly after the cache is populated. 

Fixes: https://github.com/vercel/next.js/issues/18735
Fixes: https://github.com/vercel/next.js/issues/18783
2020-11-04 22:18:44 +00:00
Guy Bedford
a1ea352911
Remove @babel/preset-modules (#18759)
This is a prerequisite to being able to ncc inline the Babel dependencies in next.js.

The removal of preset-modules is based on replacing it with preset-env under `targets: { esmodules: true }`, as per the guidance from the package (https://www.npmjs.com/package/@babel/preset-modules):

> Starting from @babel/preset-env 7.9.0, you can enable the bugfixes: true option to get the same behavior as using @babel/preset-modules, but with support for custom targets. If you need to target browsers with native modules support (like this preset does), you can use targets: { esmodules: true }.

From the above, I'm pretty sure this is entirely a backwards compatible change, apart from the change to the runtime plugin list being visible. Perhaps @developit can confirm this as well.
2020-11-04 06:53:39 +00:00
JJ Kasper
7b6a61a750
Ensure correct locale is used for non-prefixed path (#18708)
When visiting a non-locale prefixed path (`/hello` instead of `/fr/hello`) we don't trigger locale redirects currently so if another locale is matched we need to ensure this is reset to the `defaultLocale` for rendering to prevent a mis-match on the client and the server.

This also fixes hydration errors from occurring with `asPath` for `getServerSideProps` pages due to `normalizeLocalePath` expecting only a pathname and `asPath` containing `hash` and `query values also. 

Fixes: https://github.com/vercel/next.js/issues/18337
Fixes: https://github.com/vercel/next.js/issues/18510
2020-11-02 23:00:41 +00:00
JJ Kasper
a8d8f9aef9
Ensure localeDetection: false doesn't detect from header (#18695)
This ensures we don't detect the locale from the header when `localeDetection` is set to `false`

Fixes: https://github.com/vercel/next.js/issues/18482
2020-11-02 21:02:15 +00:00
JJ Kasper
faf4a0ab80
Ensure getStaticProps isn't called without params with i18n (#18702)
This corrects additional fallback pages being generated without the fallback flag causing `getStaticProps` to be called without params with i18n. The revalidation aspect of the issue has been corrected separately in https://github.com/vercel/next.js/pull/18569

Fixes: https://github.com/vercel/next.js/issues/18404
2020-11-02 20:41:34 +00:00
Carmelo Scandaliato
197d46ddb9
Remove the static optimization indicator (#18629)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2020-11-02 09:27:36 +01:00
JJ Kasper
fb07e95847
Ensure correct params are used with i18n revalidation (#18569)
This makes sure we don't use invalid `x-now-route-matches` which can occur when `i18n` default locale is visited and a prerendered page is matched. To correct this we first check if we are able to derive the correct params from the URL and then bail on parsing `x-now-route-matches` if we are. Additional test cases are being added in the builder to ensure we don't regress on this

x-ref: https://github.com/vercel/next.js/discussions/18443
Fixes #18602
2020-11-01 04:49:48 +00:00
JJ Kasper
4263318836
Ensure i18n context values are provided for blocking 404 (#18513)
This ensures we provide the current `locale`, `locales`, and `defaultLocale` in the context when rendering the 404 for a blocking SSG page

Fixes: https://github.com/vercel/next.js/issues/18505
2020-10-30 01:42:28 +00:00
Joe Haddad
9a13dd3466
Enable i18n feature flag (#18303) 2020-10-27 10:30:34 -05:00
JJ Kasper
0f25051470
Ensure getStaticProps is called for SSG 404 in blocking mode (#18300)
This ensures that when using a `pages/404` file with `getStaticProps` that we call `getStaticProps` in `fallback: 'blocking'` mode

Fixes: https://github.com/vercel/next.js/issues/18293
2020-10-27 15:11:51 +00:00
JJ Kasper
26c438b49d
Record leveraged configs (#18175)
This records new configs being leveraged
2020-10-27 13:46:18 +00:00
Steven
f773a1a44a
Rename iconSizes to imageSizes, remove size limitation (#18294)
This does two things:

- Rename `iconSizes` to `imageSizes`.
- Give priority to `imageSizes` regardless of `deviceSizes` as a means to opt-out of the srcset behavior.
2020-10-27 13:19:23 +00:00
JJ Kasper
379f4c6574
Expose configured default locale in GS(S)P methods (#18216) 2020-10-27 05:43:15 -04:00
JJ Kasper
7cb68f7981
Re-add domain locale redirect handling (#18274) 2020-10-27 04:45:39 -04:00
JJ Kasper
4782bda3e3
Add support for notFound in getServerSideProps (#18241)
This is a follow-up to https://github.com/vercel/next.js/pull/17755 which adds support for returning `notFound` to `getServerSideProps` also
2020-10-27 05:42:12 +00:00
JJ Kasper
5a8398e34d
Remove unstable_ prefix from unstable_blocking (#18276)
This removes the `unstable_` prefix to prepare for stabilizing the feature
2020-10-27 04:01:37 +00:00
Joe Haddad
31a011d6a5
Adjust configuration option placement (#18279) 2020-10-27 03:36:31 +00:00
Steven
3a169fbbf0
Separate config into deviceSizes and iconSizes (#18267)
This separates the `next.config.js` property `images.sizes` into to properties: `images.deviceSizes` and `images.iconSizes`.

The purpose is for images that are not intended to take up the majority of the viewport.


Related to #18122
2020-10-26 20:07:52 +00:00
JJ Kasper
9c65c994cc
Add next/image default loader errors (#18152)
* Add next/image default loader errors

* Add domains check

* Apply suggestions from PR

* Update test
2020-10-25 00:22:47 -05:00
JJ Kasper
81e667bfae
Update fallback 404 handling to prevent reload loop (#18119)
This updates the fallback 404 handling to render the correct 404 page on the client when a 404 is returned from fetching the data route on a fallback page on the client. This prevents us from having to rely on a cache to be updated by the time we reload the page to prevent non-stop reloading. 

This also adds handling in serverless mode to ensure the correct 404 page is rendered when leveraging fallback: 'blocking' mode. 

Additional tests for the fallback: 'blocking' 404 handling will be added in a follow-up where returning notFound from `getServerSideProps` is also added.
2020-10-22 14:54:38 +00:00
Steven
3f07e554f4
Fix Image component defaults & remove autoOptimize (#18101) 2020-10-21 21:39:12 +02:00
Ludovico Fischer
b89d417b37
Update to PostCSS 8. (#17415)
Co-authored-by: Tim Neutkens <timneutkens@me.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2020-10-21 12:31:07 +02:00
JJ Kasper
2ab34451b7
Pass locales to getStaticPaths for i18n (#18077)
This makes sure the `locales` are passed to `getStaticPaths` and also disables the removing the default locale from the path when the default locale is the preferred header. It also updates tests to ensure the domain redirects are working as expected.  

x-ref: https://github.com/vercel/next.js/pull/17370
2020-10-21 09:35:01 +00:00
JJ Kasper
4d85d4985b
Ensure root index GSP page's revalidate is recorded (#18053) 2020-10-20 18:49:25 +02:00
Steven
0fb39e2347
Add width and height props to Image component (#18031)
Co-authored-by: Tim Neutkens <timneutkens@me.com>
2020-10-20 18:43:24 +02:00
Alex Castle
01e6bd1684
Remove multi-host support for image component and support quality pass-through (#18038)
Co-authored-by: Tim Neutkens <timneutkens@me.com>
2020-10-20 16:28:01 +02:00
JJ Kasper
8be3562c48
Ensure correct default locale is detected for domain locale (#18046)
This makes sure that we detect the correct default locale for domain specific locales since a domain can have a different default locale residing at the root and we need to check this on the client for prerendered/auto-static pages. This also makes sure we disable the built-in redirect handling when on Vercel since it's handled already. 

Tests for this are tricky since we need to load the browser with a custom domain which requires editing the host file. Existing tests should ensure this doesn't break non-domain specific locale behavior though. This was also tested manually while testing https://github.com/vercel/vercel/pull/5298



x-ref: https://github.com/vercel/next.js/pull/17370
2020-10-20 10:23:11 +00:00
Ludovico Fischer
0d3671c2c2
Update to postcss-loader 4.0.2. (#17458)
Co-authored-by: Tim Neutkens <timneutkens@me.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2020-10-19 17:07:59 +02:00
Joe Haddad
0fe5b23b0e
Add perf data experiment (#17956) 2020-10-16 16:31:09 -04:00
Tim Neutkens
dfcf26732a
Only load plugins with @next prefix (#17945) 2020-10-16 18:38:36 +02:00
Steven
d3741d5ec5
Add support for Image Optimizer (#17749)
Co-authored-by: JJ Kasper <jj@jjsweb.site>
2020-10-16 13:10:01 +02:00
JJ Kasper
f0ead09421
Fix initialRevalidateSeconds manifest field with i18n (#17926)
This makes sure the correct `initialRevalidateSeconds` field is populated in the `prerender-manifest` for non-dynamic SSG pages since they will be inserted into the `initialPageRevalidationMap` under their locale prefixed variant with `i18n` enabled

x-ref: https://github.com/vercel/next.js/pull/17370
2020-10-16 09:27:34 +00:00
JJ Kasper
4b126cc336
Ensure i18n support with AMP (#17923)
* Ensure i18n support with AMP

* Fix type error

* Update size-limit
2020-10-15 18:00:08 -05:00
JJ Kasper
2a94ae037a
Add support for returning 404 from getStaticProps (#17755) 2020-10-15 23:55:38 +02:00
JJ Kasper
acd44c5b38
Add i18n items to routes manifest (#17893)
This adds the i18n config items to the routes-manifest so that they can accessed in the builder. This doesn't increment the routes-manifest version as existing value shapes haven't been modified and an additional non-breaking value is being added

x-ref: https://github.com/vercel/next.js/pull/17370
2020-10-15 18:21:30 +00:00
JJ Kasper
e554a1fbb9
Add locale prop for transitioning locales client side (#17898)
This adds the `locale` prop for `next/link` to allow transitioning between locales client-side and also allows passing the locale to `router.push/replace` via the transition options similar to `shallow` e.g. `router.push('/another', '/another, { locale: 'nl' })`

x-ref: https://github.com/vercel/next.js/pull/17370
2020-10-15 08:58:26 +00:00
JJ Kasper
245499a05a
Handle preferring default locale over accept-lang preferred locale (#17883)
This updates to set the `NEXT_LOCALE` cookie to the default locale when the user prefers a different locale from the default in their `accept-language` header but visits the default locale path e.g. `/en-US` with a `accept-language` preferred header of `nl` will set the `NEXT_LOCALE=en-US` header and then redirect to `/`

x-ref: https://github.com/vercel/next.js/pull/17370
2020-10-14 21:02:38 +00:00
Tommaso De Rossi
5c4d0bded6
Resolve to real path before checking for path inequality (#17279)
Co-authored-by: Luis Alvarez D <luis@vercel.com>
Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
2020-10-14 13:36:59 +02:00
Simone Corsi
fad07cc09a
chore(collect-plugins.ts): removes duplicated entries (#17441) 2020-10-14 11:57:35 +02:00
Alex Castle
87175fe9df
Image component foundation (#17343)
Co-authored-by: Tim Neutkens <timneutkens@me.com>
Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
2020-10-14 11:57:10 +02:00
JJ Kasper
9a5a1525bc
Update redirect handling for locale domains (#17856)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2020-10-14 11:56:58 +02:00
Jan Potoms
9300151118
Allow pages to be async modules to enable top-level-await (#17590)
Co-authored-by: JJ Kasper <jj@jjsweb.site>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2020-10-14 11:55:42 +02:00
Prateek Bhatnagar
71d798ce88
Font optimization for webpack 5 (#17450)
Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
Co-authored-by: Tim Neutkens <timneutkens@me.com>
2020-10-12 20:58:09 +02:00
JJ Kasper
1eeac4f99b
Make sure locale detecting is case-insensitive (#17757)
Follow-up to https://github.com/vercel/next.js/pull/17370 this makes sure the locale detection is case-insensitive.
2020-10-11 20:40:47 +00:00
JJ Kasper
5cab03fef0
Add handling for domain to locale mapping (#17771)
Follow-up to https://github.com/vercel/next.js/pull/17370 this adds mapping of locales to domains and handles default locales for specific domains also allowing specifying which locales can be visited for each domain. 

This PR also updates to output all statically generated pages under the locale prefix to make it easier to locate/lookup and to not redirect to the default locale prefixed path when no `accept-language` header is provided.
2020-10-10 10:22:45 +00:00
JJ Kasper
2170dfd1e3
Update to generate auto static pages with all locales (#17730)
Follow-up PR to #17370 this adds generating auto-export, non-dynamic SSG, and fallback pages with all locales. Dynamic SSG pages still control which locales the pages are generated with using `getStaticPaths`. To further control which locales non-dynamic SSG pages will be prerendered with a follow-up PR adding handling for 404 behavior from `getStaticProps` will be needed. 

x-ref: https://github.com/vercel/next.js/issues/17110
2020-10-09 09:13:05 +00:00
JJ Kasper
ec2ffb4244
Handle css-loader file resolving change (#17724)
This is a follow-up to https://github.com/vercel/next.js/pull/16973 which adds handling for the breaking change in the latest version of css-loader that causes unresolved file references in `url` or `import` to cause the build to fail. This fixes it by adding our own resolve checking and when it fails disabling the `css-loader`'s handling of it. 

Fixes: https://github.com/vercel/next.js/issues/17701
2020-10-08 18:45:39 +00:00
JJ Kasper
bbc1a21c74
Update to have default locale matched on root (#17669)
Follow-up PR to https://github.com/vercel/next.js/pull/17370 when the path is not prefixed with a locale and the default locale is the detected locale it doesn't redirect to locale prefixed variant. If the default locale path is visited and the default locale is visited this also redirects to the root removing the un-necessary locale in the URL. 

This also exposes the `defaultLocale` on the router since the RFC mentions `Setting a defaultLocale is required in every i18n library so it'd be useful for Next.js to provide it to the application.` although doesn't explicitly spec where we want to expose it. If we want to expose it differently this can be updated.
2020-10-08 11:12:17 +00:00
JJ Kasper
b2d1d87e7f
Add initial changes for i18n support (#17370)
This adds the initial changes outlined in the [i18n routing RFC](https://github.com/vercel/next.js/discussions/17078). This currently treats the locale prefix on routes similar to how the basePath is treated in that the config doesn't require any changes to your pages directory and is automatically stripped/added based on the detected locale that should be used. 

Currently redirecting occurs on the `/` route if a locale is detected regardless of if an optional catch-all route would match the `/` route or not we may want to investigate whether we want to disable this redirection automatically if an `/index.js` file isn't present at root of the pages directory. 

TODO: 

- [x] ensure locale detection/populating works in serverless mode correctly
- [x] add tests for locale handling in different modes, fallback/getStaticProps/getServerSideProps

To be continued in fall-up PRs

- [ ] add tests for revalidate, auto-export, basePath + i18n
- [ ] add mapping of domains with locales
- [ ] investigate detecting locale against non-index routes and populating the locale in a cookie

x-ref: https://github.com/vercel/next.js/issues/17110
2020-10-07 21:11:01 +00:00
JJ Kasper
b42be17593
Normalize optional catch-all fallback: true page params (#17551)
This makes sure to normalize the params for optional catch-all routes on Vercel since for `fallback: true` pages the `[[...paramName]]` value will be provided for the undefined/root param which needs to be normalized. 

Tests have been added in https://github.com/vercel/vercel/pull/5247 and were manually tested with the changes in this PR with https://github.com/ijjk/next-update-loader

Fixes: https://github.com/vercel/next.js/issues/17220
x-ref: https://github.com/vercel/vercel/pull/5247
2020-10-05 07:34:50 +00:00
JJ Kasper
f7f376f91e
Ensure optional-chaining/nullish coalescing is included (#17429) 2020-09-28 16:47:05 -07:00
JJ Kasper
ad22e77309
Expose dotenv loading under separate package (#17152)
* Expose dotenv loading under separate package

* Update pre-compiled

* Rename package to @next/env

* Update lint ignores

* Update package.json

Co-authored-by: Joe Haddad <joe.haddad@zeit.co>
2020-09-25 13:14:28 -05:00
JJ Kasper
2cf1d1c191
Separate resolved asPath from resolved URL for GSSP (#17121)
This makes sure we have the correct `asPath` value to prevent breaking hydration for `getServerSideProps` pages and doesn't re-use the `resolvedUrl` value for the `asPath` and instead creates a separate `resolvedAsPath` value that only removes the `_next/data` prefix from the path. Additional tests have been added in the `getServerSideProps` suite to ensure correct `asPath` with rewrites. 

Fixes: https://github.com/vercel/next.js/issues/17113
2020-09-15 19:19:07 +00:00
JJ Kasper
a4c97c5c4a
Update webpack 5 resolving (#17095)
On the latest beta of webpack 5 resolving fails with the below error and according to https://github.com/webpack/webpack/issues/11467 is due to the imports in this module not being fully specified. This adds the config mentioned in the thread to correct the resolving for this module. 

```sh
Failed to compile.
--
16:33:50.046 | ModuleNotFoundError: Module not found: Error: Can't resolve './assertThisInitialized' in '/vercel/f03cc85/node_modules/@babel/runtime/helpers/esm'
16:33:50.046 | > Build error occurred
16:33:50.047 | Error: > Build failed because of webpack errors
16:33:50.047 | at build (/vercel/f03cc85/node_modules/next/dist/build/index.js:15:918)
16:33:50.099 | error Command failed with exit code 1.
```
2020-09-15 03:27:43 +00:00
JJ Kasper
62cbbf525c
Fix API page check during SSG page collecting (#17092)
Fixes SSG pages that start with `/api` not being detected as SSG pages. This also adds tests to ensure this is working correctly in the `prerender` suite.

x-ref: https://github.com/vercel/next.js/issues/17091
2020-09-15 01:03:43 +00:00
JJ Kasper
d3f4a4cb2a
Provide resolvedUrl to getServerSideProps (#17082)
This continues off of https://github.com/vercel/next.js/pull/17081 and provides this normalized `asPath` value in the context provided to `getServerSideProps` to provide the consistent value since the request URL can vary between direct visit and client transition and the alternative requires building the URL each time manually. 

Kept this change separate from https://github.com/vercel/next.js/pull/17081 since this is addressing a separate issue and allows discussion separately. 

Closes: https://github.com/vercel/next.js/issues/16407
2020-09-14 21:01:04 +00:00
JJ Kasper
94a5bd6109
Normalize asPath for GS(S)P pages (#17081)
This normalizes the `asPath` for `getServerSideProps` and `getStaticProps` pages to ensure it matches the value that would show on the client instead of a) the output pathname when revalidating or generating a fallback or b) the `_next/data` URL on client transition. 

Fixes: https://github.com/vercel/next.js/issues/16542
2020-09-14 16:48:04 +00:00
Jens Meindertsma
80000f4238
[Fix] webpack@5.0.0-beta.30: Invalid configuration (#17045)
Earlier today #17038 was merged which I opened to fix a problem when using `webpack@5.0.0-beta.30` with Next.js using the new Webpack 5 support. In that PR, the only change was the renaming of a configuration key. I later discovered that the change on the Webpack side was different than I initially thought, and this meant that the fix I submittted to Next.js didn't work.

This PR intends to fix the remaining problems. Webpack 5 now accepts a `environment` key that can be used to configure the target output. Previously, this was known as `ecmaVersion` and accepted a number. Now, `environment` accepts a configuration object with individual options. I've configured this in such a way where it resembles an ES5 environment:
```js
environment: {
   arrowFunction: false,
   bigIntLiteral: false,
   const: false,
   destructuring: false,
   dynamicImport: false,
   forOf: false,
   module: false,
}
```
2020-09-14 13:21:17 +00:00
Bogdan Chadkin
9959d7ef32
Use babel 7 jsx syntax (#17043)
For some reason babel-plugin-syntax-jsx of babel 6 was used instead of
babel 7 version.
2020-09-13 13:29:23 +00:00
Jens Meindertsma
4af5032e77
Fix Webpack 5 configuration for v5.0.0-beta.30 (#17038)
This PR fixes #17035. As described in the issue, there was a breaking change in `webpack@5.0.0-beta.30`: `output.ecmaVersion` was replaced by `output.environment`. This meant Next.js apps using this `webpack` version would break. This PR updates the relevant Webpack config.

I think this will break any apps that are still using `webpack@5.0.0-beta.29`, but I don't know whether that is a problem as this is a beta feature. If it is, I'd love it if someone could let me know how to detect beta versions in the code so I can make it backwards-compatible.
2020-09-12 13:23:55 +00:00
Bogdan Chadkin
ddf9ed3b62
Prefer builtin optional chaining and nullish coalescing (#16780)
Babel-preset-env includes includes optional chaining and
nullish-coalescing since [7.8.0](https://github.com/babel/babel/releases/tag/v7.8.0).

In this diff I removed these plugins from next preset to prevent
dependency duplication when their newer versions are out.
2020-09-11 15:20:10 +00:00
Bogdan Chadkin
e5f9fbbcdf
Upgrade sass loader (#16970)
The new version replaced big clone-deep package with dependency-free klona
- https://github.com/webpack-contrib/sass-loader/releases/tag/v10.0.0
- https://github.com/webpack-contrib/sass-loader/releases/tag/v9.0.0

Also deduped some related transitives.
2020-09-11 12:36:48 +00:00
Joe Haddad
1ea6745106
Importing CSS from Third Party React Components (#16993) 2020-09-10 13:45:30 -04:00
Joe Haddad
25cdaab297
Add Support for CSS Module Value Imports (#16973)
Fixes #10142
Fixes #11629
2020-09-09 23:29:37 +00:00
JJ Kasper
d97237a292
Fix invalid config export errors (#16834)
This corrects detecting of invalid page config exports and adds additional test cases for non-invalid config import/exports

Closes: https://github.com/vercel/next.js/issues/16775
2020-09-04 13:19:12 +00:00
JJ Kasper
4685332353
Add automatic reloading when editing GS(S)P methods (#16744)
This adds initial support for reloading the page when `getStaticProps`, `getStaticPaths`, or `getServerSideProps` were changed for a page by triggering a reload when the server output for a page has changed but the client output has not since these methods aren't included in the client output. 

Closes: https://github.com/vercel/next.js/issues/13949
2020-09-02 16:57:21 +00:00
Joe Haddad
f921b4f476
Auto enable React's new JSX transform on 17.x (#16603) 2020-09-01 11:29:25 -04:00
Tim Neutkens
ed0820f763
Enable webpack 5 caching by default (#16531)
When the webpack 5 beta is used disk caching will be automatically enabled to improve incremental build performance.
2020-08-24 22:37:52 +00:00
khades
1a7f3e5199
Store css file dependencies info for dynamic imports and apply it at SSR (#12843)
To prevent FOUC, discussed in #10557 i need to store information about css file dependencies for chunk. Right now current implementation just throws away everything but js.

Can there be more than one css file in chunk? If no - code will be simplified.

closes #10557
2020-08-24 05:20:11 +00:00
Luis Alvarez D
735aab6f03
Update Fast Refresh warning (#16496)
Fixes https://github.com/vercel/next.js/issues/16495

Terminal:

![image](https://user-images.githubusercontent.com/4278345/90984442-96421b00-e53a-11ea-9939-44b00cba87cf.png)

Browser: 

![image](https://user-images.githubusercontent.com/4278345/90984456-a9ed8180-e53a-11ea-86da-d9f28e9c2fdd.png)

The link https://nextjs.link/codemod-ndc used for the warning links to a currently 404 docs page, that will be available in the next stable release.

Tests not added as the warning has tests already.
2020-08-24 03:04:25 +00:00
Tim Neutkens
f2ba97d866
Add webpack 5 cache invalidation (#16494)
Handles:

- Next.js version
- next.config.js `env` key
- `NEXT_PUBLIC_` prefixed environment variables
- next.config.js keys that affect performance

Ideally we don't invalidate the whole cache when `NEXT_PUBLIC_` / `env` key variables change, but this is just to initially make the caching reliable, this behavior is similar to the current webpack 4 behavior, so it can only be improved 👍
2020-08-24 01:37:48 +00:00
JJ Kasper
4e0b40145d
Correct initial fallback route param values (#16485)
This fixes invalid initial route params in development mode and serverless production mode. It also adds tests to ensure these values are correct in development, production, and serverless mode.

x-ref: https://github.com/vercel/next.js/pull/16084
Fixes: https://github.com/vercel/next.js/issues/16481
Fixes: https://github.com/vercel/next.js/issues/16482
2020-08-23 12:35:30 +00:00
Tim Neutkens
d0754993fc
Add webpack 5 caching for css optimizer (#16467) 2020-08-22 14:16:13 +02:00
JJ Kasper
78ef13914a
Fix un-transpiled client file with rewrites (#16453)
This fixes a client-side file not being transpiled correctly when rewrites are used. The cross browser tests have been updated to make sure there are rewrites so the related code is included and not dead-code eliminated'

Closes: https://github.com/vercel/next.js/issues/16440
2020-08-21 19:11:25 +00:00
Joe Haddad
7c7ecaa636
Do not alias Node modules for webpack 4 (#16452)
Fixes #16259
Caused by #16022
Follow up issue: #16450

This PR skips polyfilling Node modules in webpack 4 which are ignored by the `browsers` key.
2020-08-21 18:50:24 +00:00
JJ Kasper
450742274a
Fix optional catch-all /index revalidate params (#16451)
This corrects the case where `/index` is used during revalidation for an optional catch-all route and `index` is passed as a param even though it should be undefined. This also adds test cases to make sure the params are normalized correctly

Fixes: https://github.com/vercel/next.js/issues/16366
2020-08-21 18:13:24 +00:00
Tim Neutkens
b6a2051d49
Solve last mini-css-plugin webpack 5 warning (#16447)
Adds missing context parameter
2020-08-21 15:33:57 +00:00
Prateek Bhatnagar
6c9dd6c3d4
AMP compatibility for Font optimization (#16208)
- Upgrades cssnano to 1.2.0
- Only removes whitespaces from downloaded font declarations
- Disables Font optimization for AMP pages
2020-08-20 15:10:59 -04:00