-
I've been a little lost trying to figure out this issue. Small starter boilerplate using Chakra UI I've made for myself. When I'm clicking between the Home page and Page 2, the logo on the top left flickers. I have a feeling it's something related to next/image and how it serves images dynamically but I'm not sure if there is any real way to solve this. Appreciate anyone who takes the time looking into this! |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 16 replies
-
This is because the image is lazy-loaded by default. Since the image is at the top ("above the fold"), you can use Note: there was a bug fix for this that shipped in |
Beta Was this translation helpful? Give feedback.
-
I am having the same issue, but using import Link from 'next/link'
import Image from "next/image"
const IndexPage = () => {
return (
<>
<h1>HOME</h1>
<Image src="/lotus-logo-d.svg" width={32} height={32} priority={true}/>
<p>
<Link href="/about">
<a>About</a>
</Link>
</p>
</>
)
}
export default IndexPage
import Link from 'next/link'
import Image from "next/image"
const AboutPage = () => {
return (
<>
<h1>ABOUT</h1>
<Image src="/lotus-logo-d.svg" width={32} height={32} priority={true}/>
<p>
<Link href="/">
<a>Home</a>
</Link>
</p>
</>
)
}
export default AboutPage when I go back and forth between these two pages, i can clearly see the flickering of the logo file. I know i didn't put it inside a layout here, but in my own app i did put the logo inside a root level layout component and both have this flickering issue. @DecliningLotus I am curious on your app link, it doesn't flicker when I go back and forth, I checked your repo's code I don't see big differences between your layout logic and mine, would you shed some light on what could be the things that I may neglect? Thanks ! @leerob |
Beta Was this translation helpful? Give feedback.
-
For those who face same issue like me, I found this post is very helpful to understand this issue: I don't see in @DecliningLotus 's repo, it uses a Layout wrapper in |
Beta Was this translation helpful? Give feedback.
-
I just found out I saw the logo flickers is because I am in Chrome debug mode :(, if I close the debug window then it does not flicker. @DecliningLotus 's app also flickers if I am in debug mode. So the conclusion is:
|
Beta Was this translation helpful? Give feedback.
-
I am experiencing this issue as well. I have a Sidebar component that is rendering an image, on route change that image is blinking. I am statically importing image and using it like this: |
Beta Was this translation helpful? Give feedback.
-
I have the same issue with the app router. The navbar contains an SVG which is loaded with priority. The footer contains the same SVG which is lazy loaded. Now while navigating back and forth sometime the navbar image and sometimes the footer image are flickering. Looks very strange and is clearly visible on Safari on iOS. Much less on macOS browsers. Happens using the img element directly too. The SVG is a static asset delivered as is. All pages use the same layout.tsx which contains the navbar and the footer. So the images should not change at all and I don't see any network requests. The affected components are all rendered on the server. |
Beta Was this translation helpful? Give feedback.
-
This was caused by Cache-Control being set to 'public, max-age=0'. Chrome still caches the images in memory but Safari performs additional roundtrips. Solved it by adding this to next.config.js:
Now all navigations are perfectly smooth and caching works as expected. The Next.js docs still specify that Cache-Control cannot be overwritten but we are not using next/image and static assets are served as is. This might not work for all use cases. |
Beta Was this translation helpful? Give feedback.
This is because the image is lazy-loaded by default. Since the image is at the top ("above the fold"), you can use
priority
so that it's properly preloaded.Note: there was a bug fix for this that shipped in
10.0.5
, so update to that!