feat: fetchImageSize - get dimensions on server-side!!! #14
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
-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: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 sameonLoadedMetadata
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:
see: RFC: React Server Module Conventions v2聽reactjs/rfcs#227 & RFC: First class support for promises and async/await聽reactjs/rfcs#229