web/timeline: use content-visibility instead of loading=lazy for media

This commit is contained in:
Tulir Asokan 2024-12-02 00:01:58 +02:00
parent b889f90c4d
commit ab9dbbcd2f
4 changed files with 9 additions and 9 deletions

View file

@ -62,9 +62,7 @@ const MediaMessageBody = ({ event, room, sender }: EventContentProps) => {
const renderPlaceholderElem = supportsClickToShow && (!renderMediaElem || !!contentWarning || !loaded)
const isLoadingOnlyCover = !loaded && !contentWarning && renderMediaElem
const [mediaContent, containerClass, containerStyle] = useMediaContent(
content, event.type, undefined, onLoad, !clickedShow,
)
const [mediaContent, containerClass, containerStyle] = useMediaContent(content, event.type, undefined, onLoad)
let placeholderElem: JSX.Element | null = null
if (renderPlaceholderElem) {

View file

@ -199,10 +199,6 @@ div.html-body {
}
div.media-container {
&.image-container, &.video-container {
contain: strict;
}
> div.placeholder {
position: relative;
width: 100%;

View file

@ -25,7 +25,6 @@ export const useMediaContent = (
evtType: EventType,
containerSize?: ImageContainerSize,
onLoad?: () => void,
lazyLoad = true,
): [JSX.Element | null, string, CSSProperties] => {
const mediaURL = content.file?.url ? getEncryptedMediaURL(content.file.url) : getMediaURL(content.url)
const thumbnailURL = content.info?.thumbnail_file?.url
@ -34,7 +33,6 @@ export const useMediaContent = (
const style = calculateMediaSize(content.info?.w, content.info?.h, containerSize)
return [<img
onLoad={onLoad}
loading={lazyLoad ? "lazy" : "eager"}
style={style.media}
src={mediaURL}
alt={content.filename ?? content.body}

View file

@ -39,6 +39,10 @@ export function calculateMediaSize(
container: {
width: `${imageContainerWidth}px`,
height: `${imageContainerHeight}px`,
containIntrinsicWidth: `${imageContainerWidth}px`,
containIntrinsicHeight: `${imageContainerHeight}px`,
contentVisibility: "auto",
contain: "strict",
},
media: {},
}
@ -64,6 +68,10 @@ export function calculateMediaSize(
container: {
width: `${width}px`,
height: `${height}px`,
containIntrinsicWidth: `${width}px`,
containIntrinsicHeight: `${height}px`,
contentVisibility: "auto",
contain: "strict",
},
media: {
aspectRatio: `${origWidth} / ${origHeight}`,