Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dangerously-unoptimized loader for next/image #26847

Merged
merged 11 commits into from
Jul 7, 2021

Conversation

darshkpatel
Copy link
Contributor

@darshkpatel darshkpatel commented Jul 2, 2021

Related to: #21079
RFC Link: #26850

Added loader dangerously-unoptimized which basically returns the src URL, this would also allow next export to run without errors and Images without a custom loader specified can fallback to the static loader.

ToDo:

  • Add Integration tests
  • Update Documentation

@ijjk ijjk added the type: next label Jul 2, 2021
@ijjk

This comment has been minimized.

@ijjk

This comment has been minimized.

@darshkpatel darshkpatel marked this pull request as ready for review July 4, 2021 10:55
@ijjk

This comment has been minimized.

@ijjk

This comment has been minimized.

Copy link
Member

@styfle styfle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

Let's get feedback in RFC #26850 before proceeding 👍

packages/next/client/image.tsx Outdated Show resolved Hide resolved
packages/next/client/image.tsx Outdated Show resolved Hide resolved
@ijjk ijjk requested a review from styfle July 7, 2021 18:58
Co-authored-by: Steven <steven@ceriously.com>
styfle
styfle previously approved these changes Jul 7, 2021
Copy link
Member

@styfle styfle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@styfle styfle changed the title Static loader support for next/image Add dangerously-unoptimized loader for next/image Jul 7, 2021
ijjk
ijjk previously approved these changes Jul 7, 2021
@ijjk

This comment has been minimized.

@ijjk ijjk dismissed stale reviews from styfle and themself via 37c74bf July 7, 2021 19:41
@ijjk
Copy link
Member

ijjk commented Jul 7, 2021

Stats from current PR

Default Build (Increase detected ⚠️)
General Overall increase ⚠️
vercel/next.js canary darshkpatel/next.js static-loader Change
buildDuration 16.7s 16.7s -37ms
buildDurationCached 3.9s 3.8s -113ms
nodeModulesSize 49.3 MB 49.3 MB ⚠️ +465 B
Page Load Tests Overall increase ✓
vercel/next.js canary darshkpatel/next.js static-loader Change
/ failed reqs 0 0
/ total time (seconds) 2.775 2.747 -0.03
/ avg req/sec 901.05 909.95 +8.9
/error-in-render failed reqs 0 0
/error-in-render total time (seconds) 1.737 1.735 0
/error-in-render avg req/sec 1439.09 1440.85 +1.76
Client Bundles (main, webpack, commons)
vercel/next.js canary darshkpatel/next.js static-loader Change
359.HASH.js gzip 3.09 kB 3.09 kB
framework-HASH.js gzip 42 kB 42 kB
main-HASH.js gzip 20.6 kB 20.6 kB
webpack-HASH.js gzip 1.49 kB 1.49 kB
Overall change 67.2 kB 67.2 kB
Legacy Client Bundles (polyfills)
vercel/next.js canary darshkpatel/next.js static-loader Change
polyfills-HASH.js gzip 31.1 kB 31.1 kB
Overall change 31.1 kB 31.1 kB
Client Pages Overall increase ⚠️
vercel/next.js canary darshkpatel/next.js static-loader Change
_app-HASH.js gzip 803 B 803 B
_error-HASH.js gzip 3.18 kB 3.18 kB
amp-HASH.js gzip 526 B 526 B
css-HASH.js gzip 329 B 329 B
hooks-HASH.js gzip 903 B 903 B
image-HASH.js gzip 5.6 kB 5.62 kB ⚠️ +21 B
index-HASH.js gzip 261 B 261 B
link-HASH.js gzip 1.66 kB 1.66 kB
routerDirect..HASH.js gzip 319 B 319 B
withRouter-HASH.js gzip 320 B 320 B
bb14e60e810b..30f.css gzip 125 B 125 B
Overall change 14 kB 14 kB ⚠️ +21 B
Client Build Manifests Overall increase ⚠️
vercel/next.js canary darshkpatel/next.js static-loader Change
_buildManifest.js gzip 418 B 419 B ⚠️ +1 B
Overall change 418 B 419 B ⚠️ +1 B
Rendered Page Sizes
vercel/next.js canary darshkpatel/next.js static-loader Change
index.html gzip 531 B 531 B
link.html gzip 544 B 544 B
withRouter.html gzip 524 B 524 B
Overall change 1.6 kB 1.6 kB

Diffs

Diff for _buildManifest.js
@@ -13,7 +13,7 @@ self.__BUILD_MANIFEST = {
     "static\u002Fchunks\u002Fpages\u002Fhooks-4e38b05900fed34fcf34.js"
   ],
   "/image": [
-    "static\u002Fchunks\u002Fpages\u002Fimage-0a8987f5a01c8fb53ae0.js"
+    "static\u002Fchunks\u002Fpages\u002Fimage-f70c91ef36603165d772.js"
   ],
   "/link": ["static\u002Fchunks\u002Fpages\u002Flink-461e3656f357dad048d3.js"],
   "/routerDirect": [
Diff for image-HASH.js
@@ -131,7 +131,8 @@
         ["imgix", imgixLoader],
         ["cloudinary", cloudinaryLoader],
         ["akamai", akamaiLoader],
-        ["default", defaultLoader]
+        ["default", defaultLoader],
+        ["dangerously-unoptimized", unoptimizedLoader]
       ]);
       var VALID_LAYOUT_VALUES = [
         "fill",
@@ -752,11 +753,16 @@
           .concat(normalizeSrc(src));
       }
 
