The system detected an Image with the source "/images/logo.png" as the primary element contributing to Largest Contentful Paint (LCP)

I have been working on a project using Next.13 and Typescript. In order to display an Image, I created a component called Logo.tsx.

"use client";

import Image from "next/image";
import { useRouter } from "next/navigation";

const Logo = () => {
  const router = useRouter();

  return (
    <Image
      alt="logo"
      height="100"
      width="100"
      className="
        hidden
        md:block  
        cursor-pointer
      "
      src="/images/logo.png"
    />
  );
};

export default Logo;

However, I encountered a warning that says:

Image with src "/images/logo.png" was detected as the Largest Contentful Paint (LCP). Please add the "priority" property if this image is above the fold.

Despite looking into the documentation, I couldn't grasp the solution to this issue. How can I resolve this error?

One attempt I made was to add the priority prop like this:

    <Image
      priority="true"
      alt="logo"
      height="100"
      width="100"
      className="
        hidden
        md:block  
        cursor-pointer
      "
      src="/images/logo.png"
    />

Unfortunately, the warning persisted. Additionally, a new error emerged in Eslint:

Type 'string' is not assignable to type 'boolean | undefined'

Answer №1

For more information, please consult the official documentation on next/image.

If you are encountering a TypeScript error, it may be indicating what you are doing incorrectly. The error message 'Type 'string' is not assignable to type 'boolean | undefined'' suggests that the 'priority' property expects a 'boolean' or 'undefined', but you have provided a 'string' instead.

 <Image
      priority={true} // Modify this line
      alt="logo"
      height="100"
      width="100"
      className="
        hidden
        md:block  
        cursor-pointer
      "
      src="/images/logo.png"
    />

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

An error should not be thrown if the object is potentially 'undefined', as there is a filter in place from rxjs

During my service refactoring process, I encountered a frustrating issue. The API I am working with returns an object with various optional properties. To work with these properties, I need to check if they are undefined or not using an if statement, other ...

In order for a Link with prefetch to function properly on iOS Safari, two clicks are necessary

In the upcoming 14.2 release, I've encountered an issue with StackedList and HeadlessUI. The links within them have a Prefetch set to true, which functions properly on Safari Mac and laptop browsers but has strange behavior on iOS Safari. Attached is ...

The modal stubbornly refuses to close

The main component responsible for initiating the process is /new-order. Upon clicking on the confirm button, a modal window appears. <div class="col-12"> <button type="button" class="btn btn-primary m-1" (click)=& ...

How to retrieve TypeScript object within a Bootstrap modal in Angular

Unable to make my modal access a JavaScript object in the controller to dynamically populate fields. Progress Made: Created a component displaying a list of "person" objects. Implemented a functionality to open a modal upon clicking a row in the list. ...

Deduce the types of parameters in nested functions based on the parent object

Having encountered a challenging obstacle in my Typescript journey, I find myself facing a dilemma with building a command-parsing utility. My aim is to incorporate type hints within configuration objects. Let's delve into the code example below; int ...

Unexpected Object Deconstruction following the useEffect Hook

I encountered a strange issue with object destructuring in react.js, here is the problem I am facing: To begin with, the useEffect function is being used to initialize the rooms variable. const [rooms, setRooms] = useState([]); const _auth = getAuth(app) ...

The issue arose with NextJs 13 and Framer Motion where the module 'v8' could not be resolved

I keep encountering this persistent error in my app directory while attempting to implement page transition animations with framer motion. Despite my efforts, I continue to come across the v8 error. Resources on resolving this issue are scarce - does anyon ...

Utilize React.useImperativeHandle() for declaring custom types

function App(){ const refEl:React.MutableRefObject<any> = React.useRef(null); // I am uncertain about the appropriate type here. React.useEffect(()=>{ if(refEl.current){ refEl.current.start() } }, []); return <Countdown ref={refEl} ...

Employing setState in an arrow function reinitializes the state

My goal is to update a state whenever a user changes input fields on my dashboard. Here's how the handler should operate: If the state is empty, create a user with standard values and change them to the new inputs If the user already exists in t ...

Attempting to retrieve a URL using Angular/Typescript is generating an Unknown Error instead of the expected successful response

I'm trying to make a simple HTTP function call through TypeScript (Angular) to an API hosted as a function in Azure. When I call the URL through Postman or directly in the browser, everything works perfectly. However, when I try to call the URL usin ...

Tips for showing information exclusively while hovering over an item

I tried to mimic the functionality seen on GitHub, where icons appear when hovering over headings. import remarkGfm from 'remark-gfm'; import rehypeSlug from 'rehype-slug' import rehypeAutolinkHeadings from "rehype-autolink-heading ...

Enhancing Navigation in NextJS with an Active Navbar

Attempting to apply a style to the active Navbar on NextJs, I have experimented with various approaches. I imported useRouter() from next/navigation It appears that this method is somewhat outdated. <li className='font-medium py-1 my-2&apo ...

When a parameter is passed into a React-Query function with an undefined value, it can lead to the API returning a 404 error

Two parameters are sent from the frontend to trigger a GET request in another TypeScript file. It seems that one of the parameters is not successfully passed due to unknown rerenders, resulting in a 404 Error being returned by the API call in the console. ...

Issue encountered in Loopback 4: Error with @repository dependency injection (TypeError: Undefined property 'findOne')

As I set up Bearer Token authentication for my Loopback 4 application, I referenced this implementation guide: https://github.com/strongloop/loopback-next/tree/master/packages/authentication. Within my src/providers/auth-strategy.provider.ts file, I encou ...

Error: React is throwing a SyntaxError because a ")" is missing in the argument list

While working on a React-typescript project using Vite, I encountered an issue where my page was displaying blank and showing the error : Uncaught SyntaxError: missing ) after argument list (at main.tsx:6:51) This error was found in the main.tsx file : im ...

Is it possible to use AngularJS promise scheduling with `async`/`await` syntax?

When working with AngularJS services, TypeScript often recommends that I switch my code to use async/await functions. https://i.sstatic.net/vks1i.png While I understand that using the await keyword is compatible with third-party promises because it essen ...

Building stateless functional components in React using Typescript version 0.14

Demonstration: import * as React from 'react' declare function obtainMarineLife(x: any): any; declare var Tank: any; var OceanicHabitat = ({category}) => ( <Tank> {obtainMarineLife(category)} </Tank> ); let y = <Ocea ...

Utilize the express library (NodeJS, TypeScript) to send back the results of my function

I am curious about how I can handle the return values of my functions in my replies. In this specific scenario, I am interested in returning any validator errors in my response if they exist. Take a look at my SqlCompanyRepository.ts: async create(compan ...

I am facing an issue with the nginx configuration for a Next.js application running on an EC2 instance

While attempting to host a Next.js app on AWS EC2, I encountered a 403 error when trying to access the server URL. The app's code is located in /var/www/kosher/ and I am using pm2 to run the server. Here is a screenshot showing pm2 running: https://i. ...

When a class decorator is returned as a higher-order function, it is unable to access static values

Check out this showcase: function Decorator(SampleClass: Sample) { console.log('Inside the decorator function'); return function (args) { console.log('Inside the high order function of the decorator: ', args); let sample = ...