Giter Club home page Giter Club logo

Comments (7)

Niels-IO avatar Niels-IO commented on July 17, 2024

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.

kopino4 avatar kopino4 commented on July 17, 2024

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.

Niels-IO avatar Niels-IO commented on July 17, 2024

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.

kopino4 avatar kopino4 commented on July 17, 2024

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.

kopino4 avatar kopino4 commented on July 17, 2024

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):

WorkingDiv

BrokenOutterDiv (aspect-ratio gets ignored because of the trailing px at the end):

BrokenDiv

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.

Niels-IO avatar Niels-IO commented on July 17, 2024

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:
image

image

from next-image-export-optimizer.

kopino4 avatar kopino4 commented on July 17, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.