Unify dimensions cache between lightbox and feed (#6047)

* Remove useless memo

* Use explicit values when useImageAspectRatio doesn't know

It's not very good that you can't distingiush when we haven't loaded vs when we're certain. This shifts the burden of dealing with missing values to the caller.

* Check cache early

* Handle src change

* Rewrite image-sizes.fetch to avoid mixing async styles

* Make image-sizes LRU

Code is copy paste from useImageDimensions.ts

* Rm unused fields

* Derive aspect on the fly

* Factor useImageDimensions out of useImageAspectRatio

* Move useImageDimensions into image-sizes

* Make lightbox use the same cache

* Wire up known dimensions to the lightbox

* Handle division by zero in the hook

* Use safe aspect for lightbox calculations
This commit is contained in:
dan
2024-11-04 21:28:27 +00:00
committed by GitHub
parent ac9d910e1e
commit 174988bc5a
10 changed files with 144 additions and 176 deletions
+1 -1
View File
@@ -145,7 +145,7 @@ export function PostEmbeds({
uri: img.fullsize,
thumbUri: img.thumb,
alt: img.alt,
aspectRatio: img.aspectRatio,
dimensions: img.aspectRatio ?? null,
}))
const _openLightbox = (
index: number,