Using next/image with priority property and cloudinary loader config, adds space on top of every image on mobile.
See original GitHub issueBug report
Describe the bug
It renders an additional space on top of every image on mobile when using next/image
with priority
property and cloudinary loader config.
To Reproduce
- Configure loader in
next.config.js
as written below. - Render Image using
next/image
with priority property above the fold and another image without priority property, below the fold. - On mobile, images will have extra space on top of it. https://22f17.sse.codesandbox.io/
// next.config.js
module.exports = {
images: {
domains: ["assets.wego.com"],
loader: "cloudinary",
path: "https://assets.wego.com/image/upload/"
}
};
import Image from "next/image";
export default function IndexPage() {
return (
<div>
<div>
<Image
width="100"
height="40"
src="/v1/makalu/wego.png"
alt="logo"
priority
/>
</div>
<div style={{ paddingTop: "800px" }}></div>
<div>
This image has empty space on top of it.
<Image
width="100"
height="40"
src="/v1/makalu/wego.png"
alt="logo"
/>
</div>
</div>
);
}
Expected behavior
Images should not have an extra space on top of it.
Screenshots

System information
- OS: macOS
- Browser chrome mobile, chrome device toolbar
- Version of Next.js: ~10.0.3~
12.0.1
- Version of Node.js: ~12.4.0~
16
Issue Analytics
- State:
- Created 3 years ago
- Comments:13 (1 by maintainers)
Top Results From Across the Web
Next.js automatic image optimization with next/image
Learn about automatic image optimization and how it can benefit developers with the native, game-changing, and powerful next/image API.
Read more >Nextjs image optimization with examples - Refine Dev
Built-in image optimization using next image component. ... The Image Component Properties; Optional next/image Props; Configuration Options ...
Read more >Deliver images with the Next.js Image component (video tutorial)
Watch a video tutorial to learn how to deliver Cloudinary images using the Next.js Image component.
Read more >next/image - Next.js
Enable Image Optimization with the built-in Image component. ... you can use the loaderFile configuration in next.config.js to configure every instance of ...
Read more >How to Use Cloudinary Images in Next.js with Blurred ...
Step 0: Creating a new Next.js app; Step 1: Adding a new local image with Next.js Image; Step 2: Using static Cloudinary image...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@sapjax Seems to be correct. Using the original reproduction and blocking the script makes the issue go away.
With blocking:
Without blocking:
Adding a
data-cfstyle
prop to theImage
also seem to help:https://codesandbox.io/s/nextjs-image-priority-issue-forked-rsudw?file=/pages/index.js:414-437
https://rsudw.sse.codesandbox.io/
I’m not sure Next.js can do anything about this specifically. You could add a Content-Security-Policy to your website to disallow running that script.
It might also be configurable to disable this in Cloudflare:
https://help.dreamhost.com/hc/en-us/articles/216477897-Cloudflare-technologies-available-in-the-panel#:~:text=Mirage is only available for,check box.
I found this issue is that Cloudflare injected a script into HTML, https://ajax.cloudflare.com/cdn-cgi/scripts/04b3eb47/cloudflare-static/mirage2.min.js and this script remove the
style
ofimg
tags, if we adddata-cfstyle
attribute onimg
, it will not removestyle
and merge style then, so we can found on the rendered html img tags, the style is3333;position:absolute....
. 🤣related post: https://blog.cloudflare.com/mirage2-solving-mobile-speed/