From 67e930cf212ba963cd4dd3b523299c9d046880cb Mon Sep 17 00:00:00 2001 From: Oikantik Basu <140976895+Golden007-prog@users.noreply.github.com> Date: Wed, 18 Nov 2026 08:11:57 +0530 Subject: [PATCH] fix: defer inline Markdown images --- .../shared/components/CustomMarkdown.spec.tsx | 28 +++++++++++++++++++ .../shared/components/CustomMarkdown.tsx | 11 +++++++- 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 apps/frontend/src/modules/shared/components/CustomMarkdown.spec.tsx diff --git a/apps/frontend/src/modules/shared/components/CustomMarkdown.spec.tsx b/apps/frontend/src/modules/shared/components/CustomMarkdown.spec.tsx new file mode 100644 index 00000000..3a0ae5ce --- /dev/null +++ b/apps/frontend/src/modules/shared/components/CustomMarkdown.spec.tsx @@ -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( + , + ); + + 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( + , + ); + + assert.match(html, /loading="eager"/); + assert.match(html, /decoding="sync"/); + }); +}); diff --git a/apps/frontend/src/modules/shared/components/CustomMarkdown.tsx b/apps/frontend/src/modules/shared/components/CustomMarkdown.tsx index 684d35fe..5f6dc83b 100644 --- a/apps/frontend/src/modules/shared/components/CustomMarkdown.tsx +++ b/apps/frontend/src/modules/shared/components/CustomMarkdown.tsx @@ -136,10 +136,19 @@ const img = ({ node, alt, src = '', + loading = 'lazy', + decoding = 'async', ...props }: JSX.IntrinsicElements['img'] & ExtraProps) => { return ( - {alt} + {alt} ); };