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

Fix image related link prop warning with react 18 beta #31895

Merged
merged 6 commits into from
Nov 30, 2021

Conversation

huozhi
Copy link
Member

@huozhi huozhi commented Nov 28, 2021

Bug

Fixes #31892

react 18: requires camelcase for those props

Warning: Invalid DOM property `imagesrcset`. Did you mean `imageSrcSet`

react 17: requires lowercase for those props

Warning: React does not recognize the `imageSrcSet` prop on a DOM element.
  • Related issues linked using fixes #number
  • Integration tests added
  • Errors have helpful link attached, see contributing.md

Utils

  • Add command yarn next-react-18 test/integration/any-react-18-app/
  • Add util withReact18
const withReact18 = require('../../react-18/test/with-react-18')

module.exports = withReact18({
  experimental: {
    concurrentFeatures: true,
  },
})

@ijjk ijjk added created-by: Next.js team PRs by the Next.js team. type: next labels Nov 28, 2021
@huozhi huozhi changed the title Fix/camel case prop Fix image related link prop warning with react 18 beta Nov 28, 2021
@ijjk

This comment has been minimized.

@huozhi huozhi marked this pull request as ready for review November 28, 2021 22:40
@ijjk

This comment has been minimized.

@ijjk
Copy link
Member

ijjk commented Nov 28, 2021

Failing test suites

Commit: f90fd22

test/integration/react-18/test/index.test.js

  • React 18 Support > Use legacy render > supported version of react in dev
  • React 18 Support > Use legacy render > supported version of react in build
  • React 18 Support > Use legacy render > suspense is not allowed in blocking rendering mode (prod)
Expand output

● React 18 Support › Use legacy render › supported version of react in dev

expect(received).not.toMatch(expected)

Expected substring: not "Using the createRoot API for React"
Received string:        "ready - started server on 0.0.0.0:35311, url: http://localhost:35311
info  - Using the createRoot API for React
event - compiled client and server successfully in 3.7s (168 modules)
warn  - You have enabled experimental feature(s).
warn  - Experimental features are not covered by semver, and may cause unexpected or broken application behavior. Use them at your own risk.

