fix(catalog): avoid stretching unknown-size thumbnails

This commit is contained in:
Tommaso Casaburi
2026-03-31 17:46:01 +07:00
parent 6a3040dc55
commit eeb288e2dc
2 changed files with 22 additions and 2 deletions
@@ -271,6 +271,8 @@ describe('CatalogRow', () => {
expect(wrapper?.style.border).toContain('red');
expect(frameImage).toBeTruthy();
expect(frameImage?.getAttribute('width')).toBe('150');
expect(frameImage?.getAttribute('height')).toBe('75');
await act(async () => {
frameImage?.dispatchEvent(new Event('error', { bubbles: true }));
@@ -322,6 +324,23 @@ describe('CatalogRow', () => {
expect(container.querySelector<HTMLVideoElement>('video[src="https://example.com/file.mp4#t=0.001"]')).toBeTruthy();
});
it('does not force square dimensions on images when media metadata is missing', async () => {
await act(async () => {
root.render(
createElement(CatalogPostMedia, {
cid: 'image-post',
commentMediaInfo: { type: 'image', url: 'https://example.com/file.png' },
}),
);
});
const image = container.querySelector<HTMLImageElement>('img[src="https://example.com/file.png"]');
expect(image).toBeTruthy();
expect(image?.getAttribute('width')).toBeNull();
expect(image?.getAttribute('height')).toBeNull();
});
it('renders media posts with board links, counts, and hover previews in all view', async () => {
testState.directories = [{ address: 'music-posting.eth', features: { requirePostLinkIsMedia: true }, title: '/mu/ - Music' }];
testState.linkCount = 2;
+3 -2
View File
@@ -63,8 +63,9 @@ export const CatalogPostMedia = ({ cid, commentMediaInfo, linkWidth, linkHeight
displayHeight = '54px';
}
const numericWidth = parseInt(displayWidth) || undefined;
const numericHeight = parseInt(displayHeight) || undefined;
const hasKnownMediaDimensions = Boolean(linkWidth && linkHeight);
const numericWidth = hasKnownMediaDimensions ? parseInt(displayWidth) || undefined : undefined;
const numericHeight = hasKnownMediaDimensions ? parseInt(displayHeight) || undefined : undefined;
const maxWidth = imageSize === 'Large' ? '250px' : '150px';
const maxHeight = imageSize === 'Large' ? '250px' : '150px';