fix: ensure images without specified emoticon don't grow

This commit is contained in:
7w1 committed 2026-07-26 15:10:36 -05:00
1 parent e3e1d57a08
commit d4b4929c21
3 files changed
+30 -2

No files matched your search

+16
View File
@@ -64,6 +64,22 @@ describe('Image', () => {
expect(rendered).toHaveAttribute('height', '123');
});
it('keeps lottie emoticons at inline-emoticon size', async () => {
const gzipped = Buffer.from(gzipSync(lottieJson)).toString('base64');
render(
<Image
src={`data:application/gzip;base64,${gzipped}`}
aria-label="emoticon"
data-mx-emoticon
style={{ width: 'auto', height: '1em' }}
/>
);
await waitFor(() => expect(screen.getByLabelText('emoticon').tagName).toBe('CANVAS'));
const canvas = screen.getByLabelText('emoticon');
expect(canvas.parentElement).toHaveStyle({ width: '1em', height: '1em' });
});
it('forwards the canvas ref and pointer events for lottie images', async () => {
const gzipped = Buffer.from(gzipSync(lottieJson)).toString('base64');
const ref = createRef<HTMLImageElement | HTMLCanvasElement>();
+13 -2
View File
@@ -10,6 +10,7 @@ import type { IImageInfo } from '$types/matrix/common';
type ImageProps = Omit<ImgHTMLAttributes<HTMLImageElement>, 'onPointerDown'> & {
info?: IImageInfo;
mimeType?: string;
disableDefaultSizing?: boolean;
disablePixelation?: boolean;
pixelated?: boolean;
onLottieLoad?: (canvas?: HTMLCanvasElement) => void;
@@ -274,6 +275,7 @@ function resolveCachedLottieJson(src: string): Promise<string | null> {
type LottieImageProps = LottieDotProps & {
data: string;
alt?: string;
emoticon?: boolean;
onLottieLoad?: (canvas?: HTMLCanvasElement) => void;
onLottieError?: () => void;
pixelated?: boolean;
@@ -284,6 +286,7 @@ type LottieImageProps = LottieDotProps & {
function LottieImage({
data,
alt,
emoticon,
className,
style,
onLottieLoad,
@@ -353,7 +356,12 @@ function LottieImage({
<Suspense fallback={null}>
<div
className={className}
style={{ width: '100%', height: '100%', ...style }}
style={{
width: '100%',
height: '100%',
...style,
...(emoticon ? { width: '1em', height: '1em' } : undefined),
}}
onPointerDown={onPointerDown}
>
<DotLottieReact
@@ -375,6 +383,7 @@ export const Image = forwardRef<HTMLImageElement | HTMLCanvasElement, ImageProps
alt,
info,
mimeType,
disableDefaultSizing,
disablePixelation,
loading = 'lazy',
onLoad,
@@ -397,6 +406,7 @@ export const Image = forwardRef<HTMLImageElement | HTMLCanvasElement, ImageProps
const [fallbackSource, setFallbackSource] = useState<string>();
const lottieProps = props as LottieDotProps;
const emoticon = 'data-mx-emoticon' in props;
const declaredLottieCandidate = isGzippedLottieCandidate(
src,
mimeType ?? info?.mimetype,
@@ -410,7 +420,7 @@ export const Image = forwardRef<HTMLImageElement | HTMLCanvasElement, ImageProps
? undefined
: null;
const imageClass = classNames(
css.Image,
!disableDefaultSizing && css.Image,
!disablePixelation &&
(pixelated ?? isPixelatedRendering(pixelatedImageRendering, info)) &&
css.ImagePixelated,
@@ -446,6 +456,7 @@ export const Image = forwardRef<HTMLImageElement | HTMLCanvasElement, ImageProps
className={imageClass}
style={style}
data={resolvedLottieJson}
emoticon={emoticon}
alt={alt}
onLottieLoad={onLottieLoad}
onLottieError={onLottieError}
@@ -570,6 +570,7 @@ function FallbackImg({
return (
<MediaImage
{...props}
disableDefaultSizing
src={renderableSrc ?? src}
className={className}
style={className === css.EmoticonImg ? { width: 'auto', height: '1em', ...style } : style}