Commit graph

1629 commits

Author SHA1 Message Date
Joe Haddad
c8fa284854
Control <Image /> prefetching with React (#18904)
This pull request fixes `<Image />` not updating when new props are passed by removing external DOM mutations and relying on React to do it instead.

As an added bonus, I've extracted the intersection observer from both the `<Image />` and `<Link />` component, as their instance can be shared!

The increase in size is minor (+3B), and actually a decrease for apps using both `<Image />` and `<Link />`.

---

Fixes #18698
Fixes #18369
2020-11-06 23:03:15 +00:00
Joe Haddad
e9054744d8
Load CSS early instead of only preloading (#18846)
While we were fixing how Next.js handled CSS, we added a complex prefetch, preload, fetch sequence to acquire the CSS asset.

This unnecessarily overcomplicated what could've been only a `fetch()` from the very start!

---

Fixes #16932
2020-11-06 16:24:02 +00:00
JJ Kasper
db0587c4ac
Fix relay-analytics test on Azure (#18875) 2020-11-05 23:19:02 -05:00
JJ Kasper
d23d25f4b7
Fix production test compatibility for ie11 (#18874)
This corrects this test failing from an arrow function being used in ie11 which isn't supported natively

```
 ● Production Usage › Dynamic import › default behavior › should not remove css styles for same css file between page transitions

    JavascriptError: Error executing JavaScript

      at Object.throwDecodedError (../node_modules/selenium-webdriver/lib/error.js:550:15)
      at parseHttpResponse (../node_modules/selenium-webdriver/lib/http.js:565:13)
      at Executor.execute (../node_modules/selenium-webdriver/lib/http.js:491:26)
```
2020-11-06 04:18:19 +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
Joe Haddad
80468ad4c2
Ensure we prefetch on hover (#18859)
* Ensure we prefetch on hover

* double because of hovering prefetch

* rerun workflow

* disable flaky test
2020-11-05 20:12:22 -06: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
JJ Kasper
8799bd2b00
Fix chromedriver set-up to test electron separately (#18854)
* Fix chromedriver set-up to test electron separately

* Update workflow

* Update compiled
2020-11-05 14:45:21 -06:00
Steven
b684b110e4
Add props objectFit and objectPosition to Image component (#18849)
Fixes #18794
2020-11-05 19:42:55 +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
James George
596ee9c19b
tests(create-next-app): remove extraneous helper (#18833)
The helper `runStarter()` is extraneous.
2020-11-05 13:02:19 +00:00
Joe Haddad
bc2282fa38
Speed up SSG prefetching (#18813)
This pull request speeds up Next.js' rendering pipeline by fetching data, parsing it, and loading it into memory instead of only doing the network request.

This will mainly result in improved Firefox/Safari performance since they handled prefetch incorrectly—only Chrome did it right. This also gets us closer to being able to use `no-store` in our caching headers!

---

Fixes #18639
x-ref #18802
2020-11-05 09:51:24 +00:00
James George
5d80e684cd
tests(create-next-app): increase coverage (#18630)
Added a test case for asking for a name for the project if not supplied.
2020-11-05 09:26:23 +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
Steven
b9bf68638b
Disable image optimization for Data URLs (#18804)
This PR disables image optimization and lazy loading for [Data URLs](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs), because the image data is already inlined.

Fixes #18372 
Fixes #18692
2020-11-04 21:14:55 +00:00
Steven
80fd3d5d17
Print error when Image src is protocol-relative (#18809)
This PR prints a pretty error when the Image `src` property is a [protocol-relative URL](https://www.paulirish.com/2010/the-protocol-relative-url/).

> Update 2014.12.17:
> Now that SSL is encouraged for everyone and doesn’t have performance concerns, this technique is now an anti-pattern. If the asset you need is available on SSL, then always use the https:// asset.

Fixes #18536
2020-11-04 20:47:49 +00:00
Joe Haddad
bb8a49ec83
Omit ignored property from <Image/ > to prevent confusion (#18796)
Fixes #18793
2020-11-04 16:13:07 +00:00
Cowboy Ho
28e12876b8
Fix router not working on some protocol (#16650)
Co-authored-by: Tim Neutkens <timneutkens@me.com>
Co-authored-by: Joe Haddad <joe.haddad@zeit.co>
Co-authored-by: JJ Kasper <jj@jjsweb.site>
2020-11-03 16:18:02 -05:00
JJ Kasper
f791577569
Ensure redirect from GS(S)P doesn't render (#18749)
This ensures we don't render the page un-necessarily when a redirect is returned from `getStaticProps` or `getServerSideProps`.

Possibly related: https://github.com/vercel/next.js/issues/18735
Closes: https://github.com/vercel/next.js/issues/18747
2020-11-03 16:40:50 +00:00
khades
b1503e13e8
Fix dynamic css unloading (#17173)
Serverside Dynamically loaded CSS module file insertion adds css-files as usual static files with special data-n-p tag, that is used in page transition logic. That files get removed on page transition cause they are not explicitly required in scope of page.

Mini-css-extract-plugin adds style tags at chunk insertion without any tags and leave them be, no matter how many page transitions were made.

I removed data-n-p tag from dynamically loaded css module files and added new data-n-d tag for it.

Fixes #16950
2020-11-03 05:23:31 +00:00
JJ Kasper
8277d4d5e3
Ensure multi-level basePath works properly (#18715)
This ensures the `basePath` property works correctly when a multi-level value is defined (`/hello/world`)

Fixes: https://github.com/vercel/next.js/issues/17889
2020-11-03 02:44:50 +00:00
Steven
2b94b1eea6
Update default widths configuration to handle 2x/3x DPI (#18717)
- Update default `deviceSizes`
- Add default `imageSizes`
- Use `layout` value to determine which `srcset` to use

Fixes #18420 
Closes #18714
2020-11-03 02:12:46 +00:00
JJ Kasper
3f84a55ba3
Ensure locale is added/stripped correctly (#18712)
This makes sure we don't incorrectly strip locale characters from the path if it is not a locale prefix e.g. `/fr` should not be removed from `/frank`. Additional tests have been added to ensure this isn't stripped for this case.

Fixes: https://github.com/vercel/next.js/issues/18332
2020-11-02 23:32:56 +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
c8d26edf57
Allow passing statusCode for GS(S)P redirect (#18422)
This adds support for passing `statusCode` in a `redirect` from `getServerSideProps` or `getStaticProps` which matches the `redirect` shape allowed to be returned for `redirects` in `next.config.js`

Closes: https://github.com/vercel/next.js/issues/18350
2020-11-02 21:47:59 +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
JJ Kasper
4e7835c95d
Ensure html lang is updating on locale transition (#18699)
This ensures the `html` tag's `lang` attribute is updated on client-transition when the locale is changing

Fixes: https://github.com/vercel/next.js/issues/18452
2020-11-02 18:54:20 +00:00
JJ Kasper
a529e6736f
Ensure preload works correctly with locale option (#18511)
* Ensure preload works correctly with locale option

* Fix conditional import

* Update size-limit tests

* DCE some code

* Resolve merge error

Co-authored-by: Tim Neutkens <timneutkens@me.com>
2020-11-02 11:22:40 -06:00
Joe Haddad
85e143e943
Rotate image from EXIF data (#18687)
Fixes #18643
2020-11-02 16:26:03 +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
Steven
3fd1cc3ebb
Update 3rd party image loaders to prevent upscaling (#18647)
In PR #18147, we fixed the default loader to prevent upscaling images.

This PR fixes the same bug for 3rd party loaders.

---

Fixes #18648
2020-11-02 00:30:17 +00:00
Steven
377aa4b650
Fix image format for Safari and old browsers (#18646)
Older versions of Safari (and other browsers) do not support webp format so we were incorrectly falling back to png.

This PR fixes #18509 so that we fallback to the original image format if a modern format like webp was not explicitly provided in the Accept header.

Tests were added to ensure that the Accept header for Safari, Firefox, and Chrome work properly.
2020-11-01 23:53:36 +00: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
Jan Potoms
c0ae2041a1
Avoid calling setState in callback ref (#18589) 2020-10-31 23:37:28 -04:00
Steven
f8c32e556c
Add all deviceSizes to srcset for responsive and fill (#18594) 2020-10-31 20:26:57 -04:00
Joe Haddad
9569f5a31a
Deprecate Image unsized property and add layout="fill" (#18562)
This PR deprecates the `unsized` property from NextImage because the property did not accomplish the desired effect.

Users should rely on one of the new layouts instead:

- `<Image layout="fixed" />`
- `<Image layout="intrinsic" />`
- `<Image layout="responsive" />`
- `<Image layout="fill" />`

The `unsized` property will continue to work as-is in production but is deprecated and will throw in dev.

---

### TODO:
- [x] test `layout=fill` in typescript types
- [x] test `layout=fill` render behavior
- [x] test that `unsized` switches to `layout=fill`
- [x] test `next dev` erroring on `unsized`
- [ ] layout docs (tracked in issue #18554)
- [ ] both `layout=fill` and `layout=responsive` use all deviceWidths in the srcset

---

Fixes #18541 

Co-authored-by: Steven <steven@ceriously.com>
2020-10-31 18:34:06 -04:00
Steven
afa04d22db
Add layout prop to Image component (#18491)
This PR introduces a new `layout` property.

This allows 3 possible values (`fixed`, `intrinsic`, or `responsive`) which solve many use cases we have seen since 10.0.0 and will hopefully avoid usage of `unsized`.

Fixes #18351 

Co-authored-by: Joe Haddad <joe.haddad@zeit.co>
2020-10-30 10:33:34 -04: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
JJ Kasper
76504ebae3
Ensure custom routes handling with i18n (#18427)
This makes sure custom-routes function properly with i18n support. Since the `locale` is stripped from the `pathname` this re-adds when checking custom-routes to allow the locale to be matched against

Closes: https://github.com/vercel/next.js/issues/18349
2020-10-29 17:48:54 +00:00
Alex Castle
5d7f7a47af
Unlazify images if no intersection observer found (#18345) 2020-10-28 00:41:19 +01:00
JJ Kasper
27f56eb325
Add err.sh for missing images domain (#18325)
* Add err.sh for missing images domain

* Apply suggestions from code review

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

* Update test

Co-authored-by: Steven <steven@ceriously.com>
2020-10-27 16:55:21 -05: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
Steven
f7ba546e8a
Fix trailing slash for default image loader (#18298)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2020-10-27 15:29:52 +01: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
Yamagishi Kazutoshi
900afdc228
Add support number quality on Image Component (#18224)
Co-authored-by: Tim Neutkens <timneutkens@me.com>
2020-10-27 12:37:55 +01:00
Joe Haddad
080b91f986
Adjust default image quality to 75 (#18292) 2020-10-27 11:14:42 +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
9a770bde84
Add fetching 404 SSG data on fallback notFound (#18214) 2020-10-27 05:40:17 -04:00
JJ Kasper
11fce3a686
Remove unstable_ prefix from unstable_notFound (#18283)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Co-authored-by: Joe Haddad <joe.haddad@zeit.co>
2020-10-27 09:54:06 +01:00
JJ Kasper
7cb68f7981
Re-add domain locale redirect handling (#18274) 2020-10-27 04:45:39 -04:00
JJ Kasper
4026d9bea0
Remove unstable_ prefix from unstable_redirect (#18282) 2020-10-27 04:37:27 -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
Tasuku Uno
3f22490a59
Fix browser back issue of redirects from getServerSideProps / getStaticProps (#17741)
* Fix test without expect for redirects from getStaticProps/getServerSideProps

* Fix browser back issue of redirects from getServerSideProps / getStaticProps
2020-10-27 00:14:23 -05: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
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
b90e17e029
Add config limit checks for image optimizer (#18217)
This adds checks to ensure that less than 50 domain and size items are configured and no sizes are less than 0 or greater than 10,000 

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

Co-authored-by: Steven <steven@ceriously.com>
2020-10-26 11:42:44 -04:00
Steven
61fab923eb
Fix Image srcset to ensure the component's width is the largest possible image (#18236)
There was a bug when the user defines a width on the Image component, but a larger size image is requested.

This is because the browser uses the `srcset` to decide which image size to request and we had the srcset basically hardcoded.

This PR fixes the behavior so that the `srcset` will never be larger than the `width` defined on the component.

It also fixes a bug where the preload srcset did not match the img srcset.

- Related to #18147 
- Related to #18122
2020-10-26 14:29: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
Steven
33eac8acfa
Image Optimization API should 404 when loader is not default (#18211)
We currently always accept requests to the new `/_next/image` endpoint, even when it should not be used.

Instead, we should check to see if the default loader is used as a signal to enable this API.

Other loaders (such as cloudinary) will not go through the Next.js API so there is no need to expose this, instead we 404.

- Analogous to https://github.com/vercel/vercel/pull/5321
- Related to #18122
2020-10-25 04:54:22 +00:00
JJ Kasper
ebee2bafa9
Ensure 404 with SSG is rendered correctly with notFound (#18205)
This ensures a custom `/404` page with `getStaticProps` works correctly when leveraging the new `unstable_notFound` support in `getStaticProps`

Closes: https://github.com/vercel/next.js/issues/18196
x-ref: https://github.com/vercel/next.js/pull/17755
2020-10-24 19:22:48 +00:00
Steven
301c029e48
Add support for string width/height on Image component (#18178)
For many users refactoring from `<img>` to `<Image>`, we can often support their properties as-is.
The exception was width/height.

This PR allows the `<Image>` component to accept strings for `width` and `height` just like `<img>`.

Related to #18122
2020-10-24 02:01:15 +00:00
Steven
0dff7def7a
Bypass image optimization for vector images (#18179)
Previously, vector images like svg were being converted to webp and resized.

However, vector images already handle any size so we can bypass the same we do for animated images.

Related to #18122
2020-10-24 01:26:52 +00:00
Steven
a12eeea18d
Add w param (#18151)
Add missing `w` param for [old browsers](https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/srcset#Browser_compatibility) like IE that dont support `srcset` (@styfle)
2020-10-23 14:23:16 +00:00
Yamagishi Kazutoshi
f1005ca661
Pass quality param of image component to preload (#18158)
If give the `priority` and `quality` attributes to an Image Component, the `quality` attribute will not be given to the preload and a warning will be displayed to the devtool.

![screenshot on devtool](https://user-images.githubusercontent.com/12539/96960307-0837e000-153d-11eb-8c01-e15afd40e04f.png)
2020-10-23 06:36:54 +00:00
JJ Kasper
4442fe2faf
Update redirect query encoding (#18149)
* Update redirect query encoding

* Add additional tests
2020-10-22 18:45:43 -05:00
Steven
ac8a0c4836
Update Image Optimization API to prevent upscaling image (#18147)
The `w` parameter in the Image Optimization API is the requested size of the image and should only be resized if the source image is larger than the requested size. This PR fixes the behavior to prevent accidental upscaling, for example icon images.
2020-10-22 20:39:24 +00:00
Steven
07adc8ef26
Change Image component lazy=true to loading=lazy (#18138)
This PR updates the `<Image>` component to follow the same property naming as native `<img>`.

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Img#attr-loading

This currently allows two values,`loading=lazy` and `loading=eager`, but there might be new values added in a future spec.

cc @atcastle
2020-10-22 18:59:42 +00:00
JJ Kasper
9bbfa0e8d2
Add locale false handling (#18115)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2020-10-22 17:08:01 +02:00
Tim Neutkens
9fb1e60504
Make lazy-loading the default for next/image (#18123)
Co-authored-by: Steven <steven@ceriously.com>
2020-10-22 16:55:51 +02: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
Tim Neutkens
ea29bb3e4c
Fix precompiled code (#18093)
Solves the build failure we're seeing on PRs
2020-10-21 18:43:39 +00:00
Tasuku Uno
9dfc9ebc8a
Fix css dependency in /_error (#17301) 2020-10-21 12:11:18 +02:00
Steven
e8f402adfa
Add unsized property to Image component (#18059)
Implements the `unsized` property from RFC #16832

cc @atcastle
2020-10-21 10:03:31 +00: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
114de06432
Update handling for relative files in image-optimizer (#17998)
This updates the new image optimizer endpoint to instead of relying on the `host` and `proto` headers for relative files to use the internal route handling in `next-server` to load files from the public directory. The existing tests for relative files with the endpoint should cover these changes
2020-10-19 17:03:35 +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
JJ Kasper
bbdebd4f57
Make sure animated assets aren't de-animated by optimizer (#17974)
This makes sure the image optimizer doesn't de-animate images by transforming them with sharp since sharp doesn't currently handle outputting animated images

x-ref: https://github.com/vercel/next.js/pull/17749
2020-10-17 19:22:10 +00:00
Alex Castle
c9eb3dcad9
Image component lazy loading (#17916)
Co-authored-by: Tim Neutkens <timneutkens@me.com>
Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
2020-10-17 20:55:29 +02:00
JJ Kasper
f01deeedb9
Stabilize i18n fallback test (#17957)
* Stabilize i18n fallback test

* Handle reload during hydration check
2020-10-16 16:17:12 -05:00
Joe Haddad
0fe5b23b0e
Add perf data experiment (#17956) 2020-10-16 16:31:09 -04:00
Yamagishi Kazutoshi
6f13956f12
Unify config.image.breakpoints to config.image.sizes (#17953)
Unify the confusing `config.images.sizes` ([Image Optimizer](https://github.com/vercel/next.js/discussions/17141)) and `config.images.breakpoints` ([Image Component](https://github.com/vercel/next.js/discussions/16832)).
2020-10-16 19:36:31 +00: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
Joe Haddad
75f75f33ba
Call Web Vitals reporting at correct time (#17933)
This PR adjust the Web Vitals reporting to be called *after* rendering occurs. It used to work like this, but React's render method is no longer synchronous—so we have to do it in an effect.

Existing tests should cover this code path, and IMO it's unfeasible to test that it's invoked _after_ hydration.

Also removed the `&& ST` condition which is not relevant to Web Vitals.
2020-10-16 08:27:50 +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
Slawek Kolodziej
4238878c17
Make sure that params are properly passed to hybrid amp pages (#17461)
Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2020-10-15 16:03:02 +02: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
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
JJ Kasper
854a84937c
Fix a couple i18n cases (#17805)
While working on https://github.com/vercel/next.js/pull/17755 noticed a couple of cases that needed fixing and broke them out to this PR to make that one easier to review. One fix is for `ssgCacheKey` where it wasn't having the `locale` prefix stripped correctly due to the locales no longer being populated under the server instances `renderOpts` and the second fix is for the `asPath` not being set to `/` when the `locale` is the only part in the URL e.g. `/en` became an empty string `""`

x-ref: https://github.com/vercel/next.js/pull/17370
2020-10-12 10:05:47 +00: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
James George
742f5d9a46
test(create-next-app): increase coverage (#17507)
Added a test case to make sure that creating a new project within the current directory works as expected.
2020-10-05 13:04:25 +00:00
JJ Kasper
782b7e48ec
Add warning when exporting with custom routes (#17538)
This adds a warning when `next export` and custom routes are defined  outside of a platform that supports them since they won't be applied anymore.
2020-10-05 07:11:06 +00:00
JJ Kasper
489b13d00e
Fix empty title in head (#17430)
This handles the case where the children on a head element are undefined and not a string or an array of strings. This doesn't currently handle sub-children on head elements so additional handling will be needed if this is a feature we would like to support although can be discussed/investigated separately from this fix. 

Fixes: https://github.com/vercel/next.js/issues/17364  
Fixes: https://github.com/vercel/next.js/issues/6388
Closes: https://github.com/vercel/next.js/pull/16751
2020-09-28 23:12:07 +00:00
Joe Haddad
c351f6154b
Improve server performance by skipping decode/re-encode (#17323)
Prior to this pull request, Next.js would immediately decode all URLs sent to its server (via `path-match`).

This was rarely needed, and Next.js would typically re-encode the incoming request right away (see all the `encodeURIComponent`s removed in PR diff). This adds unnecessary performance overhead.

Long term, this will also help prevent weird encoding edge-cases like #10004, #10022, #11371, et al.

---

No new tests are necessary for this change because we've extensively tested these edge cases with existing tests.
One test was updated to reflect that we skip decoding in a 404 scenario.

Let's see if all the existing tests pass!
2020-09-24 06:05:40 +00:00
Stig Kleppe-Jørgensen
a4be780781
Remove duplicate should in test name (#17303) 2020-09-23 17:36:46 +00:00
Yuji Sugiura
4adf48b6cc
Fix export-cli progress label default value (#17106)
This PR fixes `info  - undefined (N/N)` log for `export` cli.

![image](https://user-images.githubusercontent.com/6259812/93186247-5d801500-f779-11ea-89ec-e20939d7b7c1.png)

Default parameter `label` for `createProgress()` was always ignored by `${Log.prefixes.info} undefined` 😅 .
2020-09-21 16:09:14 +00: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
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
Joe Haddad
49a59b1ad2
Polyfill missing std lib fns for module browsers (#17083) 2020-09-14 15:25:30 -04: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
a3c47721a1
Include all files in Prettier (#17050)
This uses the "Expand directories" feature introduces in Prettier 2.0 to automatically format all supported file types.

Also, I fixed some badly formatted files.
2020-09-14 02:53:19 +00:00
Joe Haddad
9b22dc4660
Improve custom document error message (#17048) 2020-09-12 18:57:07 +00:00
Markus Lautenbach
76e86e0fba
Remove false positive in circular structure detection (#16380)
Co-authored-by: Joe Haddad <joe.haddad@zeit.co>
2020-09-12 02:36:29 -04:00
JJ Kasper
8ecc359b6d
Update to check for overlay in client nav tests (#17002)
Closes: https://github.com/vercel/next.js/issues/14433
2020-09-11 08:37:19 +00:00
JJ Kasper
47d983f71f
Add error when href interpolation fails (#16946)
This adds an error when interpolation fails to make sure invalid `href`s aren't accidentally used and an invalid URL is built. 

Closes: https://github.com/vercel/next.js/issues/16944
2020-09-10 20:05:02 +00:00
Joe Haddad
1ea6745106
Importing CSS from Third Party React Components (#16993) 2020-09-10 13:45:30 -04:00
Jan Potoms
5aed1d2e35
Correct query behavior for falsey values to pre 9.5.1 behavior (#16608)
Fixes https://github.com/vercel/next.js/issues/16147
2020-09-10 15:12:37 +00:00
JJ Kasper
dcdcf49a87
Fix resolving href with a rewrite (#16975)
This makes sure we properly resolve a rewrite when only the `href` value is used. This was causing a full-reload and was missed in the existing test since we weren't making sure a full navigation didn't occur which has been added in this PR. 

Fixes: https://github.com/vercel/next.js/issues/16974
2020-09-10 00:55:22 +00:00
Joe Haddad
25cdaab297
Add Support for CSS Module Value Imports (#16973)
Fixes #10142
Fixes #11629
2020-09-09 23:29:37 +00:00
Gerald Monaco
039eb817e1
Remove next-head-count (#16758)
Removes `next-head-count`, improving support for 3rd party libraries that insert or append new elements to `<head>`.

---

This is more or less what a solution with a `data-` attribute would look like, except that instead of directly searching for elements with that attribute, we serialize the elements expected in `<head>` and then find them/assume ownership of them during initialization (in a manner similar to React's reconciliation) based on their properties.

There are two main assumptions here:
1. Content is served with compression, so duplicate serialization of e.g. inline script or style tags doesn't have a meaningful impact. Storing a hash would be a potential optimization.
2. 3rd party libraries primarily only insert new, unique elements to head. Libraries trying to actively manage elements that overlap with those that Next.js claims ownership of will still be unsupported.

The reason for this roundabout approach is that I'd really like to avoid `data-` if possible, for maximum compatibility. Implicitly adding an attribute could be a breaking change for some class of tools or crawlers and makes it otherwise impossible to insert raw HTML into `<head>`. Adding an unexpected attribute is why the original `class="next-head"` approach was problematic in the first place!

That said, while I don't expect this to be more problematic than `next-head-count` (anything that would break in this new model also should have broken in the old model), if that does end up being the case, it might make sense to just bite the bullet.

Fixes #11012
Closes #16707

---

cc @Timer @timneutkens
2020-09-09 01:41:04 +00:00
JJ Kasper
f46ddc6933
Correct page path for GS(S)P data refreshing (#16939)
This makes sure to the page path is the expected version to trigger refreshing on the client and adds additional tests to make sure it is working properly with these page variants. 

Closes: https://github.com/vercel/next.js/issues/16938
2020-09-08 16:00:05 +00:00
JJ Kasper
bc80fb4fb2
Add handling for redirects from getStaticProps/getServerSideProps (#16642)
Co-authored-by: Tim Neutkens <timneutkens@me.com>
2020-09-08 09:23:21 +02:00
JJ Kasper
f942d9e892
Include additional query values when interpolating href (#16878)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2020-09-07 13:09:02 +02:00
JJ Kasper
489cad36bc
Fix href resolving with trailing slash enabled (#16873)
This makes sure to strip the trailing slash before attempting to resolve the `href` against pages/dynamic routes and adds tests ensuring the correct pages are resolved with `trailingSlash: true` enabled.

Fixes: https://github.com/vercel/next.js/issues/16872
2020-09-06 02:36:57 +00:00
JJ Kasper
6233ef7ed8
Correct client rewrite resolving with query (#16860)
This makes sure we only pass the as value's `pathname` instead of the full value so that we don't accidentally include `query` values while resolving the rewrites. This also adds tests to ensure the rewrites are resolved with the correct query values when only providing `href` and when manually mapping them with `href` and `as`

Fixes: https://github.com/vercel/next.js/issues/16825
2020-09-04 19:19:17 +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
Zack Tanner
08859275ae
Add tests for searchParams dev warning (#16798)
Fixes a warning being logged to the console when using `href` with a dynamic path. Fixes #16794
2020-09-03 18:47:45 +00:00
JJ Kasper
8426f13713
Update to show build indicator while re-fetching GS(S)P data in dev (#16789)
This is a follow-up to https://github.com/vercel/next.js/pull/16744 which shows the build/activity indicator while the data is being re-fetched to let the user know the re-fetching is occurring 

Closes: https://github.com/vercel/next.js/issues/16790
2020-09-03 12:27:08 +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
JJ Kasper
f8d92a67f0
Ensure interpolating dynamic href values works correctly (#16774)
This corrects/makes sure interpolating dynamic route values for `href` works correctly. This provides an alternative approach to building the `href` value with `next/link` so that you don't need to worry about encoding the params manually. 

Closes: https://github.com/vercel/next.js/issues/13473
Closes: https://github.com/vercel/next.js/issues/14959
Closes: https://github.com/vercel/next.js/issues/16771
2020-09-02 16:23:26 +00:00
Alex Castle
6874adbbb9
Make the image post-processor ignore SVG images (#16732)
This is a small change to the image post-processor logic. When it's looking for images to preload, it will now ignore SVGs, as these are rarely the relevant images for LCP.
2020-09-02 02:42:20 +00:00
Joe Haddad
1c45f70952
[test] Update hydration marker for React 17 (#16756) 2020-09-01 17:43:44 +00:00
Joe Haddad
f921b4f476
Auto enable React's new JSX transform on 17.x (#16603) 2020-09-01 11:29:25 -04:00
Jan Potoms
20a4928b16
remove unneeded error (#16636)
This is not needed anymore since absolute urls are supported.
Also added an extra test for `mailto:` urls
2020-08-28 02:49:40 +00:00
Joe Haddad
6895f9b0f4
Replace <link rel=stylesheet> client-side transitions with <style> tags (#16581)
This pull request replaces our client-side style transitions with `<style>` tags over async `<link rel=stylesheet>` tags. This should fix some edge cases users see with Chrome accidentally causing a FOUC.

This also removes the need to perform an async operation before starting the render, which should remove any perceivable navigation delay.

---

Fixes #16289
2020-08-26 16:34:53 +00:00
JJ Kasper
990c1792d2
Add tests for preview mode caching (#16579)
This adds tests to ensure preview mode pages aren't cached and made publicly available or written to the disk. 

Closes: https://github.com/vercel/next.js/issues/16020
2020-08-26 11:07:32 +00:00
Joe Haddad
52efe3364f
Reuse existing <link rel=stylesheet> on nav (#16537)
This pull request reuses existing `<link rel=stylesheet>` tags if their `href` matches instead of recreating it. This is in effort to fix an edge case where the browser will FOUC on the tag swap.

This behavior should be sufficiently covered by all the existing CSS cases, as misbehavior would result in the resulting CSS styles being incorrect.
2020-08-25 15:03:14 +00:00
Joe Haddad
34f737c47b
Increase font test timeout for Windows (#16527) 2020-08-25 10:41:34 -04: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
JJ Kasper
a7550bf1d7
Add error when document component isn't rendered (#16459)
If a custom `_document` is added but not all of the expected document components are rendered it can cause unintended errors as noticed in https://github.com/vercel/next.js/issues/10219 so this adds detecting when one of the expected document components isn't rendered and shows an error. 

Closes: https://github.com/vercel/next.js/issues/10219
2020-08-24 02:42:51 +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
JJ Kasper
32ee65efa1
Correct shallow routing behavior through history (#16477)
When navigating from a non-shallow page to a page that was navigated to shallowly in history it causes incorrect page data to be shown since an incorrect shallow navigation is done. We can only maintain shallow routing when the current page was navigated to shallowly and the page being navigated to in history was also navigated to shallowly. Additional tests to ensure this behavior is working has also been added. 

Closes: https://github.com/vercel/next.js/issues/7395
Closes: https://github.com/vercel/next.js/issues/14928
Fixes: https://github.com/vercel/next.js/issues/16028
2020-08-22 21:51:14 +00:00
Joe Haddad
9acd001e09
Fix render cancel behavior (#16462)
This pull request correctly tracks render cancelation behavior. Prior to this PR, we'd have an unhandled rejection that left the app in a bad state and no routeChangeError event was fired.

---

Closes #16424
Fixes #16445
2020-08-22 11:47:21 +00:00
JJ Kasper
8a1c9937b6
Make sure to break rewrites chain when dynamic route matches (#16455)
This makes sure to also check if a dynamic route matched after resolving a rewrite on the client to match behavior on the server. It also adds tests for this behavior to ensure it is working properly. 

Fixes: https://github.com/vercel/next.js/issues/16454
2020-08-22 05:15:45 +00: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
Janicklas Ralph
b1ea19a563
Eslint preload (#16199)
Eslint rule checks for missing preloads for stylesheets.

cc: @prateekbh
2020-08-20 19:34:12 +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
Joe Haddad
ec7009620a
Ensure unknown static paths 404 for data request (#16401)
We were accidentally allowing data requests to be rendered unconditionally. Instead, we should also check them against the staticPaths result and 404 when appropriate.

---

Fixes #15383
2020-08-20 17:59:03 +00:00
Joe Haddad
fc98c13a2e
Warn on duplicate Sass deps (#16398)
Fixes #13953
2020-08-20 16:05:29 +00:00
JJ Kasper
3dec50001e
Add debug flag for extra build output (#16399)
This adds a `-d` or `--debug` flag which enables outputting additional build output information like the rewrites, redirects, and headers

Fixes #15281
2020-08-20 15:43:38 +00:00
JJ Kasper
e1e6cfa189
Fix page checking failing with trailingSlash (#16362)
This fixes page checking failing due to the trailing slash being present which causes pages to proxied by a rewrite when they shouldn't be. This also adds additional tests to ensure rewriting to an external resource is working correctly with `trailingSlash: true`

Fixes: https://github.com/vercel/next.js/issues/15700
2020-08-20 04:05:38 +00:00
JJ Kasper
681fbbd04d
Fix basePath and public folder check ending routes early (#16356)
This corrects the basePath being required check for filesystem routes to not consider the public folder catch-all route since it always matches even if the public file isn't present and instead moves the basePath check inside of the public-folder catch-all. Tests already exist that catch this by adding a public folder to the existing `basepath` test suite

Fixes: https://github.com/vercel/next.js/issues/16332
Closes: https://github.com/vercel/next.js/pull/16350
2020-08-19 17:30:33 +00:00
matamatanot
0226e7872a
CNA: Add warning about permission (#14889)
close #14744

<img width="851" alt="screen_shot" src="https://user-images.githubusercontent.com/39780486/86603491-06bec800-bfdf-11ea-9928-ee85cbad86a7.png">


I have some concerns.

- `import { isWriteable } from '../next/build/is-writeable'` **not** from `create-next-app ` package.
- The warning sentence is from npm. Not for Next.js. I'm not a native English speaker. I'd like to know the natural expression for this.
2020-08-19 17:09:34 +00:00
JJ Kasper
67482914c6
Normalize request URL/asPath for fallback SSG pages (#16352)
This interpolates the dynamic values and rebuilds the request URL for fallback SSG pages since the proxy uses the output path for non-prerendered pages on Vercel which can cause inconsistent request URL/`asPath` values for SSG pages. This also adds tests to ensure the `asPath` is correctly updated

Fixes: https://github.com/vercel/next.js/issues/16269
2020-08-19 15:23:02 +00:00
Joe Haddad
0a72d14deb
Make loadPage track success of script loading (#16334)
Prior to this PR, `loadPage` would call `loadScript` which would then report if the script failed to load.

This was problematic because `loadScript` notified a failure to load via `pageRegisterEvents`, which would not set the `pageCache` value for future requests.
This means a one-off promise rejection would happen, [in lieu of being] typically consumed within the client-side router, causing a server-side reload.

However, when `loadPage` was used independently (i.e. to preload pages), this promise rejection would be ignored as a preload failure.
When the real routing request comes in, the `loadPage` function skips its attempt to load the `<script>` because it was already in the DOM, and the router would stop functioning.

---

To fix this behavior, I've removed erroneous emits on `pageRegisterEvents` to only happen during the page registration lifecycle (its intended use).

The new behavior is that `loadScript` returns a `Promise` that `loadPage` can track, and if any of the page(s) scripts fail to load, we mark the entire page as errored in `pageCache`. This ensures future requests to `loadPage` will always immediately reject with a `PAGE_LOAD_ERROR`, which causes the server-side redirect at the appropriate point.

---

Fixes #16333
2020-08-19 11:41:01 +00:00
Joe Haddad
9746043354
Fix IE11 CSS Compatibility (#16336) 2020-08-19 02:34:44 -04:00
Alex Castle
7198cbe093
Add at attribute to image preload link (#16328)
Fixes a small error in the image preload post-processor. Adds a needed 'as' attribute to the link.
2020-08-18 21:14:42 +00:00
Joe Haddad
5f9755002d
Force browser to recompute layout on page nav (#16318)
This fixes an edge case where every dozen or so transitions you'll see a flash depending on what's happening on the main thread at the time.

I'm not sure it's possible to test for this case, so we'll just have to do more field testing with this.
2020-08-18 18:15:51 +00:00
Joe Haddad
ff33e07afe
Replace broken prop-types-exact package (#15953)
This PR replaces `prop-types-exact` (only used in this location) with manual property checking.

Right now, malformed properties sent to `<Link>` are silently handled and only emit a warning in the console.
This leads to confusing/unexpected errors because we try to read a value that is undefined.

To fix this, we'll now throw a proper error when `<Link>` is misused. **This still isn't optimal, however, because we don't have a component stack trace we can give the user**.
We're not going to be able to give the user actionable instructions until React 16.14 at a minimum.

---

Fixes #13951
Fixes #16107
Closes #13962
2020-08-18 16:36:40 +00:00
Joe Haddad
1318a8d98a
Fix module not found test 2020-08-18 11:30:37 -04:00
James Mosier
29ae372738
Allow React experimental version without warning (#16140)
Co-authored-by: Joe Haddad <joe.haddad@zeit.co>
2020-08-18 01:54:31 -04:00
Joe Haddad
bb8374126f
Test basic css module prefetching without compose (#16134) 2020-08-18 01:12:34 -04:00
Joe Haddad
06d8acdfd0
Update stylesheets on page navigation (#16126)
This pull request adds a test case for the reproduction provided in #12445. This bug is specifically caused when loading the next page before navigation has actually occurred.

---

Fixes #12445
2020-08-17 21:20:05 +00:00
Kevin Mårtensson
aa4b87e357
Handle cases where config is exported after its declaration (#16211)
AMP will still not work correctly when switching between non-AMP and AMP pages in development mode because of https://github.com/vercel/next.js/blob/canary/packages/next/build/babel/plugins/next-page-config.ts#L116-L120.

Fixes #15704.
2020-08-17 17:24:18 +00:00
JJ Kasper
f8534a6e62
Fix data URL with root-catchall and basePath (#16263)
This fixes the incorrect `/_next/data` URL being generated on client transition due to the `as` value passed to `getRouteInfo` having the `basePath` which is used while interpolating the values for dynamic routes, specifically root catch-all routes. A regression test has also been added to ensure this is working

Closes: https://github.com/vercel/next.js/issues/15747
2020-08-17 15:25:36 +00:00
Sergey Rubanov
feeb941dc6
Update to Terser 5 (#16194)
Co-authored-by: Tim Neutkens <timneutkens@me.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2020-08-16 19:32:37 +02:00
JJ Kasper
1b4d463cc8
Update rewrite params query appending (#16189)
This updates to not automatically append params to the query for rewrites if one or more of the params are already used in the destination's path. No other behavior is being changed and if the user still wants the params in the query after using them in the destination's path they can manually add them like with redirects.

Closes: https://github.com/vercel/next.js/issues/15626
2020-08-14 18:51:58 +00:00
JJ Kasper
39e00a3f2f
Add test case for preloading buildManifest (#16183) 2020-08-13 23:04:27 -05:00
JJ Kasper
8a489e24bc
Add initial handling for dynamic route href resolving and rewrites on the client (#15231)
Co-authored-by: Tim Neutkens <timneutkens@me.com>
2020-08-13 14:39:36 +02:00
Joe Haddad
6d71eef518
Do not assign to readonly property in Safari (#16051) 2020-08-10 13:15:37 -04:00
Joe Haddad
e08b633c3a
Do not bundle caniuse-lite (#16048) 2020-08-10 11:27:21 -04:00
Tim Neutkens
843d58425b
Add browser polyfils for Node.js modules (webpack 5 backwards compat) (#16022)
This adds the following Node.js core polyfills only when the import is used:

- `path`
- `stream`
- `vm`
- `crypto`
- `buffer`

Fixes #15948

We'll have a separate issue about adding warnings for the usage of these modules in the browser, some polyfills like crypto are quite heavy and generally not needed for most applications (included accidentally through node_modules).
2020-08-10 01:26:21 +00:00
Amirali Esmaeili
4b6e9a45a3
Fix amphtml link rel not respecting basePath (#15949)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2020-08-08 15:15:00 +02:00
JJ Kasper
b1ef76df31
Fix asPath normalizing for non-dynamic pages (#15960) 2020-08-07 09:01:34 +02:00
Markoz Peña
6375026a41
Added Friendly error for res.redirect 🐝 (#15844)
## Which solves this PR

 Displaying a friendly error, when the user is only passing `statusOrUrl`(type number) and the second argument `url` is ignored.

**Example**

`res.redirect(307);` // Show friendly error

Closes: https://github.com/vercel/next.js/issues/15594
x-ref: https://github.com/vercel/next.js/pull/15603
2020-08-06 22:53:09 +00:00
Tom Dohnal
eb4be226fd
notify component when route hash changes (#13894)
This resolves https://github.com/vercel/next.js/issues/13659
2020-08-06 22:04:47 +00:00
Joe Haddad
882288b532
Warn when Fast Refresh is disabled (React <16.10) (#15931) 2020-08-06 10:41:11 -04:00
Joe Haddad
2d42b8e076
Delay server start message until it's listening (#15929)
Fixes #15928

---

This would cause us to print the message too early and open the browser to a server that wasn't started yet. This waits until we're listening, but before the app is ready fully.
2020-08-06 06:47:01 +00:00
Joris
0fd1958ae4
Disallow re-export all exports from Next.js pages (#14325)
Co-authored-by: Joe Haddad <joe.haddad@zeit.co>
2020-08-05 16:21:40 -04:00
JJ Kasper
7d7a8fc300
Normalize serverless asPath value (#15914)
Since we now use query parameters to pass dynamic route params while routing on Vercel, this makes sure we normalize the request URL before populating the `asPath`

Fixes: https://github.com/vercel/next.js/issues/15879
2020-08-05 19:29:38 +00:00
Tim Neutkens
405e42e41e
Enhance module not found error (#15860)
Adds handling for module not found errors exposed by webpack. This ensures you see the actual stack line and code instead of a short message where you don't know where to go.

### Previous

<img width="794" alt="Screen Shot 2020-08-05 at 18 02 06" src="https://user-images.githubusercontent.com/6324199/89435935-d5542c00-d745-11ea-9ca7-c67f553364f9.png">


### New

<img width="769" alt="Screen Shot 2020-08-05 at 14 20 23" src="https://user-images.githubusercontent.com/6324199/89412212-f6595480-d726-11ea-81a3-398ab7036338.png">


Fixes #14711
2020-08-05 19:11:35 +00:00
Jan Potoms
17716d1499
Add tests for querystring-relative urls (#15911) 2020-08-05 14:23:08 -04:00
Jan Potoms
5dbe0d0215
Allow absolute urls in router and Link (#15792)
Fixes https://github.com/vercel/next.js/issues/15639
Fixes https://github.com/vercel/next.js/issues/15820

To Do:
- [x] Doesn't work with `basePath` yet
2020-08-05 18:12:17 +00:00
Alex Castle
b6060fa4a5
Add experimental image post-processing (#15875)
This PR adds a second experimental post-processing step for the framework introduced by @prateekbh in #14746. The image post-processing step scans the rendered document for the first few images and uses a simple heuristic to determine if the images should be automatically preloaded.

Analysis of quite a few production Next apps has shown that a lot of sites are taking a substantial hit to their [LCP](https://web.dev/lcp/) score because an image that's part of the "hero" element on the page is not preloaded and is getting downloaded with lower priority than the JavaScript bundles. This post-processor should automatically fix that for a lot of sites, without causing any real performance effects in cases where it fails to identify the hero image.

This feature is behind an experimental flag, and will be subject to quite a bit of experimentation and tweaking before it's ready to be made a default setting.
2020-08-05 17:49:44 +00:00
Joe Haddad
754ec6642a
Run Fast Refresh Loader in Babel Loader (#15851)
Next.js plugins like `@next/mdx` inject additional webpack loaders to compile files, but they omit the necessary loader for Fast Refresh to work.

Instead of making these files deopt out of Fast Refresh, we can automatically detect and inject the loader in these cases.

Fixes #13574
2020-08-04 21:24:56 +00:00
Jan Potoms
92304404a4
Disallow basePath: false for internal routes (#15837) 2020-08-04 17:50:09 +00:00
jiangtao
35e4a370d9
fixed issue with runtime-config returning undefined when building or in a development environment (#15777)
fix https://github.com/vercel/next.js/issues/7713#issuecomment-643632270
2020-08-04 16:47:37 +00:00
Joe Haddad
e818389999
Add support for fallback: 'blocking' (#15672)
By popular request, this pull request adds support for returning `fallback: 'blocking'` from `getStaticPaths`.

This new mode will cause unknown paths to be rendered on-demand ("SSR") without the static (placeholder) fallback.

This feature is **currently experimental and should not be used in production yet**. It's currently flagged behind `unstable_`:

```
fallback: 'unstable_blocking'
```

TODO:

- [x] Next.js tests
- [ ] Add Vercel support
- [ ] Vercel tests

---

Fixes #15637
2020-08-04 15:10:31 +00:00