Comments (7)
Hi @kopino4,
Thanks for the bug report. Could you please provide an example implementation of the ExportedImage component that causes a layout shift?
from next-image-export-optimizer.
Hi @Niels-IO,
This is an example of a usage with static image import, CAUSING Layout shift.
<ExportedImage src={photo} alt="photo" layout="responsive" />
If i replace it with Image, everything works fine. NO Layout shift:
<Image src={photo} alt="photo" layout="responsive" />
If i wrap the ExportedImage with an optimistic apect ratio, so that the height has some margin of safety. NO Layout shift:
<div
style={{
width: '100%',
aspectRatio: '1',
position: 'relative',
alignSelf: 'center',
}}
>
<ExportedImage src={photo} alt="photo" layout="responsive" />
</div>
The layout shift is very small. Not visible with the eye, but Lighthouse test recognizes it. Is it possible that you also set the aspect ration in your component but the result get rounded up/down? For example the aspect ratio of the image is 0.123 but the calculation results in 0.124? Just an idea.
Thanks
from next-image-export-optimizer.
Hey @kopino4,
For statically imported images, I had to wrap the ExportedImage component in another div that gets an aspect ration style prop. So the reason can very well be what you described with a rounding error. Could you please try to test it without the aspectRatio style prop in your outer div?
Thanks
from next-image-export-optimizer.
Hey @Niels-IO,
As expected, without the aspect ratio set in the outter div, Layout shift occurs:
<div
style={{
width: '100%',
position: 'relative',
alignSelf: 'center',
}}
>
<ExportedImage src={photo} alt="photo" layout="responsive" />
</div>
The original dimensions of the source image are 1024 x 768. Which results into a 1,33333333 aspect ratio. If it gets rounded to 1.3330 somewhere. This could be it.
from next-image-export-optimizer.
Hi @Niels-IO ,
I think the issue is in the format of your aspect ratio. Look at the following situations:
WorkingOutterDiv (apect-ratio is applied to the div):
BrokenOutterDiv (aspect-ratio gets ignored because of the trailing px
at the end):
This is because of the calculation you use in your ExportedImage implementation
style={{
aspectRatio: 1024/768,
}}
Results in aspect-ratio:1.33333333px
, which is an Invalid format for aspect-ratio
style={{
aspectRatio: (1024/768).toString(),
}}
Results in aspect-ratio:1.33333333
from next-image-export-optimizer.
Hi @kopino4,
I have trouble reproducing your findings, unfortunately. Are you using the current version 0.14.5?
Your code here works for me without a layout shift:
<div
style={{
width: '100%',
position: 'relative',
alignSelf: 'center',
}}
>
<ExportedImage src={photo} alt="photo" layout="responsive" />
</div>
Also, the aspect ratio is calculated as expected:
from next-image-export-optimizer.
Hey @Niels-IO,
thanks to your answer I tried to update the react and nextjs version in my package.json.
This fixed the issue
from next-image-export-optimizer.
Related Issues (20)
- Next.js 14 dev mode error HOT 2
- Images that dont have predefined height HOT 8
- SVG optimization with tools like svgo HOT 2
- Can't optimize two different path HOT 1
- unexpected property: transpilePackages HOT 4
- Srcset not created for Static Images HOT 28
- Output folder not being created on build. HOT 12
- Add support for Picture element HOT 1
- Issue with query string get params HOT 2
- Could not load sharp module error HOT 2
- Export utilities from ExportedImage component HOT 1
- Allow setting location of the hashes.json and optimized images
- Add `unoptimized` configuration option
- Adding custom options when fetching remote images HOT 4
- Doesn't work on next 14.1 HOT 2
- Remote image download error: `ENAMETOOLONG: name too long` HOT 3
- Images exporting too all sizes but all rendering at full size HOT 1
- Error: ENOENT: no such file or directory, scandir 'remoteImagesForOptimization' HOT 1
- Allow CSS images optimization (for example background image) HOT 2
- CLI tool does not even start on Mac (1.14.1) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from next-image-export-optimizer.