mirror of
https://github.com/immich-app/immich.git
synced 2026-05-18 03:10:24 +03:00
fix: don't partially render images in firefox
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { isFirefox } from '$lib/utils/asset-utils';
|
||||||
import { cancelImageUrl } from '$lib/utils/sw-messaging';
|
import { cancelImageUrl } from '$lib/utils/sw-messaging';
|
||||||
import { onDestroy, untrack } from 'svelte';
|
import { onDestroy, untrack } from 'svelte';
|
||||||
import type { HTMLImgAttributes } from 'svelte/elements';
|
import type { HTMLImgAttributes } from 'svelte/elements';
|
||||||
@@ -14,6 +15,7 @@
|
|||||||
let { src, onStart, onLoad, onError, ref = $bindable(), ...rest }: Props = $props();
|
let { src, onStart, onLoad, onError, ref = $bindable(), ...rest }: Props = $props();
|
||||||
|
|
||||||
let capturedSource: string | undefined = $state();
|
let capturedSource: string | undefined = $state();
|
||||||
|
let loaded = $state(false);
|
||||||
let destroyed = false;
|
let destroyed = false;
|
||||||
|
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
@@ -32,11 +34,25 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const completeLoad = () => {
|
||||||
|
if (destroyed) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
loaded = true;
|
||||||
|
onLoad?.();
|
||||||
|
};
|
||||||
|
|
||||||
const handleLoad = () => {
|
const handleLoad = () => {
|
||||||
if (destroyed || !src) {
|
if (destroyed || !src) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
onLoad?.();
|
|
||||||
|
if (isFirefox && ref) {
|
||||||
|
ref.decode().then(completeLoad, completeLoad);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
completeLoad();
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleError = () => {
|
const handleError = () => {
|
||||||
@@ -49,6 +65,13 @@
|
|||||||
|
|
||||||
{#if capturedSource}
|
{#if capturedSource}
|
||||||
{#key capturedSource}
|
{#key capturedSource}
|
||||||
<img bind:this={ref} src={capturedSource} {...rest} onload={handleLoad} onerror={handleError} />
|
<img
|
||||||
|
bind:this={ref}
|
||||||
|
src={capturedSource}
|
||||||
|
{...rest}
|
||||||
|
style:visibility={isFirefox && !loaded ? 'hidden' : undefined}
|
||||||
|
onload={handleLoad}
|
||||||
|
onerror={handleError}
|
||||||
|
/>
|
||||||
{/key}
|
{/key}
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
@@ -224,6 +224,8 @@ const supportedImageMimeTypes = new Set([
|
|||||||
'image/webp',
|
'image/webp',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
export const isFirefox = typeof navigator !== 'undefined' && navigator.userAgent.includes('Firefox');
|
||||||
|
|
||||||
async function addSupportedMimeTypes(): Promise<void> {
|
async function addSupportedMimeTypes(): Promise<void> {
|
||||||
const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent); // https://stackoverflow.com/a/23522755
|
const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent); // https://stackoverflow.com/a/23522755
|
||||||
if (isSafari) {
|
if (isSafari) {
|
||||||
|
|||||||
Reference in New Issue
Block a user