Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: fetchImageSize - get dimensions on server-side!!! #14

Merged
merged 1 commit into from
Nov 11, 2022

Conversation

nickadamson
Copy link
Owner

-related to #2, #6

Co-authored-by:
Federico Brigante me@fregante.com
image-size/image-size#258 (comment)

Info

This PR adds https://github.com/image-size/image-size to let messonry determine an arbitrary image's width & height WITHOUT having to download the entire image! It should (hopefully 馃) allow messonry to become fully Server-Side Render(-ed/-able?)!

So previously we were hiding unknown/arbitrary images (via CSS) until the HTML Image Element's onLoad event to grab the image's dimensions, and once that was known - show the element. This was admittedly a pretty poor implementation performance-wise, because:

  1. it is 100% client-side dependent
  2. if the client ever downloads an image quicker than the page itself, this event will actually not fire at all, and the image will remain hidden. Read more: https://stackoverflow.com/questions/39777833/image-onload-event-in-isomorphic-universal-react-register-event-after-image-is (and thank you to @Joonpark13 for making me aware of this in Add experimental blurry placeholder to image component聽vercel/next.js#24153)
  3. the client has to wait until the end of downloading the entire image to get what is essentially metadata! And is actually the first few bits of data that is downloaded!

For the past year or so I have been working on this 'messonry' idea (in one form or another) I have continually been asking myself, "Why can't <img> have the same onLoadedMetadata event that <video> has?!?! $%*&!!!"
It's actually very common to see some videos loading in the grid before images due to this restrictive race condition.

Well now that we can essentially do the same, and on the server side no less, we will finally be able to get & pass the size props of unknown images so that they are ready by the time it gets to the user. Is this the end of Cumulative Layout Shift (CLS) for messonry??? It just might be 馃槃

next up:

@nickadamson nickadamson added the enhancement New feature or request label Nov 4, 2022
@nickadamson nickadamson self-assigned this Nov 4, 2022
@nickadamson nickadamson reopened this Nov 11, 2022
@nickadamson nickadamson merged commit 9e1e453 into next Nov 11, 2022
@nickadamson nickadamson deleted the image-size branch November 11, 2022 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant