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: Do not omit alt on getImgProps return type, ImgProps #70608

Merged

Conversation

icyJoseph
Copy link
Contributor

What?

Small type tweak, asked for in #70443

Why?

The alt prop is required on the call to getImgProps, and the implementation, returns it back to the caller, however, the type signature of the return type for getImgProps, omits the alt prop, which means that users have to manually apply the alt prop.

That is to say, that in this example, tweaked from the docs:

import { getImageProps } from 'next/image'
 
export default function Page() {
  const common = { alt: 'Theme Example', width: 800, height: 400 }
  const {
    props: { srcSet: dark },
  } = getImageProps({ ...common, src: '/dark.png' })
  const {
    props: { srcSet: light, ...rest },
  } = getImageProps({ ...common, src: '/light.png' })
 
  return (
    <picture>
      <source media="(prefers-color-scheme: dark)" srcSet={dark} />
      <source media="(prefers-color-scheme: light)" srcSet={light} />
      {/* the alt prop is here, but as far as TypeScript is concerned, it is not */}
      <SomeCustomImageComponent {...rest} /> 
    </picture>
  )
}

So users have to do:

      <SomeCustomImageComponent {...rest} alt={common.alt} /> 

See more at, #70443

How?

Remove alt from the Omit union.

export type ImgProps = Omit<ImageProps, 'src'  | 'alt' | 'loader'> & { /* other stuff */ }

Fixes #70443

@ijjk
Copy link
Member

ijjk commented Sep 30, 2024

Allow CI Workflow Run

  • approve CI run for commit: 093283c

Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer

Copy link
Member

@ijjk ijjk left a comment

Choose a reason for hiding this comment

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

Hi, could we add a test case where this is failing without the change?

@icyJoseph
Copy link
Contributor Author

Are you thinking something like:

import { getImageProps } from 'next/image'

test('alt text from getImageProps', () => {
  const common = { alt: 'Theme Example', width: 800, height: 400 }
  const { props } = getImageProps({ ...common, src: '/example.png' })

  expect(props.alt).toBe(common.alt)
})

Which ensures that getImageProps, returns alt text, as defined by its return type?

@ijjk
Copy link
Member

ijjk commented Oct 1, 2024

A full example showing how you mean for it to be used in an integration test would be more ideal so we capture use case

@styfle
Copy link
Member

styfle commented Oct 2, 2024

however, the type signature of the return type for getImgProps, omits the alt prop

Is this just a TS type issue? If so then you can probably update an existing TS test to confirm it fails and that your PR fixes it. Here's an example:

