Commit graph

420 commits

Author SHA1 Message Date
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
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
JJ Kasper
3f94f33ba2
Ensure error is passed up in minimal mode (#22030)
This ensures we pass the error up to the top-level when in minimal mode
2021-02-11 09:31:49 +00:00
JJ Kasper
a65f8c3e0e
Update stats flag default (#21791) 2021-02-02 21:38:50 +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
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
Roko Bekavac
004ad62d6b
Allow undefined body sent to sendData() (#20981)
Co-authored-by: rokobekavac0 <roko.beakavac2003@gmail.com>
Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
Co-authored-by: Joe Haddad <joe.haddad@zeit.co>
2021-01-26 10:24:48 -05:00
Andre Hsu
a47d47e07a
Change type of GetServerSidePropsContext.req.cookies the be the same as NextApiRequest.cookies (#21336)
The original type for `GetServerSidePropsContext.req.cookies` was introduced in #19724. In the PR, the test at `test/integration/typescript/test/index.test.js` expects req.cookies to always exist, so `req.cookies` will never be undefined.

I'm guessing that req.cookies is parsed using the same cookie middleware as `NextApiRequest`, in which case `req.cookies` should be `{ [key: string]: string }`, not `{ [key: string]: any }`.
2021-01-26 14:26:59 +00:00
tarunama
c110e45b62
refactor: server/api-utils.ts (#21148)
- Add return type to function
- Add [isNotValidData](https://github.com/vercel/next.js/pull/21148/files#diff-64466461287cc1a70ce5597e3e1d18ac22755f9aeb7ff1865160a8c057540983R374) function for readability
2021-01-26 09:52:00 +00:00
kaykdm
47cb4cf850
Fix aspath for getInitialProps (#20572)
Fixes: https://github.com/vercel/next.js/issues/20370

> AsPath is incorrect on Server if you use rewrites and getInitialProps. On the server, asPath is the rewritten asPath while on the client asPath ist as given in the request URL.

The same issue was used to happen on `getServersideProps`, but it was fixed in this PR (https://github.com/vercel/next.js/pull/17121).
`getInitialProps` needs same fix except when the target is serverless, which has correct `asPath` value.

Additional tests have been added in the `getInitialProps` suite to ensure correct asPath with rewrites.
2021-01-25 18:26:32 +00: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
Tim Neutkens
56b149f7be
Add experimental per-page option to disable JS preloads (#21329)
As discussed with @csswizardry. This is a temporary option in case you know the preloads are not needed. It will likely be a default once the ScriptLoader work from @janicklas-ralph has been proven in partner apps and landed.

```js
// pages/index.js
export const config = {
  unstable_JsPreload: false
}
```
2021-01-19 19:38:15 +00:00
Bernd Artmüller
72ce099106
Fix splitting page path by buildId (#19901)
Running next.js in `development` causes issues when having pages named "development" or "developments",... as `this.buildId` = `development`

Fixes: https://github.com/vercel/next.js/issues/19520
2021-01-19 18:27:28 +00:00
JJ Kasper
cfa9326c63
Minimal mode normalizing (#21083)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2021-01-16 16:46:21 +01:00
Guy Bedford
bddb02286f
feat: webpack inlining with configuration for v4 / v5 (#20598) 2021-01-13 20:59:08 -05:00
kaykdm
e1184fb060
Fix image cache for vector and animated images (#20480)
Fixes: https://github.com/vercel/next.js/issues/19100
> According to https://nextjs.org/docs/basic-features/image-optimization#caching Next.js populates a cache dir when using the new <Image /> component. This is not the case when using SVG files. This results in a performance penalty.

I created a function for writing images to cache directory (`wrirteToCacheDir`) and it is called for all images.
However, vector and animated images are not optimized before writing them to cache dir

Related to #18179
2021-01-13 18:06:04 +00:00
Ari Freyr Asgeirsson
69ff95f50e
Wrong index path revalidation timer (#20818)
Hello friends

Ran into this bug on our production site, prerenderManifest stores revalidation info for the index as `"/": { .. }`, but the code tries to access this information as `"/index"`.

This leads to our index page always having s-max-age: 1
2021-01-13 16:15:11 +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
JJ Kasper
b9ba264bd6
Ensure i18n + API rewrite is handled correctly (#20751)
This ensures rewrites to API routes with i18n enabled handles as an API route correctly. This also adds tests for API routes in the i18n test suite

Fixes: https://github.com/vercel/next.js/issues/20725
2021-01-06 09:54:45 +00:00
Jan Varho
b944b06f30
Fix notFound false pages returning 404 (#19861)
Currently pages with `notFound: false` from `getServerSideProps` behave the same as `notFound: true`, i.e. just having the key is enough to result in a 404. This fixes the check in render.tsx and adds tests for it.
2021-01-04 22:43:53 +00:00
matamatanot
fc75baeb3c
Move sizes var declaration just before used (#18402)
As with `const width`, it should be declared just before it is used.
2021-01-04 18:09:07 +00:00
Alexander Kachkaev
7076758c8d
Call res.write('') inside apiRes.redirect() helper to prevent an edge case (#20461)
This PR is a small follow-up to #14705. It saves Next.js users from falling into a [pretty nasty trap](https://github.com/nodejs/node/issues/36620) in which I ended up last Friday. It took more than two days to investigate what was going on, so I hope I'm the last person who’s doing it 😅

Next.js-specific MWE: https://github.com/kachkaev/hanging-response-in-next-via-redirect-plus-compression (needs to be ran locally using Node 14.0.0+).

> <img width="521" alt="Screenshot 2020-12-24 at 20 50 00" src="https://user-images.githubusercontent.com/608862/103105989-a9b8dc00-4629-11eb-9be3-5108755604bf.png">

To reproduce the bug I’m fixing:

1. Pick a large http body size (64 or 128 KB)
1. Check _Call res.end() after res.redirect() in /api/redirect_
1. Navigate to a heavy page or an api handler via redirect
1. Observe that the http response is never finished.

If you set `compress` to `false` in `next.config.js` or pick a small payload size (< `zlib.Z_DEFAULT_CHUNK` after compression), the bug will not be observed. This is explained by the use of `res.on("drain", ...)` [by the `compression` package](3fea81d0ea/index.js (L193-L218)). The package itself is not the reason for an issue though, it seems to be in the Node’s built-in `http` package.

I’m happy to provide more info or GitHub CI to the MWE if needed. I was also thinking of adding some Next.js-specific testing, but could not come up with a compact and clear test plan. Happy to do this if there are any ideas.

cc @botv (author of #14705)
2021-01-04 10:14:15 +00:00
JJ Kasper
3a9d18b549
Add isReady field on router (#20628)
Adds an `isReady` field on `next/router` specifying whether the router fields are updated client-side and ready for use. Should only be used inside of `useEffect` methods and not for conditionally rendering on the server.

Closes: https://github.com/vercel/next.js/issues/8259
Closes: https://github.com/vercel/next.js/pull/9370
2020-12-31 16:54:32 +00:00
JJ Kasper
fd33c9f7e1
Ensure href is updated for locale domain (#20631)
This ensures we render the locale domain on the `href` when using `next/link` previously the provided `href` was stilling being rendered which differed from the resulting `href` that was navigated to. 

Fixes: https://github.com/vercel/next.js/issues/20612
2020-12-31 08:07:51 +00: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
JJ Kasper
962535752b
Ensure next/image loads correctly with basePath (#20592)
This ensures the default path used for the `next/image` component includes the `basePath` when configured. Additional tests have also been added to ensure the image component is working correctly with `basePath` configured.

Fixes: https://github.com/vercel/next.js/issues/19711
2020-12-30 01:57:08 +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
JJ Kasper
db329fe9b0
Ensure index rewrite is matched with i18n correctly (#20509)
This makes sure we don't generate the wrong locale source variant for the rewrite requiring a `/` on the end which won't ever be added causing the rewrite to never match. Additional tests have been added to ensure this specific rewrite is working correctly. 


Fixes: https://github.com/vercel/next.js/issues/20508
2020-12-28 18:21:28 +00:00
JJ Kasper
690fc36ccc
Update revalidate checks (#19796)
This ensures we show an error for string values for `revalidate` since we currently don't handle these and instead it results in `revalidate: false` being used. This also adds tests for our `revalidate` checks to ensure they are triggered correctly and not triggered for valid values. 

x-ref: https://github.com/vercel/next.js/issues/20310
2020-12-22 20:15:26 +00:00
JJ Kasper
118588b027
Remove extra redirect for index with i18n (#20397)
This makes sure redirects to the index route properly end with a trailing slash or don't based on the `trailingSlash` config to ensure an additional redirect doesn't need to take place un-necessarily. 

Fixes: https://github.com/vercel/next.js/issues/19405
2020-12-22 17:12:53 +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
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
JJ Kasper
5b89b1b6df
Ensure href resolvedAs is correct with locale (#20080)
This makes sure the `locale` doesn't cause the wrong `href` to be resolved, this also ensures route specificity is correct when loading dynamic routes in production mode. 

Fixes: https://github.com/vercel/next.js/issues/19747
2020-12-12 14:06:46 +00:00
Tim Neutkens
c792317295
Clear up production build missing message for next start and next export (#19777)
Adds an err.sh link to the production build missing message. Also clears up `valid` as `production`.

Also fixes an edge case where an unhelpful error would be thrown because we checked for `.next` instead of `.next/BUILD_ID`

Added the out directory location as the list line during export to make sure people know where the files are output. 

Fixes #19778
Fixes #19788
2020-12-08 15:16:56 +00:00
JJ Kasper
358861d315
Ensure trailingSlash redirect applies correctly for i18n (#19859)
This ensures locales aren't applied for the trailing slash redirect un-necessarily

Fixes: https://github.com/vercel/next.js/issues/19784
2020-12-07 17:36:46 +00:00
Daniel Kempner
90e97b535b
Custom Server with bodyParser, don't parse body again in API Route (#16169)
## Why

Some users prefer to use a custom server implementation that handles body parsing. If they do this, they have no way to opt out of all body parsing in API Routes. Requests with bodies die if next's `bodyParser` is not disabled. Requests just hang forever.

Instead of adding [this config](https://nextjs.org/docs/api-routes/api-middlewares#custom-config) to every API Route, we do a simple check to avoid parsing the body twice.

Fixes #8315
Fixes #7960
2020-12-07 13:30:38 +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
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
JJ Kasper
2790ea411b
Ensure i18n + trailingSlash works for different page types (#19331)
This adds additional test coverage and more handling for i18n + `trailingSlash: true`

Closes: https://github.com/vercel/next.js/issues/19069
2020-11-20 18:45:47 +00:00
JJ Kasper
5959f18431
Ensure non-configured i18n locales 404 (#19338)
This ensures navigations to non-configured locales causes the 404 page to be shown, it also adds tests to ensure direct visits for non-configured locales 404s correctly. 

Fixes: https://github.com/vercel/next.js/issues/19214
2020-11-20 15:07:00 +00:00
JJ Kasper
13aa9d666c
Correct errsh links in config checks (#19280)
This makes sure we're using `next.js` in the err.sh links instead of `nextjs` since that leads to a 404
2020-11-20 13:04:18 +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
JJ Kasper
ca590c4cb9
Ensure i18n + trailingSlash: true handles correctly (#19149)
This ensures redirects are handled properly with i18n + `trailingSlash: true`, additional tests have also been added to ensure this is covered 

Fixes: https://github.com/vercel/next.js/issues/19069
2020-11-17 21:46:46 +00:00
JJ Kasper
a32b1f4870
Enable handling for revalidate and notFound (#19165)
This allows SSG pages that return `notFound` to be revalidated. 

Closes: https://github.com/vercel/next.js/issues/18651
2020-11-14 07:12:47 +00:00