Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): keep an archived image swap from shortening the thread

Yudhi Armyndharisbc30e5f061d0
diff --git a/dashboard/src/components/chats/ArchivedMediaPreview.test.ts b/dashboard/src/components/chats/ArchivedMediaPreview.test.ts
index 355d4a09e..0298a1a55 100644
--- a/dashboard/src/components/chats/ArchivedMediaPreview.test.ts
+++ b/dashboard/src/components/chats/ArchivedMediaPreview.test.ts
@@ -285,3 +285,24 @@ test('an archived image is a named button that says it opens a dialog', async ()
// The viewer is a dialog; without this a screen reader announces a bare "photo.jpg, button".
assert.equal(button.getAttribute('aria-haspopup'), 'dialog');
});
+
+test('an archived image holds the height of the placeholder it replaces, so the swap never shortens the thread', async () => {
+ const { container } = rtl.render(
+ createElement(ArchivedMediaPreview, {
+ kind: 'image',
+ fallback,
+ load: async () => new Blob(['x'], { type: 'image/jpeg' }),
+ }),
+ );
+ const img = await rtl.waitFor(() => {
+ const found = container.querySelector('img.chat-image-media');
+ assert.ok(found, 'the archived image did not render');
+ return found;
+ });
+ assert.ok(img.classList.contains('chat-image-media-archived'));
+ // The placeholder is a 14px spinner plus .25rem of margin; an image has no box until it decodes and
+ // brings .5rem of its own. A shorter thread clamps a scroll position pinned to the bottom, and the
+ // browser reports the clamp as the reader scrolling away.
+ const css = readFileSync(new URL('../../pages/Chats.css', import.meta.url), 'utf8');
+ assert.match(css, /\.chat-image-media-archived\s*\{[^}]*min-height:\s*calc\(14px - 0\.25rem\)/);
+});
diff --git a/dashboard/src/components/chats/ArchivedMediaPreview.tsx b/dashboard/src/components/chats/ArchivedMediaPreview.tsx
index fc1a451c1..2dff9a701 100644
--- a/dashboard/src/components/chats/ArchivedMediaPreview.tsx
+++ b/dashboard/src/components/chats/ArchivedMediaPreview.tsx
@@ -150,7 +150,7 @@ function ArchivedMediaPreview({
<img
src={state.url}
alt={alt ?? ''}
- className="chat-image-media"
+ className="chat-image-media chat-image-media-archived"
ref={measureMedia}
onLoad={onMediaLoad}
role="button"
diff --git a/dashboard/src/pages/Chats.css b/dashboard/src/pages/Chats.css
index 48609ff2c..89b79d19a 100644
--- a/dashboard/src/pages/Chats.css
+++ b/dashboard/src/pages/Chats.css
@@ -972,6 +972,15 @@
object-fit: cover;
}
+/* An archived preview swaps a 14px spinner (plus .25rem of margin) for an image that has no box until it
+ decodes. Holding that box at the difference to the image's own .5rem of margin keeps the swap from
+ shortening the thread: a shorter thread clamps a scroll position pinned to the bottom, and the clamp
+ reaches the scroll hook as the reader scrolling away. It also makes the box the hook seeds at mount
+ exactly what the thread gains once the image decodes. */
+.chats-page .chat-image-media-archived {
+ min-height: calc(14px - 0.25rem);
+}
+
/* A button, not a label: the bytes are fetchable from the per-message media route, so this is the
viewer's handle on media the list did not inline. Styled to keep the previous inert appearance
apart from the affordance. */