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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Safari displays a zoomed image in degraded quality #290

Closed
nazar-ch opened this issue Jun 30, 2024 · 3 comments
Closed

Safari displays a zoomed image in degraded quality #290

nazar-ch opened this issue Jun 30, 2024 · 3 comments
Labels
bug Something isn't working released Implemented and released

Comments

@nazar-ch
Copy link

Describe the bug

The current desktop & mobile versions of Safari initially load smaller images from the slide's scrSet, and after zooming in and replacing the smaller image with the larger version, render it in degraded quality.

Please check the screenshot (or the recording) with the illustration of the issue.

The browser loads the correct image (I checked this by using visually marked images), but displays it in a quality that resembles the low res version.

It seems to be caused by a bug in Safari. The transform: translateZ(0px) in the img style may change the way how the image is rendered and something in the rendering engine caches the original image dimensions. When src is replaced with another larger image it's rendered with the cached smaller dimensions.

Disabling translateZ by adding this style resolves the problem:

.yarl__slide_image {
    -webkit-transform: none !important;
}

Expected behavior

The high res image retains its quality

How to reproduce

  • Create the lightbox using srcSet with variants of different sizes.
  • Open in iOS Safari or Desktop Safari with the smallest window width.
  • Zoom in and see that large.jpg is displayed with degraded quality.
<Lightbox
    slides={[
        {
           // ...
           srcSet: [
                { width: 500, height: 500, src: 'small.jpg' },
                { width: 3000, height: 3000, src: 'large.jpg' },
            ],
        },
    ]}
/>;

Screenshots / Logs

safari-chrome-image-quality

Recording:
https://github.com/igordanchenko/yet-another-react-lightbox/assets/8333702/435e9aca-0f57-447e-8d85-42c83968307f

Additional context

No response

@igordanchenko
Copy link
Owner

igordanchenko commented Jul 1, 2024

Thank you for the very detailed report. I appreciate it!

Apparently, you discovered a Safari bug caused by the code meant to workaround a different Safari bug 😅

const style = {
// workaround occasional flickering in mobile Safari
WebkitTransform: "translateZ(0)",
};

// workaround occasional image flickering in desktop Safari
@media screen and (min-width: 800px) {
// noinspection CssUnknownProperty
-webkit-transform: translateZ(0);
-webkit-backface-visibility: hidden;
-webkit-transform-style: preserve-3d;
}

I'll implement another workaround to fix the blurred image, but keep in mind that images will still appear blurry during zoom-in / zoom-out transition.

Screen.Recording.2024-07-01.at.7.57.10.AM.mov

It's another Webkit bug dating back to 2009 😱

https://bugs.webkit.org/show_bug.cgi?id=27684

@igordanchenko igordanchenko added the bug Something isn't working label Jul 1, 2024
Copy link

github-actions bot commented Jul 1, 2024

🎉 This issue has been resolved in version 3.20.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@github-actions github-actions bot added the released Implemented and released label Jul 1, 2024
@nazar-ch
Copy link
Author

nazar-ch commented Jul 2, 2024

🤦

Thank you for the fix! The turnaround time is extraordinary :)

The blurry part feels like expected behavior, I hope it will be fine for users.

@github-actions github-actions bot locked and limited conversation to collaborators Oct 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working released Implemented and released
Projects
None yet
Development

No branches or pull requests

2 participants