Next.js Discord

Discord Forum

Image Flickering on page change

Answered
Arinji posted this in #help-forum
Open in Discord
Avatar
const montserrat = Montserrat({ subsets: ["latin"] });

export const metadata: Metadata = {
  title: "Create Next App",
  description: "Generated by create next app",
};

export default async function RootLayout({
  children,
}: Readonly<{
  children: React.ReactNode;
}>) {
  const parsedOptions = await unstable_cache(
    async () => {
      const data = await fetch(
        `${process.env.NEXT_PUBLIC_PAYLOAD_URL}/api/article`,
        {
          headers: {
            Authorization: `users API-Key ${process.env.API_KEY}`,
          },
        }
      );

      const options = await data.json();
      const parsedOptions: SearchSchemaType[] = options.docs.map(
        (option: any) => {
          const parse = SearchSchema.safeParse(option);
          if (parse.success) return parse.data as SearchSchemaType;
        }
      );
      return parsedOptions;
    },
    ["key"],
    { tags: ["searchTAG"], revalidate: false }
  )();

  return (
    <html lang="en">
      <body className={`${montserrat.className} bg-shades-dark`}>
        <div className="w-full   bg-shades-dark h-[180px] relative flex flex-col items-center justify-center">
          <Image
            fill
            src="/banner.png"
            alt="Banner"
            sizes="100vw"
            className="w-full h-full absolute object-cover object-[90%_90%] "
          />
          <div className="...."></div>
          <div className="...">
            <Image
              src="/logo.webp"
              alt="Logo"
              width={100}
              height={100}
              className=" absolute top-0 left-0 object-contain"
            />
            <SearchBar options={parsedOptions} />
        <div className="w-full h-full flex flex-col items-center justify-center">
          {children}
        </div>
      </body>
    </html>
  );
}


Thats my layout.tsx with the image being the banner image... im so confused why the image is resizing.... its on prod mode btw
Image
Answered by DirtyCajunRice | AppDir
import it statically
View full answer

11 Replies

Avatar
Bump
Avatar
@Arinji Bump
Avatar
import it statically
Answer
Avatar
@DirtyCajunRice | AppDir import it statically
Avatar
Like import from ...
Why though?
Usually it works normally
Avatar
@Arinji Like import from ... Why though?
Avatar
because what you are doing it bad and is client rendering all the images 😂
Avatar
@Arinji Usually it works normally
Avatar
it works has nothing to do with if its good practice
Avatar
@DirtyCajunRice | AppDir because what you are doing it bad and is client rendering all the images 😂
Avatar
Oh shit it does? My bad lmao all of my projects do that xD
Lemm try and let you know if it works
Avatar
@DirtyCajunRice | AppDir uh so i found the problem
the importing thing, helped with the resizing.. but it keps flickering
wanna know why?... i used an a tag xD