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

React does not recognize the fetchPriority prop on a DOM element. #65161

Closed
KDederichs opened this issue Apr 29, 2024 · 36 comments · Fixed by #65235
Closed

React does not recognize the fetchPriority prop on a DOM element. #65161

KDederichs opened this issue Apr 29, 2024 · 36 comments · Fixed by #65235
Labels
bug Issue was opened via the bug report template. Image (next/image) Related to Next.js Image Optimization. linear: next Confirmed issue that is tracked by the Next.js team. locked

Comments

@KDederichs
Copy link

KDederichs commented Apr 29, 2024

Link to the code that reproduces this issue

https://github.com/KDederichs/fetch-prio-reproducer

To Reproduce

npm install
jest

Current vs. Expected behavior

jest
  console.error
    Warning: React does not recognize the `fetchPriority` prop on a DOM element. If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercase `fetchpriority` instead. If you accidentally passed it from a parent component, remove it from the DOM element.
        at img
        at /Users/USER/source_code/fetch-priority-reproducer/node_modules/next/src/client/image-component.tsx:212:5
        at /Users/USER/source_code/fetch-priority-reproducer/node_modules/next/src/client/image-component.tsx:372:5
        at Home

      4 | describe('Tests', () => {
      5 |     it('it renders without warning', async () => {
    > 6 |         const {container} = render(
        |                                   ^
      7 |             <Home/>
      8 |         )
      9 |     })

      at printWarning (node_modules/react-dom/cjs/react-dom.development.js:86:30)
      at error (node_modules/react-dom/cjs/react-dom.development.js:60:7)
      at validateProperty$1 (node_modules/react-dom/cjs/react-dom.development.js:3757:7)
      at warnUnknownProperties (node_modules/react-dom/cjs/react-dom.development.js:3803:21)
      at validateProperties$2 (node_modules/react-dom/cjs/react-dom.development.js:3827:3)
      at validatePropertiesInDevelopment (node_modules/react-dom/cjs/react-dom.development.js:9541:5)
      at setInitialProperties (node_modules/react-dom/cjs/react-dom.development.js:9830:5)
      at finalizeInitialChildren (node_modules/react-dom/cjs/react-dom.development.js:10950:3)
      at completeWork (node_modules/react-dom/cjs/react-dom.development.js:22232:17)
      at completeUnitOfWork (node_modules/react-dom/cjs/react-dom.development.js:26632:16)
      at performUnitOfWork (node_modules/react-dom/cjs/react-dom.development.js:26607:5)
      at workLoopSync (node_modules/react-dom/cjs/react-dom.development.js:26505:5)
      at renderRootSync (node_modules/react-dom/cjs/react-dom.development.js:26473:7)
      at performConcurrentWorkOnRoot (node_modules/react-dom/cjs/react-dom.development.js:25777:74)
      at flushActQueue (node_modules/react/cjs/react.development.js:2667:24)
      at act (node_modules/react/cjs/react.development.js:2582:11)
      at node_modules/@testing-library/react/dist/act-compat.js:47:25
      at renderRoot (node_modules/@testing-library/react/dist/pure.js:180:26)
      at render (node_modules/@testing-library/react/dist/pure.js:271:10)
      at Object.<anonymous> (app/page.spec.tsx:6:35)

Should be no error there

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.4.0: Fri Mar 15 00:12:41 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T8103
  Available memory (MB): 16384
  Available CPU cores: 8
Binaries:
  Node: 20.11.0
  npm: 10.2.4
  Yarn: 1.22.19
  pnpm: 8.15.1
Relevant Packages:
  next: 14.3.0-canary.30 // Latest available version is detected (14.3.0-canary.30).
  eslint-config-next: N/A
  react: 18.3.1
  react-dom: 18.3.1
  typescript: 5.1.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Image (next/image)

Which stage(s) are affected? (Select all that apply)

next dev (local)

Additional context

No response

NEXT-3273

@KDederichs KDederichs added the bug Issue was opened via the bug report template. label Apr 29, 2024
@github-actions github-actions bot added the Image (next/image) Related to Next.js Image Optimization. label Apr 29, 2024
@tonymtz
Copy link

tonymtz commented Apr 29, 2024

Updated to latest nextjs last night, this started to appear as soon as I imported Image from next/image.

@daybert
Copy link

daybert commented Apr 29, 2024

same waring, any use of Image from Next/Image

@luudv

This comment has been minimized.

@luudv

This comment has been minimized.

@chadlinden
Copy link

Same as facebook/react#25682 ? Regression?

@roshaninet

This comment has been minimized.

@styfle
Copy link
Member

styfle commented May 1, 2024

To be clear, the warning only happens when running jest, not next dev or next build, correct?

This sounds like an issue with @testing-library/react, not next.

@tr1s
Copy link

tr1s commented May 1, 2024

Same issue here after updating Next from 14.2.2 to 14.2.3 and React from 18.2.0 to 18.3.1.

Rolling back Next to 14.2.2 did not fix the error, however, keeping Next at 14.2.3 and rolling just React back to 18.2.0 fixed the error.

@styfle this happens using next dev, I don't have any testing libraries in my package.json. This seems to be an issue with the latest React update.

@styfle styfle added the linear: next Confirmed issue that is tracked by the Next.js team. label May 1, 2024
@styfle
Copy link
Member

styfle commented May 1, 2024

I see. This also seems to impact Pages Router + [email protected]

styfle added a commit that referenced this issue May 1, 2024
In a previous PR, #47302,
detection for `fetchPriority` assumed that
facebook/react#25927 would land in [email protected]
because that was the react@canary version at the time. However, it
didn't land in [email protected] and it is expected to land in [email protected]
due to the breaking change.

This means that users upgrading to [email protected] will see a warning.

The fix is to stop looking at the `React.version` string and instead
check for `React.use`, a feature that [will land in
[email protected]](https://react.dev/blog/2024/04/25/react-19#new-feature-use)
but is also available in react@canary and react@beta today.

Note: There were tests added for App Router and Pages Router in a
previous PR #47302 but they seem
to run on [email protected] which is why we don't see failures.

Fixes #65161
joonassandell added a commit to joonassandell/portfolio that referenced this issue May 2, 2024
@shinwonse

This comment has been minimized.

thomasdax98 added a commit to a11yphant/a11yphant that referenced this issue May 3, 2024
thomasdax98 added a commit to a11yphant/a11yphant that referenced this issue May 3, 2024
@styfle
Copy link
Member

styfle commented May 3, 2024

This is fixed on the canary channel.

You can try it out today with npm install next@canary, thanks!

joonassandell added a commit to joonassandell/portfolio that referenced this issue May 4, 2024
Among the conversion and linting there are additional changes included:

* Set proper useEffect deps
* Header: Fix initial arrow animation (unnecessary animating happened under the Splash)
* Header: Remove unnecessary animation props that didn't have effect and do minor animation tweaks
* Header: Remove the marquee "transition" key since it isn't a variant
* Header: Rename NavItem -> HeaderNavItem
* Header: Fix useMedia ssr error
* Fix vercel/next.js#65161
* Relocate locomotive-scroll wrapper to components with proper types
* Add build step script for Vercel, not active currently
* Figure: Don't spread props since the invalid blur* attrs could be applied (vercel/next.js#56511)
* Figure: Remove unnecessary props and add ones that could be needed
* Figure: Add alt text to video also
* Tweak tokens
* Slightly tweak some content strings and styles
* Refactor unnecessary stuff away from useInView hook
* Bunch of file extension changes and sort tweaks
* Relocate and fix component script
* Sort keys, jsx props and destructured keys
* Sitemap: Better key for projects
* utility.js -> utils.ts
@Islam-AbdElhakiim
Copy link

@styfle Thank you it solved my issue, but can you explain to me what was the issue and how this package solved it?

@bungandy

This comment was marked as duplicate.

@guillermo-avalos

This comment was marked as duplicate.

@uphiago
Copy link

uphiago commented Jun 4, 2024

same here, fixed after "react": "18.2.0" and "react-dom": "18.2.0"

styfle added a commit that referenced this issue Jun 6, 2024
In a previous PR, #47302,
detection for `fetchPriority` assumed that
facebook/react#25927 would land in [email protected]
because that was the react@canary version at the time. However, it
didn't land in [email protected] and it is expected to land in [email protected]
due to the breaking change.

This means that users upgrading to [email protected] will see a warning.

The fix is to stop looking at the `React.version` string and instead
check for `React.use`, a feature that [will land in
[email protected]](https://react.dev/blog/2024/04/25/react-19#new-feature-use)
but is also available in react@canary and react@beta today.

Note: There were tests added for App Router and Pages Router in a
previous PR #47302 but they seem
to run on [email protected] which is why we don't see failures.

Fixes #65161
@lucaliebenberg

This comment was marked as resolved.

@vicasas

This comment was marked as duplicate.

@pheonix5

This comment was marked as resolved.

J-HernandezM added a commit to J-HernandezM/ananda-web that referenced this issue Jun 14, 2024
@NebraskaCoder
Copy link

NebraskaCoder commented Jun 15, 2024

I hope this mock fixes the issue. Hit thumbs up if it works and thumbs down if it didnt. And let me know the error.

jest.mock('next/image', () => {
  const MockedImage = ({ src, alt, fetchPriority, ...props }) => {
    return (
      <img src={src} alt={alt} data-fetch-priority={fetchPriority} {...props} />
    );
  };
  MockedImage.displayName = 'MockedImage';
  return MockedImage;
});

Here is a better mock for Typescript support (placed in __mocks__/next/image.tsx), which also works for plain Javascript projects and won't break if ref is used:

/* eslint-disable @next/next/no-img-element */

import React, { useMemo } from "react";

import type {
  StaticImageData,
  StaticRequire,
} from "next/dist/shared/lib/get-img-props";

type ImageProps = React.DetailedHTMLProps<
  React.ImgHTMLAttributes<HTMLImageElement>,
  HTMLImageElement
>;

type ModifiedImageProps = Omit<ImageProps, "src"> & {
  src?: string | (StaticRequire | StaticImageData);
};

const NextImage = React.forwardRef<HTMLImageElement, ModifiedImageProps>((props, ref) => {
  const { src, alt, ...rest } = props;

  const imageSrc = useMemo(() => {
    if (!src) {
      return undefined;
    }

    if (typeof src === "string") {
      return src;
    }

    if ("default" in src) {
      return src.default.src;
    }

    return src.src;
  }, [src]);

  return (
    <img
      ref={ref}
      src={imageSrc}
      alt={alt}
    />
  );
});

NextImage.displayName = "Image";

export default NextImage;

I have edited this mock to not pass most of the props. I can't see why this is a problem as Next/Image props don't exactly line up to HTMLImage props and something like fill={true} will cause Jest to go nuts.

@styfle
Copy link
Member

styfle commented Jun 17, 2024

This is fixed in [email protected]

@guillermo-avalos
Copy link

This is fixed in [email protected]

Yup. I can now confirm it’s been fixed in 14.2.4

EnoF added a commit to kadena-community/spirekey that referenced this issue Jun 19, 2024
EnoF added a commit to kadena-community/spirekey that referenced this issue Jun 19, 2024
@cobalt88
Copy link

Thank you for getting this fixed. Its one of those errors I haven't been able to get rid of for a while now lol.

@o-faro
Copy link

o-faro commented Jun 26, 2024

Seems not to be fixed. Just ran into this problem for the first time today after a fresh install.
[email protected] was installed together with [email protected] and [email protected]

jaysoo pushed a commit to nrwl/nx that referenced this issue Jul 4, 2024
## Current Behavior

`fetchpriority` attribute error in Next image loading cmp. 

<img width="1260" alt="image"
src="https://github.com/nrwl/nx/assets/542458/9ba9f539-e0ad-4fe1-9a6a-64db856fd25c">

## Expected Behavior

Upgrading patch version of next fixes it.

//Edit: some context:
vercel/next.js#65161 (comment)

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #
FrozenPandaz pushed a commit to nrwl/nx that referenced this issue Jul 5, 2024
## Current Behavior

`fetchpriority` attribute error in Next image loading cmp.

<img width="1260" alt="image"
src="https://github.com/nrwl/nx/assets/542458/9ba9f539-e0ad-4fe1-9a6a-64db856fd25c">

## Expected Behavior

Upgrading patch version of next fixes it.

//Edit: some context:
vercel/next.js#65161 (comment)

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #

(cherry picked from commit 929a57c)
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. Image (next/image) Related to Next.js Image Optimization. linear: next Confirmed issue that is tracked by the Next.js team. locked
Projects
None yet
Development

Successfully merging a pull request may close this issue.