it('should return props in correct order', async () => {

You can copy/pasta that test and call the new one should have correct types for props and change the single assertion on Object.entries() to multiple assertions on props.alt, props.id, etc.

@icyJoseph
Copy link
Contributor Author

Good suggestion! So without the changes of this PR, having a test such as:

    const { props } = getImageProps({
      alt: 'a nice desc',
      id: 'my-image',
      src: '/test.png',
      width: 100,
      height: 200,
    })

    expect(props.alt).toBeString()
    expect(props.id).toBeString()
    // rest of type expectations

Causes this TS error, at IDE/text-editor level:

Screenshot 2024-10-02 at 21 36 10

Does the repository have any type testing tool installed? Otherwise, I guess, this is alright, and, though the test run (pnpm test) doesn't seem to evaluate types, the pnpm typescript command does catch it:

pnpm typescript

> nextjs-project@0.0.0 typescript /Users/joseph/dev-exp/next.js
> tsc --noEmit

test/unit/next-image-get-img-props.test.ts:50:18 - error TS2339: Property 'alt' does not exist on type 'ImgProps'.

50     expect(props.alt).toBeString()
                    ~~~

Re-applying the fix, clears the text editor error highlight and the output of pnpm typescript

@ijjk ijjk added the tests label Oct 2, 2024
@ijjk
Copy link
Member

ijjk commented Oct 2, 2024

Tests Passed

@styfle
Copy link
Member

styfle commented Oct 2, 2024

the pnpm typescript command does catch it

I'm fine with that since it that command should already run in CI 👍

@ijjk
Copy link
Member

ijjk commented Oct 2, 2024

Stats from current PR

Default Build (Increase detected ⚠️)
General Overall increase ⚠️
vercel/next.js canary icyJoseph/next.js fix/typescript-get-img-props-alt-text Change
buildDuration 17.7s 18.9s ⚠️ +1.2s
buildDurationCached 15.4s 13.2s N/A
nodeModulesSize 369 MB 371 MB ⚠️ +1.7 MB
nextStartRea..uration (ms) 432ms 415ms N/A
Client Bundles (main, webpack)
vercel/next.js canary icyJoseph/next.js fix/typescript-get-img-props-alt-text Change
1623-HASH.js gzip 41.9 kB 41.8 kB N/A
3383-HASH.js gzip 5.26 kB 5.25 kB N/A
5952.HASH.js gzip 169 B 169 B
946e5feb-HASH.js gzip 52.8 kB 52.8 kB
framework-HASH.js gzip 57.5 kB 57.5 kB N/A
main-app-HASH.js gzip 231 B 228 B N/A
main-HASH.js gzip 32.7 kB 32.7 kB N/A
webpack-HASH.js gzip 1.71 kB 1.71 kB N/A
Overall change 52.9 kB 52.9 kB
Legacy Client Bundles (polyfills)
vercel/next.js canary icyJoseph/next.js fix/typescript-get-img-props-alt-text Change
polyfills-HASH.js gzip 39.4 kB 39.4 kB
Overall change 39.4 kB 39.4 kB
Client Pages
vercel/next.js canary icyJoseph/next.js fix/typescript-get-img-props-alt-text Change
_app-HASH.js gzip 193 B 193 B
_error-HASH.js gzip 191 B 192 B N/A
amp-HASH.js gzip 512 B 512 B
css-HASH.js gzip 343 B 343 B
dynamic-HASH.js gzip 1.84 kB 1.84 kB N/A
edge-ssr-HASH.js gzip 265 B 265 B
head-HASH.js gzip 364 B 365 B N/A
hooks-HASH.js gzip 390 B 391 B N/A
image-HASH.js gzip 4.41 kB 4.4 kB N/A
index-HASH.js gzip 268 B 267 B N/A
link-HASH.js gzip 2.78 kB 2.78 kB N/A
routerDirect..HASH.js gzip 326 B 327 B N/A
script-HASH.js gzip 395 B 397 B N/A
withRouter-HASH.js gzip 323 B 322 B N/A
1afbb74e6ecf..834.css gzip 106 B 106 B
Overall change 1.42 kB 1.42 kB
Client Build Manifests
vercel/next.js canary icyJoseph/next.js fix/typescript-get-img-props-alt-text Change
_buildManifest.js gzip 749 B 748 B N/A
Overall change 0 B 0 B
Rendered Page Sizes
vercel/next.js canary icyJoseph/next.js fix/typescript-get-img-props-alt-text Change
index.html gzip 524 B 523 B N/A
link.html gzip 538 B 536 B N/A
withRouter.html gzip 520 B 517 B N/A
Overall change 0 B 0 B
Edge SSR bundle Size
vercel/next.js canary icyJoseph/next.js fix/typescript-get-img-props-alt-text Change
edge-ssr.js gzip 129 kB 129 kB N/A
page.js gzip 184 kB 181 kB N/A
Overall change 0 B 0 B
Middleware size
vercel/next.js canary icyJoseph/next.js fix/typescript-get-img-props-alt-text Change
middleware-b..fest.js gzip 671 B 668 B N/A
middleware-r..fest.js gzip 156 B 155 B N/A
middleware.js gzip 30 kB 30 kB N/A
edge-runtime..pack.js gzip 844 B 844 B
Overall change 844 B 844 B
Next Runtimes Overall increase ⚠️
vercel/next.js canary icyJoseph/next.js fix/typescript-get-img-props-alt-text Change
973-experime...dev.js gzip 322 B 322 B
973.runtime.dev.js gzip 314 B 314 B
app-page-exp...dev.js gzip 309 kB 319 kB ⚠️ +10.2 kB
app-page-exp..prod.js gzip 118 kB 126 kB ⚠️ +7.65 kB
app-page-tur..prod.js gzip 132 kB 139 kB ⚠️ +7.72 kB
app-page-tur..prod.js gzip 127 kB 134 kB ⚠️ +7.68 kB
app-page.run...dev.js gzip 299 kB 309 kB ⚠️ +10.2 kB
app-page.run..prod.js gzip 114 kB 122 kB ⚠️ +7.66 kB
app-route-ex...dev.js gzip 33.8 kB 34.1 kB ⚠️ +276 B
app-route-ex..prod.js gzip 22.7 kB 22.7 kB N/A
app-route-tu..prod.js gzip 22.7 kB 22.7 kB N/A
app-route-tu..prod.js gzip 22.4 kB 22.4 kB N/A
app-route.ru...dev.js gzip 35.5 kB 35.8 kB ⚠️ +271 B
app-route.ru..prod.js gzip 22.4 kB 22.4 kB N/A
pages-api-tu..prod.js gzip 9.62 kB 9.62 kB
pages-api.ru...dev.js gzip 11.5 kB 11.5 kB
pages-api.ru..prod.js gzip 9.61 kB 9.61 kB
pages-turbo...prod.js gzip 20.9 kB 20.9 kB N/A
pages.runtim...dev.js gzip 26.5 kB 26.5 kB N/A
pages.runtim..prod.js gzip 20.9 kB 20.9 kB N/A
server.runti..prod.js gzip 57.5 kB 57.4 kB N/A
Overall change 1.2 MB 1.25 MB ⚠️ +51.6 kB
build cache
vercel/next.js canary icyJoseph/next.js fix/typescript-get-img-props-alt-text Change
0.pack gzip 1.81 MB 1.67 MB N/A
index.pack gzip 139 kB 131 kB N/A
Overall change 0 B 0 B
Diff details
Diff for page.js

Diff too large to display

Diff for middleware.js

Diff too large to display

Diff for edge-ssr.js

Diff too large to display

Diff for dynamic-HASH.js
@@ -1,7 +1,7 @@
 (self["webpackChunk_N_E"] = self["webpackChunk_N_E"] || []).push([
   [2739],
   {
-    /***/ 1543: /***/ (
+    /***/ 2307: /***/ (
       __unused_webpack_module,
       __unused_webpack_exports,
       __webpack_require__
@@ -9,7 +9,7 @@
       (window.__NEXT_P = window.__NEXT_P || []).push([
         "/dynamic",
         function () {
-          return __webpack_require__(1872);
+          return __webpack_require__(4622);
         },
       ]);
       if (false) {
@@ -18,7 +18,7 @@
       /***/
     },
 
-    /***/ 7703: /***/ (module, exports, __webpack_require__) => {
+    /***/ 588: /***/ (module, exports, __webpack_require__) => {
       "use strict";
 
       Object.defineProperty(exports, "__esModule", {
@@ -51,7 +51,7 @@
         __webpack_require__(4630)
       );
       const _loadablesharedruntime = /*#__PURE__*/ _interop_require_default._(
-        __webpack_require__(1264)
+        __webpack_require__(6443)
       );
       const isServerSide = "object" === "undefined";
       // Normalize loader to return the module as form { default: Component } for `React.lazy`.
@@ -152,11 +152,7 @@
       /***/
     },
 
-    /***/ 7264: /***/ (
-      __unused_webpack_module,
-      exports,
-      __webpack_require__
-    ) => {
+    /***/ 55: /***/ (__unused_webpack_module, exports, __webpack_require__) => {
       "use strict";
       /* __next_internal_client_entry_do_not_use__  cjs */
       Object.defineProperty(exports, "__esModule", {
@@ -179,7 +175,7 @@
       /***/
     },
 
-    /***/ 1264: /***/ (
+    /***/ 6443: /***/ (
       __unused_webpack_module,
       exports,
       __webpack_require__
@@ -221,7 +217,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
       const _react = /*#__PURE__*/ _interop_require_default._(
         __webpack_require__(4630)
       );
-      const _loadablecontextsharedruntime = __webpack_require__(7264);
+      const _loadablecontextsharedruntime = __webpack_require__(55);
       function resolve(obj) {
         return obj && obj.default ? obj.default : obj;
       }
@@ -456,7 +452,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
       /***/
     },
 
-    /***/ 1872: /***/ (
+    /***/ 4622: /***/ (
       __unused_webpack_module,
       __webpack_exports__,
       __webpack_require__
@@ -471,7 +467,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
       /* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__ =
         __webpack_require__(4893);
       /* harmony import */ var next_dynamic__WEBPACK_IMPORTED_MODULE_1__ =
-        __webpack_require__(2171);
+        __webpack_require__(7321);
       /* harmony import */ var next_dynamic__WEBPACK_IMPORTED_MODULE_1___default =
         /*#__PURE__*/ __webpack_require__.n(
           next_dynamic__WEBPACK_IMPORTED_MODULE_1__
@@ -480,12 +476,12 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
       const DynamicHello = next_dynamic__WEBPACK_IMPORTED_MODULE_1___default()(
         () =>
           __webpack_require__
-            .e(/* import() */ 5952)
-            .then(__webpack_require__.bind(__webpack_require__, 5952))
+            .e(/* import() */ 3404)
+            .then(__webpack_require__.bind(__webpack_require__, 3404))
             .then((mod) => mod.Hello),
         {
           loadableGenerated: {
-            webpack: () => [/*require.resolve*/ 5952],
+            webpack: () => [/*require.resolve*/ 3404],
           },
         }
       );
@@ -512,12 +508,12 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
       /***/
     },
 
-    /***/ 2171: /***/ (
+    /***/ 7321: /***/ (
       module,
       __unused_webpack_exports,
       __webpack_require__
     ) => {
-      module.exports = __webpack_require__(7703);
+      module.exports = __webpack_require__(588);
 
       /***/
     },
@@ -527,7 +523,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
     /******/ var __webpack_exec__ = (moduleId) =>
       __webpack_require__((__webpack_require__.s = moduleId));
     /******/ __webpack_require__.O(0, [2888, 9774, 179], () =>
-      __webpack_exec__(1543)
+      __webpack_exec__(2307)
     );
     /******/ var __webpack_exports__ = __webpack_require__.O();
     /******/ _N_E = __webpack_exports__;
Diff for image-HASH.js
@@ -1,7 +1,7 @@
 (self["webpackChunk_N_E"] = self["webpackChunk_N_E"] || []).push([
   [8358],
   {
-    /***/ 7478: /***/ (
+    /***/ 994: /***/ (
       __unused_webpack_module,
       __unused_webpack_exports,
       __webpack_require__
@@ -9,7 +9,7 @@
       (window.__NEXT_P = window.__NEXT_P || []).push([
         "/image",
         function () {
-          return __webpack_require__(519);
+          return __webpack_require__(3167);
         },
       ]);
       if (false) {
@@ -18,7 +18,7 @@
       /***/
     },
 
-    /***/ 8397: /***/ (module, exports, __webpack_require__) => {
+    /***/ 3394: /***/ (module, exports, __webpack_require__) => {
       "use strict";
       /* __next_internal_client_entry_do_not_use__  cjs */
       Object.defineProperty(exports, "__esModule", {
@@ -40,17 +40,17 @@
         __webpack_require__(5545)
       );
       const _head = /*#__PURE__*/ _interop_require_default._(
-        __webpack_require__(3681)
+        __webpack_require__(5328)
       );
-      const _getimgprops = __webpack_require__(4550);
-      const _imageconfig = __webpack_require__(2064);
-      const _imageconfigcontextsharedruntime = __webpack_require__(5889);
-      const _warnonce = __webpack_require__(4748);
-      const _routercontextsharedruntime = __webpack_require__(5563);
+      const _getimgprops = __webpack_require__(4657);
+      const _imageconfig = __webpack_require__(240);
+      const _imageconfigcontextsharedruntime = __webpack_require__(8335);
+      const _warnonce = __webpack_require__(7134);
+      const _routercontextsharedruntime = __webpack_require__(1941);
       const _imageloader = /*#__PURE__*/ _interop_require_default._(
-        __webpack_require__(9287)
+        __webpack_require__(7771)
       );
-      const _usemergedref = __webpack_require__(8186);
+      const _usemergedref = __webpack_require__(6875);
       // This is replaced by webpack define plugin
       const configEnv = {
         deviceSizes: [640, 750, 828, 1080, 1200, 1920, 2048, 3840],
@@ -371,7 +371,7 @@
       /***/
     },
 
-    /***/ 8186: /***/ (module, exports, __webpack_require__) => {
+    /***/ 6875: /***/ (module, exports, __webpack_require__) => {
       "use strict";
 
       Object.defineProperty(exports, "__esModule", {
@@ -432,7 +432,7 @@
       /***/
     },
 
-    /***/ 4550: /***/ (
+    /***/ 4657: /***/ (
       __unused_webpack_module,
       exports,
       __webpack_require__
@@ -448,9 +448,9 @@
           return getImgProps;
         },
       });
-      const _warnonce = __webpack_require__(4748);
-      const _imageblursvg = __webpack_require__(3682);
-      const _imageconfig = __webpack_require__(2064);
+      const _warnonce = __webpack_require__(7134);
+      const _imageblursvg = __webpack_require__(444);
+      const _imageconfig = __webpack_require__(240);
       const VALID_LOADING_VALUES =
         /* unused pure expression or super */ null && [
           "lazy",
@@ -823,7 +823,7 @@
       /***/
     },
 
-    /***/ 3682: /***/ (__unused_webpack_module, exports) => {
+    /***/ 444: /***/ (__unused_webpack_module, exports) => {
       "use strict";
       /**
        * A shared function, used on both client and server, to generate a SVG blur placeholder.
@@ -878,7 +878,7 @@
       /***/
     },
 
-    /***/ 6081: /***/ (
+    /***/ 1078: /***/ (
       __unused_webpack_module,
       exports,
       __webpack_require__
@@ -905,10 +905,10 @@
         },
       });
       const _interop_require_default = __webpack_require__(9608);
-      const _getimgprops = __webpack_require__(4550);
-      const _imagecomponent = __webpack_require__(8397);
+      const _getimgprops = __webpack_require__(4657);
+      const _imagecomponent = __webpack_require__(3394);
       const _imageloader = /*#__PURE__*/ _interop_require_default._(
-        __webpack_require__(9287)
+        __webpack_require__(7771)
       );
       function getImageProps(imgProps) {
         const { props } = (0, _getimgprops.getImgProps)(imgProps, {
@@ -940,7 +940,7 @@
       /***/
     },
 
-    /***/ 9287: /***/ (__unused_webpack_module, exports) => {
+    /***/ 7771: /***/ (__unused_webpack_module, exports) => {
       "use strict";
 
       Object.defineProperty(exports, "__esModule", {
@@ -975,7 +975,7 @@
       /***/
     },
 
-    /***/ 519: /***/ (
+    /***/ 3167: /***/ (
       __unused_webpack_module,
       __webpack_exports__,
       __webpack_require__
@@ -992,8 +992,8 @@
 
       // EXTERNAL MODULE: ./node_modules/.pnpm/react@19.0.0-rc-3edc000d-20240926/node_modules/react/jsx-runtime.js
       var jsx_runtime = __webpack_require__(4893);
-      // EXTERNAL MODULE: ./node_modules/.pnpm/next@file+..+main-repo+packages+next+next-packed.tgz_react-dom@19.0.0-rc-3edc000d-20240926_re_okha6m53pf4dodtmle7pje5faa/node_modules/next/image.js
-      var next_image = __webpack_require__(4038);
+      // EXTERNAL MODULE: ./node_modules/.pnpm/next@file+..+diff-repo+packages+next+next-packed.tgz_react-dom@19.0.0-rc-3edc000d-20240926_re_ixusczm6ngtdvmbk5ko4spdqvu/node_modules/next/image.js
+      var next_image = __webpack_require__(1005);
       var image_default = /*#__PURE__*/ __webpack_require__.n(next_image); // CONCATENATED MODULE: ./pages/nextjs.png
       /* harmony default export */ const nextjs = {
         src: "/_next/static/media/nextjs.cae0b805.png",
@@ -1023,12 +1023,12 @@
       /***/
     },
 
-    /***/ 4038: /***/ (
+    /***/ 1005: /***/ (
       module,
       __unused_webpack_exports,
       __webpack_require__
     ) => {
-      module.exports = __webpack_require__(6081);
+      module.exports = __webpack_require__(1078);
 
       /***/
     },
@@ -1038,7 +1038,7 @@
     /******/ var __webpack_exec__ = (moduleId) =>
       __webpack_require__((__webpack_require__.s = moduleId));
     /******/ __webpack_require__.O(0, [2888, 9774, 179], () =>
-      __webpack_exec__(7478)
+      __webpack_exec__(994)
     );
     /******/ var __webpack_exports__ = __webpack_require__.O();
     /******/ _N_E = __webpack_exports__;
Diff for 1623-HASH.js

Diff too large to display

Diff for 3383-HASH.js
@@ -1,8 +1,8 @@
 "use strict";
 (self["webpackChunk_N_E"] = self["webpackChunk_N_E"] || []).push([
-  [3383],
+  [9378],
   {
-    /***/ 3383: /***/ (module, exports, __webpack_require__) => {
+    /***/ 9378: /***/ (module, exports, __webpack_require__) => {
       /* __next_internal_client_entry_do_not_use__  cjs */
       Object.defineProperty(exports, "__esModule", {
         value: true,
@@ -13,27 +13,27 @@
           return Image;
         },
       });
-      const _interop_require_default = __webpack_require__(6752);
-      const _interop_require_wildcard = __webpack_require__(5685);
-      const _jsxruntime = __webpack_require__(9649);
+      const _interop_require_default = __webpack_require__(9334);
+      const _interop_require_wildcard = __webpack_require__(8725);
+      const _jsxruntime = __webpack_require__(6331);
       const _react = /*#__PURE__*/ _interop_require_wildcard._(
-        __webpack_require__(8008)
+        __webpack_require__(6960)
       );
       const _reactdom = /*#__PURE__*/ _interop_require_default._(
-        __webpack_require__(3516)
+        __webpack_require__(6477)
       );
       const _head = /*#__PURE__*/ _interop_require_default._(
-        __webpack_require__(3344)
+        __webpack_require__(1321)
       );
-      const _getimgprops = __webpack_require__(6122);
-      const _imageconfig = __webpack_require__(2749);
-      const _imageconfigcontextsharedruntime = __webpack_require__(511);
-      const _warnonce = __webpack_require__(3619);
-      const _routercontextsharedruntime = __webpack_require__(5415);
+      const _getimgprops = __webpack_require__(2708);
+      const _imageconfig = __webpack_require__(9371);
+      const _imageconfigcontextsharedruntime = __webpack_require__(6362);
+      const _warnonce = __webpack_require__(647);
+      const _routercontextsharedruntime = __webpack_require__(5115);
       const _imageloader = /*#__PURE__*/ _interop_require_default._(
-        __webpack_require__(6900)
+        __webpack_require__(515)
       );
-      const _usemergedref = __webpack_require__(7562);
+      const _usemergedref = __webpack_require__(160);
       // This is replaced by webpack define plugin
       const configEnv = {
         deviceSizes: [640, 750, 828, 1080, 1200, 1920, 2048, 3840],
@@ -355,7 +355,7 @@
       /***/
     },
 
-    /***/ 7562: /***/ (module, exports, __webpack_require__) => {
+    /***/ 160: /***/ (module, exports, __webpack_require__) => {
       Object.defineProperty(exports, "__esModule", {
         value: true,
       });
@@ -365,7 +365,7 @@
           return useMergedRef;
         },
       });
-      const _react = __webpack_require__(8008);
+      const _react = __webpack_require__(6960);
       function useMergedRef(refA, refB) {
         const cleanupA = (0, _react.useRef)(() => {});
         const cleanupB = (0, _react.useRef)(() => {});
@@ -414,7 +414,7 @@
       /***/
     },
 
-    /***/ 1900: /***/ (
+    /***/ 4624: /***/ (
       __unused_webpack_module,
       exports,
       __webpack_require__
@@ -428,9 +428,9 @@
           return AmpStateContext;
         },
       });
-      const _interop_require_default = __webpack_require__(6752);
+      const _interop_require_default = __webpack_require__(9334);
       const _react = /*#__PURE__*/ _interop_require_default._(
-        __webpack_require__(8008)
+        __webpack_require__(6960)
       );
       const AmpStateContext = _react.default.createContext({});
       if (false) {
@@ -439,7 +439,7 @@
       /***/
     },
 
-    /***/ 7918: /***/ (__unused_webpack_module, exports) => {
+    /***/ 825: /***/ (__unused_webpack_module, exports) => {
       Object.defineProperty(exports, "__esModule", {
         value: true,
       });
@@ -461,7 +461,7 @@
       /***/
     },
 
-    /***/ 6122: /***/ (
+    /***/ 2708: /***/ (
       __unused_webpack_module,
       exports,
       __webpack_require__
@@ -475,9 +475,9 @@
           return getImgProps;
         },
       });
-      const _warnonce = __webpack_require__(3619);
-      const _imageblursvg = __webpack_require__(6187);
-      const _imageconfig = __webpack_require__(2749);
+      const _warnonce = __webpack_require__(647);
+      const _imageblursvg = __webpack_require__(1881);
+      const _imageconfig = __webpack_require__(9371);
       const VALID_LOADING_VALUES =
         /* unused pure expression or super */ null && [
           "lazy",
@@ -850,8 +850,8 @@
       /***/
     },
 
-    /***/ 3344: /***/ (module, exports, __webpack_require__) => {
-      /* provided dependency */ var process = __webpack_require__(9129);
+    /***/ 1321: /***/ (module, exports, __webpack_require__) => {
+      /* provided dependency */ var process = __webpack_require__(6598);
       /* __next_internal_client_entry_do_not_use__  cjs */
       Object.defineProperty(exports, "__esModule", {
         value: true,
@@ -872,19 +872,19 @@
           return defaultHead;
         },
       });
-      const _interop_require_default = __webpack_require__(6752);
-      const _interop_require_wildcard = __webpack_require__(5685);
-      const _jsxruntime = __webpack_require__(9649);
+      const _interop_require_default = __webpack_require__(9334);
+      const _interop_require_wildcard = __webpack_require__(8725);
+      const _jsxruntime = __webpack_require__(6331);
       const _react = /*#__PURE__*/ _interop_require_wildcard._(
-        __webpack_require__(8008)
+        __webpack_require__(6960)
       );
       const _sideeffect = /*#__PURE__*/ _interop_require_default._(
-        __webpack_require__(6549)
+        __webpack_require__(2016)
       );
-      const _ampcontextsharedruntime = __webpack_require__(1900);
-      const _headmanagercontextsharedruntime = __webpack_require__(7709);
-      const _ampmode = __webpack_require__(7918);
-      const _warnonce = __webpack_require__(3619);
+      const _ampcontextsharedruntime = __webpack_require__(4624);
+      const _headmanagercontextsharedruntime = __webpack_require__(4104);
+      const _ampmode = __webpack_require__(825);
+      const _warnonce = __webpack_require__(647);
       function defaultHead(inAmpMode) {
         if (inAmpMode === void 0) inAmpMode = false;
         const head = [
@@ -1068,7 +1068,7 @@
       /***/
     },
 
-    /***/ 6187: /***/ (__unused_webpack_module, exports) => {
+    /***/ 1881: /***/ (__unused_webpack_module, exports) => {
       /**
        * A shared function, used on both client and server, to generate a SVG blur placeholder.
        */
@@ -1122,7 +1122,7 @@
       /***/
     },
 
-    /***/ 511: /***/ (
+    /***/ 6362: /***/ (
       __unused_webpack_module,
       exports,
       __webpack_require__
@@ -1136,11 +1136,11 @@
           return ImageConfigContext;
         },
       });
-      const _interop_require_default = __webpack_require__(6752);
+      const _interop_require_default = __webpack_require__(9334);
       const _react = /*#__PURE__*/ _interop_require_default._(
-        __webpack_require__(8008)
+        __webpack_require__(6960)
       );
-      const _imageconfig = __webpack_require__(2749);
+      const _imageconfig = __webpack_require__(9371);
       const ImageConfigContext = _react.default.createContext(
         _imageconfig.imageConfigDefault
       );
@@ -1150,7 +1150,7 @@
       /***/
     },
 
-    /***/ 2749: /***/ (__unused_webpack_module, exports) => {
+    /***/ 9371: /***/ (__unused_webpack_module, exports) => {
       Object.defineProperty(exports, "__esModule", {
         value: true,
       });
@@ -1190,7 +1190,6 @@
         dangerouslyAllowSVG: false,
         contentSecurityPolicy: "script-src 'none'; frame-src 'none'; sandbox;",
         contentDispositionType: "attachment",
-        localPatterns: undefined,
         remotePatterns: [],
         unoptimized: false,
       }; //# sourceMappingURL=image-config.js.map
@@ -1198,7 +1197,7 @@
       /***/
     },
 
-    /***/ 6900: /***/ (__unused_webpack_module, exports) => {
+    /***/ 515: /***/ (__unused_webpack_module, exports) => {
       Object.defineProperty(exports, "__esModule", {
         value: true,
       });
@@ -1231,7 +1230,7 @@
       /***/
     },
 
-    /***/ 5415: /***/ (
+    /***/ 5115: /***/ (
       __unused_webpack_module,
       exports,
       __webpack_require__
@@ -1245,9 +1244,9 @@
           return RouterContext;
         },
       });
-      const _interop_require_default = __webpack_require__(6752);
+      const _interop_require_default = __webpack_require__(9334);
       const _react = /*#__PURE__*/ _interop_require_default._(
-        __webpack_require__(8008)
+        __webpack_require__(6960)
       );
       const RouterContext = _react.default.createContext(null);
       if (false) {
@@ -1256,7 +1255,7 @@
       /***/
     },
 
-    /***/ 6549: /***/ (
+    /***/ 2016: /***/ (
       __unused_webpack_module,
       exports,
       __webpack_require__
@@ -1270,7 +1269,7 @@
           return SideEffect;
         },
       });
-      const _react = __webpack_require__(8008);
+      const _react = __webpack_require__(6960);
       const isServer = typeof window === "undefined";
       const useClientOnlyLayoutEffect = isServer
         ? () => {}
Diff for main-HASH.js

Diff too large to display

Diff for app-page-exp..ntime.dev.js
failed to diff
Diff for app-page-exp..time.prod.js

Diff too large to display

Diff for app-page-tur..time.prod.js

Diff too large to display

Diff for app-page-tur..time.prod.js

Diff too large to display

Diff for app-page.runtime.dev.js
failed to diff
Diff for app-page.runtime.prod.js

Diff too large to display

Diff for app-route-ex..ntime.dev.js

Diff too large to display

Diff for app-route-ex..time.prod.js

Diff too large to display

Diff for app-route-tu..time.prod.js

Diff too large to display

Diff for app-route-tu..time.prod.js

Diff too large to display

Diff for app-route.runtime.dev.js

Diff too large to display

Diff for app-route.ru..time.prod.js

Diff too large to display

Diff for pages-turbo...time.prod.js

Diff too large to display

Diff for pages.runtime.dev.js

Diff too large to display

Diff for pages.runtime.prod.js

Diff too large to display

Diff for server.runtime.prod.js

Diff too large to display

Commit: 093283c

@styfle styfle requested a review from ijjk October 2, 2024 21:56
@styfle styfle enabled auto-merge (squash) October 2, 2024 21:57
@styfle styfle merged commit 1a81fe4 into vercel:canary Oct 2, 2024
105 checks passed
styfle pushed a commit that referenced this pull request Oct 5, 2024
### What?

Small type tweak, asked for in
#70443

### Why?

The `alt` prop is required on the call to `getImgProps`, and the
implementation, returns it back to the caller, however, the type
signature of the return type for `getImgProps`, omits the `alt` prop,
which means that users have to manually apply the `alt` prop.

That is to say, that in this example, tweaked from the docs:

```jsx
import { getImageProps } from 'next/image'
 
export default function Page() {
  const common = { alt: 'Theme Example', width: 800, height: 400 }
  const {
    props: { srcSet: dark },
  } = getImageProps({ ...common, src: '/dark.png' })
  const {
    props: { srcSet: light, ...rest },
  } = getImageProps({ ...common, src: '/light.png' })
 
  return (
    <picture>
      <source media="(prefers-color-scheme: dark)" srcSet={dark} />
      <source media="(prefers-color-scheme: light)" srcSet={light} />
      {/* the alt prop is here, but as far as TypeScript is concerned, it is not */}
      <SomeCustomImageComponent {...rest} /> 
    </picture>
  )
}
``` 

So users have to do:

```jsx
      <SomeCustomImageComponent {...rest} alt={common.alt} /> 
```

See more at, #70443

### How?

Remove `alt` from the Omit union.

```tsx
export type ImgProps = Omit<ImageProps, 'src'  | 'alt' | 'loader'> & { /* other stuff */ }
```

Fixes #70443
styfle added a commit that referenced this pull request Oct 6, 2024
- Backport #70608 to `14.2.x`

Co-authored-by: Joseph <sephxd1234@gmail.com>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 17, 2024
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