warn  - You have to use React 18 to use `experimental.reactRoot`.
"

  59 |
  60 | describe('React 18 Support', () => {
> 61 |   describe('Use legacy render', () => {
     |                                ^
  62 |     beforeAll(async () => {
  63 |       await fs.remove(join(appDir, 'node_modules'))
  64 |       nextConfig.replace('reactRoot: true', '// reactRoot: true')

  at Object.<anonymous> (integration/react-18/test/index.test.js:61:32)

● React 18 Support › Use legacy render › supported version of react in build

expect(received).not.toMatch(expected)

Expected substring: not "Using the createRoot API for React"
Received string:        "info  - Checking validity of types...
info  - Creating an optimized production build...
info  - Using the createRoot API for React
info  - Compiled successfully
info  - Collecting page data...
info  - Generating static pages (0/9)
info  - Generating static pages (2/9)
info  - Generating static pages (4/9)
info  - Generating static pages (6/9)
info  - Generating static pages (9/9)
info  - Finalizing page optimization...

Page                                       Size     First Load JS
┌ ○ /                                      4.39 kB        79.3 kB
├   /_app                                  0 B            74.9 kB
├ ○ /404                                   195 B          75.1 kB
├ λ /ssr                                   255 B          75.1 kB
├ λ /suspense/backpressure                 411 B          75.3 kB
├ ○ /suspense/no-preload                   2.34 kB        77.2 kB
├ ○ /suspense/no-thrown                    2.37 kB        77.2 kB
├ ○ /suspense/thrown                       2.37 kB        77.2 kB
├ ○ /suspense/typing                       2.29 kB        77.2 kB
├ ○ /suspense/unwrapped                    2.3 kB         77.2 kB
└ ○ /use-id                                286 B          75.2 kB
+ First Load JS shared by all              74.9 kB
  ├ chunks/framework-09b6cbaf12e61211.js   1.89 kB
  ├ chunks/main-c899a3485de782d1.js        70.5 kB
  ├ chunks/pages/_app-b03ed3ebdb6f4317.js  1.03 kB
  └ chunks/webpack-fabc6d93ba0613c1.js     1.46 kB

λ  (Server)  server-side renders at runtime (uses getInitialProps or getServerSideProps)
○  (Static)  automatically rendered as static HTML (uses no initial props)

warn  - You have enabled experimental feature(s).
warn  - Experimental features are not covered by semver, and may cause unexpected or broken application behavior. Use them at your own risk.

warn  - The Next.js plugin was not detected in your ESLint configuration. See https://nextjs.org/docs/basic-features/eslint#migrating-existing-config
warn  - You have to use React 18 to use `experimental.reactRoot`.
"

  64 |       nextConfig.replace('reactRoot: true', '// reactRoot: true')
  65 |     })
> 66 |     afterAll(() => {
     |                     ^
  67 |       nextConfig.replace('// reactRoot: true', 'reactRoot: true')
  68 |     })
  69 |

  at Object.<anonymous> (integration/react-18/test/index.test.js:66:32)

● React 18 Support › Use legacy render › suspense is not allowed in blocking rendering mode (prod)

expect(received).toBe(expected) // Object.is equality

Expected: 1
Received: 0

  72 |       expect(output).not.toMatch(USING_CREATE_ROOT)
  73 |       expect(output).not.toMatch(UNSUPPORTED_PRERELEASE)
> 74 |     })
     |       ^
  75 |
  76 |     test('supported version of react in build', async () => {
  77 |       const output = await getBuildOutput(appDir)

  at Object.<anonymous> (integration/react-18/test/index.test.js:74:26)

@ijjk

This comment has been minimized.

@huozhi huozhi requested a review from ijjk November 30, 2021 17:21
@ijjk

This comment has been minimized.

@ijjk
Copy link
Member

ijjk commented Nov 30, 2021

Stats from current PR

Default Build (Increase detected ⚠️)
General Overall increase ⚠️
vercel/next.js canary huozhi/next.js fix/camel-case-prop Change
buildDuration 20.7s 21.3s ⚠️ +644ms
buildDurationCached 3.9s 3.9s ⚠️ +71ms
nodeModulesSize 347 MB 347 MB ⚠️ +503 B
Page Load Tests Overall decrease ⚠️
vercel/next.js canary huozhi/next.js fix/camel-case-prop Change
/ failed reqs 0 0
/ total time (seconds) 3.394 3.42 ⚠️ +0.03
/ avg req/sec 736.58 730.91 ⚠️ -5.67
/error-in-render failed reqs 0 0
/error-in-render total time (seconds) 1.574 1.602 ⚠️ +0.03
/error-in-render avg req/sec 1588.31 1560.07 ⚠️ -28.24
Client Bundles (main, webpack, commons)
vercel/next.js canary huozhi/next.js fix/camel-case-prop Change
450.HASH.js gzip 179 B 179 B
framework-HASH.js gzip 42.2 kB 42.2 kB
main-HASH.js gzip 28.4 kB 28.4 kB
webpack-HASH.js gzip 1.45 kB 1.45 kB
Overall change 72.3 kB 72.3 kB
Legacy Client Bundles (polyfills)
vercel/next.js canary huozhi/next.js fix/camel-case-prop Change
polyfills-HASH.js gzip 31 kB 31 kB
Overall change 31 kB 31 kB
Client Pages Overall increase ⚠️
vercel/next.js canary huozhi/next.js fix/camel-case-prop Change
_app-HASH.js gzip 1.37 kB 1.37 kB
_error-HASH.js gzip 194 B 194 B
amp-HASH.js gzip 312 B 312 B
css-HASH.js gzip 326 B 326 B
dynamic-HASH.js gzip 2.38 kB 2.38 kB
head-HASH.js gzip 350 B 350 B
hooks-HASH.js gzip 635 B 635 B
image-HASH.js gzip 4.45 kB 4.49 kB ⚠️ +45 B
index-HASH.js gzip 263 B 263 B
link-HASH.js gzip 1.87 kB 1.87 kB
routerDirect..HASH.js gzip 321 B 321 B
script-HASH.js gzip 383 B 383 B
withRouter-HASH.js gzip 318 B 318 B
85e02e95b279..7e3.css gzip 107 B 107 B
Overall change 13.3 kB 13.3 kB ⚠️ +45 B
Client Build Manifests
vercel/next.js canary huozhi/next.js fix/camel-case-prop Change
_buildManifest.js gzip 460 B 460 B
Overall change 460 B 460 B
Rendered Page Sizes
vercel/next.js canary huozhi/next.js fix/camel-case-prop Change
index.html gzip 532 B 532 B
link.html gzip 546 B 546 B
withRouter.html gzip 527 B 527 B
Overall change 1.6 kB 1.6 kB

Diffs

Diff for _buildManifest.js
@@ -12,7 +12,7 @@ self.__BUILD_MANIFEST = {
   ],
   "/head": ["static\u002Fchunks\u002Fpages\u002Fhead-7100d3b2a548f0e4.js"],
   "/hooks": ["static\u002Fchunks\u002Fpages\u002Fhooks-ff60bc61acd2698b.js"],
-  "/image": ["static\u002Fchunks\u002Fpages\u002Fimage-91f7c5ff8695376c.js"],
+  "/image": ["static\u002Fchunks\u002Fpages\u002Fimage-f207079640969086.js"],
   "/link": ["static\u002Fchunks\u002Fpages\u002Flink-678af336607f5345.js"],
   "/routerDirect": [
     "static\u002Fchunks\u002Fpages\u002FrouterDirect-76232dd6bc335a24.js"
Diff for image-HASH.js
@@ -37,6 +37,19 @@
           return arr2;
         }
       }
+      function _defineProperty(obj, key, value) {
+        if (key in obj) {
+          Object.defineProperty(obj, key, {
+            value: value,
+            enumerable: true,
+            configurable: true,
+            writable: true
+          });
+        } else {
+          obj[key] = value;
+        }
+        return obj;
+      }
       function _iterableToArray(iter) {
         if (
           Symbol.iterator in Object(iter) ||
@@ -101,7 +114,7 @@
       var _toBase64 = __webpack_require__(6978);
       var _imageConfig = __webpack_require__(5809);
       var _useIntersection = __webpack_require__(7190);
-      function _defineProperty(obj, key, value) {
+      function _defineProperty1(obj, key, value) {
         if (key in obj) {
           Object.defineProperty(obj, key, {
             value: value,
@@ -137,7 +150,7 @@
               );
             }
             ownKeys.forEach(function(key) {
-              _defineProperty(target, key, source[key]);
+              _defineProperty1(target, key, source[key]);
             });
           };
         for (var i = 1; i < arguments.length; i++) _loop(i);
@@ -403,6 +416,7 @@
           img.onload = handleLoad;
         }
       }
+      var _obj;
       function Image(_param) {
         var src = _param.src,
           sizes = _param.sizes,
@@ -624,6 +638,15 @@
         if (false) {
           var fullUrl;
         }
+        var imageSrcSetPropName = "imagesrcset";
+        var imageSizesPropName = "imagesizes";
+        if (false) {
+        }
+        var linkProps =
+          ((_obj = {}), // Note: imagesrcset and imagesizes are not in the link element type with react 17.
+          _defineProperty(_obj, imageSrcSetPropName, imgAttributes.srcSet),
+          _defineProperty(_obj, imageSizesPropName, imgAttributes.sizes),
+          _obj);
         return /*#__PURE__*/ _react.default.createElement(
           "span",
           {
@@ -711,20 +734,22 @@
               /*#__PURE__*/ _react.default.createElement(
                 _head.default,
                 null,
-                /*#__PURE__*/ _react.default.createElement("link", {
-                  key:
-                    "__nimg-" +
-                    imgAttributes.src +
-                    imgAttributes.srcSet +
-                    imgAttributes.sizes,
-                  rel: "preload",
-                  as: "image",
-                  href: imgAttributes.srcSet ? undefined : imgAttributes.src,
-                  // @ts-ignore: imagesrcset is not yet in the link element type.
-                  imagesrcset: imgAttributes.srcSet,
-                  // @ts-ignore: imagesizes is not yet in the link element type.
-                  imagesizes: imgAttributes.sizes
-                })
+                /*#__PURE__*/ _react.default.createElement(
+                  "link",
+                  Object.assign(
+                    {
+                      key:
+                        "__nimg-" +
+                        imgAttributes.src +
+                        imgAttributes.srcSet +
+                        imgAttributes.sizes,
+                      rel: "preload",
+                      as: "image",
+                      href: imgAttributes.srcSet ? undefined : imgAttributes.src
+                    },
+                    linkProps
+                  )
+                )
               )
             : null
         );

Default Build with SWC (Increase detected ⚠️)
General Overall increase ⚠️
vercel/next.js canary huozhi/next.js fix/camel-case-prop Change
buildDuration 23.4s 23.9s ⚠️ +456ms
buildDurationCached 4s 3.9s -131ms
nodeModulesSize 347 MB 347 MB ⚠️ +503 B
Page Load Tests Overall decrease ⚠️
vercel/next.js canary huozhi/next.js fix/camel-case-prop Change
/ failed reqs 0 0
/ total time (seconds) 3.552 3.529 -0.02
/ avg req/sec 703.84 708.42 +4.58
/error-in-render failed reqs 0 0
/error-in-render total time (seconds) 1.606 1.693 ⚠️ +0.09
/error-in-render avg req/sec 1556.57 1476.28 ⚠️ -80.29
Client Bundles (main, webpack, commons)
vercel/next.js canary huozhi/next.js fix/camel-case-prop Change
450.HASH.js gzip 179 B 179 B
framework-HASH.js gzip 42.3 kB 42.3 kB
main-HASH.js gzip 28.6 kB 28.6 kB
webpack-HASH.js gzip 1.44 kB 1.44 kB
Overall change 72.5 kB 72.5 kB
Legacy Client Bundles (polyfills)
vercel/next.js canary huozhi/next.js fix/camel-case-prop Change
polyfills-HASH.js gzip 31 kB 31 kB
Overall change 31 kB 31 kB
Client Pages Overall increase ⚠️
vercel/next.js canary huozhi/next.js fix/camel-case-prop Change
_app-HASH.js gzip 1.35 kB 1.35 kB
_error-HASH.js gzip 180 B 180 B
amp-HASH.js gzip 305 B 305 B
css-HASH.js gzip 321 B 321 B
dynamic-HASH.js gzip 2.37 kB 2.37 kB
head-HASH.js gzip 342 B 342 B
hooks-HASH.js gzip 622 B 622 B
image-HASH.js gzip 4.47 kB 4.53 kB ⚠️ +62 B
index-HASH.js gzip 256 B 256 B
link-HASH.js gzip 1.91 kB 1.91 kB
routerDirect..HASH.js gzip 314 B 314 B
script-HASH.js gzip 375 B 375 B
withRouter-HASH.js gzip 309 B 309 B
85e02e95b279..7e3.css gzip 107 B 107 B
Overall change 13.2 kB 13.3 kB ⚠️ +62 B
Client Build Manifests Overall decrease ✓
vercel/next.js canary huozhi/next.js fix/camel-case-prop Change
_buildManifest.js gzip 459 B 458 B -1 B
Overall change 459 B 458 B -1 B
Rendered Page Sizes
vercel/next.js canary huozhi/next.js fix/camel-case-prop Change
index.html gzip 533 B 533 B
link.html gzip 545 B 545 B
withRouter.html gzip 526 B 526 B
Overall change 1.6 kB 1.6 kB

Diffs

Diff for _buildManifest.js
@@ -12,7 +12,7 @@ self.__BUILD_MANIFEST = {
   ],
   "/head": ["static\u002Fchunks\u002Fpages\u002Fhead-7100d3b2a548f0e4.js"],
   "/hooks": ["static\u002Fchunks\u002Fpages\u002Fhooks-ff60bc61acd2698b.js"],
-  "/image": ["static\u002Fchunks\u002Fpages\u002Fimage-91f7c5ff8695376c.js"],
+  "/image": ["static\u002Fchunks\u002Fpages\u002Fimage-f207079640969086.js"],
   "/link": ["static\u002Fchunks\u002Fpages\u002Flink-678af336607f5345.js"],
   "/routerDirect": [
     "static\u002Fchunks\u002Fpages\u002FrouterDirect-76232dd6bc335a24.js"
Diff for image-HASH.js
@@ -37,6 +37,19 @@
           return arr2;
         }
       }
+      function _defineProperty(obj, key, value) {
+        if (key in obj) {
+          Object.defineProperty(obj, key, {
+            value: value,
+            enumerable: true,
+            configurable: true,
+            writable: true
+          });
+        } else {
+          obj[key] = value;
+        }
+        return obj;
+      }
       function _iterableToArray(iter) {
         if (
           Symbol.iterator in Object(iter) ||
@@ -101,7 +114,7 @@
       var _toBase64 = __webpack_require__(6978);
       var _imageConfig = __webpack_require__(5809);
       var _useIntersection = __webpack_require__(7190);
-      function _defineProperty(obj, key, value) {
+      function _defineProperty1(obj, key, value) {
         if (key in obj) {
           Object.defineProperty(obj, key, {
             value: value,
@@ -137,7 +150,7 @@
               );
             }
             ownKeys.forEach(function(key) {
-              _defineProperty(target, key, source[key]);
+              _defineProperty1(target, key, source[key]);
             });
           };
         for (var i = 1; i < arguments.length; i++) _loop(i);
@@ -403,6 +416,7 @@
           img.onload = handleLoad;
         }
       }
+      var _obj;
       function Image(_param) {
         var src = _param.src,
           sizes = _param.sizes,
@@ -624,6 +638,15 @@
         if (false) {
           var fullUrl;
         }
+        var imageSrcSetPropName = "imagesrcset";
+        var imageSizesPropName = "imagesizes";
+        if (false) {
+        }
+        var linkProps =
+          ((_obj = {}), // Note: imagesrcset and imagesizes are not in the link element type with react 17.
+          _defineProperty(_obj, imageSrcSetPropName, imgAttributes.srcSet),
+          _defineProperty(_obj, imageSizesPropName, imgAttributes.sizes),
+          _obj);
         return /*#__PURE__*/ _react.default.createElement(
           "span",
           {
@@ -711,20 +734,22 @@
               /*#__PURE__*/ _react.default.createElement(
                 _head.default,
                 null,
-                /*#__PURE__*/ _react.default.createElement("link", {
-                  key:
-                    "__nimg-" +
-                    imgAttributes.src +
-                    imgAttributes.srcSet +
-                    imgAttributes.sizes,
-                  rel: "preload",
-                  as: "image",
-                  href: imgAttributes.srcSet ? undefined : imgAttributes.src,
-                  // @ts-ignore: imagesrcset is not yet in the link element type.
-                  imagesrcset: imgAttributes.srcSet,
-                  // @ts-ignore: imagesizes is not yet in the link element type.
-                  imagesizes: imgAttributes.sizes
-                })
+                /*#__PURE__*/ _react.default.createElement(
+                  "link",
+                  Object.assign(
+                    {
+                      key:
+                        "__nimg-" +
+                        imgAttributes.src +
+                        imgAttributes.srcSet +
+                        imgAttributes.sizes,
+                      rel: "preload",
+                      as: "image",
+                      href: imgAttributes.srcSet ? undefined : imgAttributes.src
+                    },
+                    linkProps
+                  )
+                )
               )
             : null
         );
Commit: 2948af9

@kodiakhq kodiakhq bot merged commit d2cef24 into vercel:canary Nov 30, 2021
@vercel vercel locked as resolved and limited conversation to collaborators Jan 27, 2022
@huozhi huozhi deleted the fix/camel-case-prop branch February 3, 2022 12:01
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Warning: Invalid DOM property imagesizes. Did you mean imageSizes?
2 participants