-      function defaultLoader(_ref9) {
-        var root = _ref9.root,
-          src = _ref9.src,
-          width = _ref9.width,
-          quality = _ref9.quality;
+      function unoptimizedLoader(_ref9) {
+        var src = _ref9.src;
+        return src;
+      }
+
+      function defaultLoader(_ref10) {
+        var root = _ref10.root,
+          src = _ref10.src,
+          width = _ref10.width,
+          quality = _ref10.quality;
 
         if (false) {
           var parsedSrc, missingValues;
@@ -1532,7 +1538,13 @@ Also adds support for deduplicated `key` properties
       "use strict";
       exports.__esModule = true;
       exports.imageConfigDefault = exports.VALID_LOADERS = void 0;
-      const VALID_LOADERS = ["default", "imgix", "cloudinary", "akamai"];
+      const VALID_LOADERS = [
+        "default",
+        "imgix",
+        "cloudinary",
+        "akamai",
+        "dangerously-unoptimized"
+      ];
       exports.VALID_LOADERS = VALID_LOADERS;
       const imageConfigDefault = {
         deviceSizes: [640, 750, 828, 1080, 1200, 1920, 2048, 3840],

Webpack 4 Mode (Decrease detected ✓)
General Overall increase ⚠️
vercel/next.js canary darshkpatel/next.js static-loader Change
buildDuration 13.1s 13.3s ⚠️ +230ms
buildDurationCached 5.3s 5.3s -37ms
nodeModulesSize 49.3 MB 49.3 MB ⚠️ +465 B
Page Load Tests Overall decrease ⚠️
vercel/next.js canary darshkpatel/next.js static-loader Change
/ failed reqs 0 0
/ total time (seconds) 2.804 2.788 -0.02
/ avg req/sec 891.59 896.75 +5.16
/error-in-render failed reqs 0 0
/error-in-render total time (seconds) 1.667 1.703 ⚠️ +0.04
/error-in-render avg req/sec 1499.31 1468.23 ⚠️ -31.08
Client Bundles (main, webpack, commons)
vercel/next.js canary darshkpatel/next.js static-loader Change
14.HASH.js gzip 3.11 kB 3.11 kB
677f882d2ed8..HASH.js gzip 13.9 kB 13.9 kB
framework.HASH.js gzip 41.8 kB 41.8 kB
main-HASH.js gzip 7.81 kB 7.81 kB
webpack-HASH.js gzip 1.19 kB 1.19 kB
Overall change 67.8 kB 67.8 kB
Legacy Client Bundles (polyfills)
vercel/next.js canary darshkpatel/next.js static-loader Change
polyfills-HASH.js gzip 31.3 kB 31.3 kB
Overall change 31.3 kB 31.3 kB
Client Pages
vercel/next.js canary darshkpatel/next.js static-loader Change
_app-HASH.js gzip 791 B 791 B
_error-HASH.js gzip 3.83 kB 3.83 kB
amp-HASH.js gzip 531 B 531 B
css-HASH.js gzip 333 B 333 B
hooks-HASH.js gzip 910 B 910 B
index-HASH.js gzip 230 B 230 B
link-HASH.js gzip 1.64 kB 1.64 kB
routerDirect..HASH.js gzip 297 B 297 B
withRouter-HASH.js gzip 293 B 293 B
e025d2764813..52f.css gzip 125 B 125 B
Overall change 8.98 kB 8.98 kB
Client Build Manifests
vercel/next.js canary darshkpatel/next.js static-loader Change
_buildManifest.js gzip 418 B 418 B
Overall change 418 B 418 B
Rendered Page Sizes
vercel/next.js canary darshkpatel/next.js static-loader Change
index.html gzip 575 B 575 B
link.html gzip 586 B 586 B
withRouter.html gzip 568 B 568 B
Overall change 1.73 kB 1.73 kB
Commit: 37c74bf

@ijjk ijjk merged commit 226e81c into vercel:canary Jul 7, 2021
kodiakhq bot pushed a commit that referenced this pull request Jul 8, 2021
… applicable (#26998)

Since we are no longer accepting new built-in loaders, users may wish to use a different cloud provider.

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

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

- Follow up to #26847 
- Fixes #21079 
- Fixes #19612 
- Related to #26850
flybayer pushed a commit to blitz-js/next.js that referenced this pull request Aug 19, 2021
* add support for static loader

* update existing test

* add test

* add prettier-ignore

* update docs

* apply suggestions from review

* remove un-needed normalize

* Apply suggestions from code review

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

* update test

Co-authored-by: JJ Kasper <jj@jjsweb.site>
Co-authored-by: Steven <steven@ceriously.com>
flybayer pushed a commit to blitz-js/next.js that referenced this pull request Aug 19, 2021
… applicable (vercel#26998)

Since we are no longer accepting new built-in loaders, users may wish to use a different cloud provider.

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

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

- Follow up to vercel#26847 
- Fixes vercel#21079 
- Fixes vercel#19612 
- Related to vercel#26850
@vercel vercel locked as resolved and limited conversation to collaborators Jan 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants