From 1a835c32abe04e70f1c3bb347ded33005b893de9 Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Wed, 28 Jun 2023 23:35:22 +0800 Subject: [PATCH] Attempt to fix Safari's cut-off images bug --- src/components/media.jsx | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/components/media.jsx b/src/components/media.jsx index b49bc519..3e4d324e 100644 --- a/src/components/media.jsx +++ b/src/components/media.jsx @@ -12,6 +12,8 @@ import Icon from './icon'; import Link from './link'; import { formatDuration } from './status'; +const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent); // https://stackoverflow.com/a/23522755 + /* Media type === @@ -117,6 +119,19 @@ function Media({ media, to, showOriginal, autoAnimate, onClick = () => {} }) { if (isImage) { // Note: type: unknown might not have width/height quickPinchZoomProps.containerProps.style.display = 'inherit'; + + useLayoutEffect(() => { + if (!isSafari) return; + (async () => { + try { + await fetch(mediaURL, { cache: 'reload', mode: 'no-cors' }); + mediaRef.current.src = mediaURL; + } catch (e) { + // Ignore + } + })(); + }, [mediaURL]); + return (