Commit graph

1509 commits

Author SHA1 Message Date
Steven
318a1bf309
Add "nonce" from <Head> to the injected <style> to satisfy CSP (#19150)
Fixes #18557
2020-11-13 20:29:16 +00:00
Joe Haddad
415d7fd75e
Respect next/babel user provided runtime option (#19136) 2020-11-13 02:41:54 -05:00
Steven
20ab35128c
Add missing sizes prop on image component (#19128)
- Fixes #19120
- Closes #18413 
- Related to #19041
2020-11-13 04:30:41 +00:00
Joe Haddad
9174b7a337
Fix component lifecycle order for style swap (#19125)
Co-authored-by: Gerald Monaco <gbmonaco@google.com>
2020-11-12 22:57:15 -05:00
Joe Haddad
04ab35298a
Remove preload for priority images (#19118)
Fixes #18720

This removes image preloading. It doesn't work correctly on any browser other than Chrome (with Chrome's real engine). On all other browsers, it triggers 2x the bytes to be downloaded. The tradeoff isn't worth it here IMO.

Chrome itself should be smart enough to bump an `<img />` tag's priority over other preloads that are script type during the preparse phase.

We can reintroduce this when we don't hurt non-Chrome users.
2020-11-12 19:45:50 +00:00
Steven
5562daf7a1
Fallback to default config to enable testing Image component (#19107)
Fixes #18415 by using the default config as fallback.

Users who wish to use their `next.config.js` values will still need the workaround from https://github.com/vercel/next.js/issues/18415#issuecomment-718180659
2020-11-12 19:24:08 +00: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
Matsumoto Toshi
c88872cea0
fix: issue #18338 - don't add a trailing slash to external links (#18595)
## Description

Fixes #18338 - Fixed an issue with `trailingSlash: true` adding a slash to the end of an external link.

After
```
<h1 class="Home_title__3DjR7">Welcome to <a href="https://nextjs.org">Without slash</a></h1>
<h1 class="Home_title__3DjR7">Welcome to <a href="https://nextjs.org">With slash?</a></h1>
```

Before
```
<h1 class="Home_title__3DjR7">Welcome to <a href="https://nextjs.org">Without slash</a></h1>
<h1 class="Home_title__3DjR7">Welcome to <a href="https://nextjs.org/">With slash?</a></h1>
```
2020-11-12 18:10:40 +00:00
Anton Rieder
62633b1af5
Fix grammar in isSerializableProps (#19072)
I believe this should read ["altogether"](https://www.merriam-webster.com/dictionary/altogether) not "all together".
2020-11-12 16:07:14 +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
9f6d5b14df
Add test and errsh for mixed notFound/redirect error (#19076)
This ensures the mixed `notFound`/`redirect` error is shown correctly and adds an err.sh for the error. 

Closes: https://github.com/vercel/next.js/issues/18727
2020-11-11 22:02:11 +00: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
Joe Haddad
0d5bf65feb
Replace page loader with new route loader (#19006)
This pull request completely replaces our old page loader with a brand new route loader.

Our existing comprehensive test suite means I did not need to add a bunch of tests. I did add them where behavior was added or fixed.

Summary of the changes:

- Eagerly evaluates prefetched pages in browser idle time (speeds up transitions)
- Router is **no longer frozen** indefinitely if the Build Manifest never arrives
- Router is **no longer frozen** indefinitely if a page fails to bootstrap
- New `withFuture` utility instead of ad-hoc deduping per resource
- Prefetching is now delayed until browser idle time to not impact TTI
- Browsers without `prefetch` now fall back to eager evaluation instead of using `preload`
- We're now ready to serve non-static assets **with `no-store` without breaking prefetching**
- **Application can now hydrate without fetching CSS assets—this is a huge performance win that was previously blocking hydration**

---

The minor size increase here is unfortunate, but we have to incur it for correctness.

---

Fixes #18389
Fixes #18642
2020-11-11 18:13:16 +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
Gerald Monaco
80671273ca
Revert "Remove next-head-count (#16758)" (#18713)
Co-authored-by: Joe Haddad <joe.haddad@zeit.co>
2020-11-10 16:35:47 -05:00
Steven
530b14616f
Add test for .ico image bypass (#19025)
We fixed this in a previous PR but there were no tests for `.ico` so this PR adds a test for it to ensure we don't regress.

Similar to SVG, we bypass ICO because it typically contains multiple sizes in a single file.

Closes #18600
2020-11-10 17:49:37 +00:00
JJ Kasper
18494fe3fb
Break-up unit tests to separate step (#18992) 2020-11-10 12:25:50 -05:00
Steven
9573426599
Add etag header to optimized image response (#18986)
Fixes #18563 by adding the etag header to the optimized image response.

This does _not_ change the expireAt (TTL) for cached files on the server, which still uses the max-age of the upstream response.

The new file format on disk for cached image files is the following:

```
.next/cache/images/<HASHED_QUERYSTRING>/<EXPIREAT>.<ETAG>.<EXT>
```
2020-11-10 04:40:26 +00:00
tolfino
bbde18f120
Fix false positive in isSerializable with shared references in arrays (#18232)
This replaces the seen set with a newly instantiated map of refs per
value in the array. This corrects the behavior that the refs map passed
into isSerializable contains only values along the path to the current
value: previously, because the refs map was shared among all values in
the array, this would trigger on instances such as:

```js
    const x = [];
    isSerializableProps('/', 'test', { arr: [x, [x]] });
```

... where the reference is shared but there is no cycle formed, as the
presence of elements is disjoint.

Fixes #18228.
2020-11-09 14:25:41 +00:00
James George
91d4aa5450
tests(create-next-app): prevent catch assertions (#18939)
Prevent `catch` assertions in tests.
2020-11-09 13:59:44 +00:00
Tadao Iseki
d196e72a7f
Export ImageProps from Image component (#18576)
This allows to import the type `ImageProps` from `next/image` like `next/link`.

a6660729ea/packages/next/client/link.tsx (L21)

## Usage

```tsx
import Image, { ImageProps } from 'next/image'

const CustomImage: React.FC<ImageProps> = (props) => (
  <Image {...props} unsized />
)
```
2020-11-09 06:20:54 +00:00
JJ Kasper
3cece4d2ad
Update Azure config (#18931) 2020-11-09 00:56:39 -05:00
JJ Kasper
90a86e6723
Ensure auto-export dynamic routes work with i18n next start (#18930)
This ensures dynamic routes are correctly generated for `next start` with i18n and adds tests to the i18n suite to ensure they are working correctly. 

Closes: https://github.com/vercel/next.js/issues/18397
2020-11-08 02:18:13 +00:00
Steven
b2a8a2f99e
Fix html validation for Image component (#18903)
This PR fixes two bugs causing HTML validators to complain.

- Error: Bad value data:image/svg+xml;charset=utf-8, for attribute src on element img: Illegal character in scheme data: < is not allowed.
  - Fixed by using base64 for svg during `layout=intrinsic` to avoid angle brackets
- Error: Element img is missing required attribute src.
  - Fixed by using base64 transparent gif for `loading=lazy` placeholder

Fixes #18850
2020-11-07 17:39:14 +00:00
Joe Haddad
266c7ed74c
Add additional tests (#18597)
This PR adds additional security tests.
2020-11-07 12:49:18 +00:00
JJ Kasper
2effca8e03
Fix redirect query handling for param like values (#17448)
This makes sure to compile query values for rewrites/redirects as non-path items to prevent param like values e.g. `https://` from causing the destination to fail to compile. 

Fixes: https://github.com/vercel/next.js/issues/17440 
x-ref: https://github.com/vercel/next.js/issues/18670
2020-11-07 04:30:14 +00:00
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