-
Notifications
You must be signed in to change notification settings - Fork 427
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(sanity): prevent layout shifts in image input #7535
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Skipped Deployment
|
No changes to documentation |
Component Testing Report Updated Oct 1, 2024 9:25 AM (UTC) ✅ All Tests Passed -- expand for details
|
a2cf780
to
2eb20ff
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A great example of not only fixing the bug, but also making the code cleaner and removing complexity! Thank you so much for this @juice49. Left a few comments, no blockers for merge.
packages/sanity/src/core/form/inputs/files/ImageInput/usePreviewImageSource.ts
Show resolved
Hide resolved
packages/sanity/src/core/form/inputs/files/ImageInput/usePreviewImageSource.ts
Outdated
Show resolved
Hide resolved
f38512a
to
48f8da7
Compare
Description
This branch introduces refinements to the image input preview, primarily to address the layout shift reported in #7337.
There are two scenarios in which layout shift can occur:
This branch removes the ref added in #6930. Instead of attempting to preserve the last known height of the image preview DOM node using a ref, the known image dimensions are set as CSS custom properties on the outer container of the image input. Both the image preview and upload state UI use CSS to match the aspect ratio of the selected image, eliminating both layout shifts noted above.
Importantly, the value of the image field reflects the previously selected image while the next image is uploading. This means the upload state UI can match the dimensions of the previously selected image, addressing layout shift when uploading a new image in a simpler manner than before.
This branch also introduces a couple of other refinements to the image input:
30vh
. I believe there was previously an attempt to achieve this, but the block size was ultimately limited to arem
value in CSS. Moving the calculations to CSS makes it simpler to allow the block size to extend to avh
value, while collapsing to the intrinsic height of the image if it's less than30vh
.Demo
Images now have a maximum height of
30vh
.We still preserve the aspect ratio of the current image to prevent layout shifts when uploading a new one, which was first addressed by Cody in #6930. Now we achieve it in a simpler way.
after-upload.mov
What to review
Does the approach make sense?
Testing
Notes for release