Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import assert from 'node:assert/strict';
import { describe, it } from 'node:test';

import { renderToStaticMarkup } from 'react-dom/server';

import { CustomMarkdown } from './CustomMarkdown';

describe('CustomMarkdown images', () => {
it('loads inline images lazily and decodes them asynchronously', () => {
const html = renderToStaticMarkup(
<CustomMarkdown MarkdownContent='![Example](/example.png)' />,
);

assert.match(html, /loading="lazy"/);
assert.match(html, /decoding="async"/);
assert.match(html, /alt="Example"/);
assert.match(html, /src="\/example\.png"/);
});

it('preserves explicit loading and decoding for authored HTML images', () => {
const html = renderToStaticMarkup(
<CustomMarkdown MarkdownContent='<img src="/hero.png" loading="eager" decoding="sync" alt="" />' />,
);

assert.match(html, /loading="eager"/);
assert.match(html, /decoding="sync"/);
});
});
11 changes: 10 additions & 1 deletion apps/frontend/src/modules/shared/components/CustomMarkdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,19 @@ const img = ({
node,
alt,
src = '',
loading = 'lazy',
decoding = 'async',
...props
}: JSX.IntrinsicElements['img'] & ExtraProps) => {
return (
<img {...props} alt={alt} src={src} className='my-8 mx-auto rounded-lg' />
<img
{...props}
alt={alt}
src={src}
loading={loading}
decoding={decoding}
className='my-8 mx-auto rounded-lg'
/>
);
};

Expand Down