Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(dashboard): stop the older-page row from moving the thread
Yudhi Armyndharis95714d64f920
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex fff8f42e3..4790238b4 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -54,6 +54,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0- Keep the dashboard chat's scroll-to-bottom button in view while the reader is scrolled up, where it moved with the thread and was off screen.- Land the dashboard chat's scroll-to-bottom button at the bottom when an older page arrives meanwhile, where the animated jump could end far above it.- Keep the dashboard's reaction popover inside the thread, where the emoji nearest one of its edges was clipped and could not be picked.+- Keep the dashboard chat's content still while an older page loads and lands, where the loading row pushed it down by its height and back up.- Refuse to save a local `storage.localPath` the app cannot create or write, where the next start refused to boot and the dashboard that could undo the save was down.- Answer `400` for a send route's or a product send's `chatId`, or a bulk `batchId`, over 255 characters, where PostgreSQL answered `500` once the value passed its index entry limit.- Answer `400` for a `chatId` over 255 characters in the request body of a chat action, as the send routes do, instead of handing it to the engine.diff --git a/dashboard/src/components/chats/ChatThread.test.ts b/dashboard/src/components/chats/ChatThread.test.tsindex 60d9fa675..455f7bbef 100644--- a/dashboard/src/components/chats/ChatThread.test.ts+++ b/dashboard/src/components/chats/ChatThread.test.ts@@ -5,7 +5,7 @@ import '../../test-helpers/register-hooks.ts';import { test, before, after, afterEach, mock } from 'node:test';import assert from 'node:assert/strict';import { readFileSync } from 'node:fs';-import { createElement, createRef } from 'react';+import { createElement, createRef, type ComponentProps } from 'react';import type { Chat } from '../../services/api.ts';import type { ChatMessageView } from '../../utils/chatMessages.ts';@@ -79,6 +79,7 @@ function renderThread(role: string,messages: ChatMessageView[] = [PROMPT],activeChat: Chat = CHAT,+ props: Partial<ComponentProps<typeof ChatThread>> = {},): { clicks: string[]; container: HTMLElement; rerenderWith: (next: ChatMessageView[]) => void } {window.sessionStorage.setItem('openwa_user_role', role);const clicks: string[] = [];@@ -107,6 +108,7 @@ function renderThread(onClickButton: async (_message, button) => {clicks.push(button.id);},+ ...props,}),);const { container, rerender } = rtl.render(tree(messages));@@ -994,8 +996,8 @@ test('focus held for a control survives the page losing focus, and is given backassert.equal(focusedMessage(), 'wamid.3');});-// What it got back with the page is not a new focus to classify: an engine that does not call it-// :focus-visible would otherwise make it one a pointer brought, and the place held for the keyboard is dropped.+// The focus given back with the page is not classified again: the place held for the keyboard is kept and+// pointer mode is not entered, whether or not the engine calls that focus :focus-visible.test('focus given back with the page keeps what was held, whatever :focus-visible says', () => {const [a, b, c]: ChatMessageView[] = ['1', '2', '3'].map(n => ({...PROMPT,@@ -1156,6 +1158,233 @@ test('the scroll-to-bottom button is sticky inside the scroller, not absolute, aassert.ok(level(rule) < level(menu), 'the jump button paints over the actions menu');});+// The stylesheet without its comments, and what is read from it. jsdom has no layout, so the declarations are+// read and evaluated.+const chatsCss = readFileSync(new URL('../../pages/Chats.css', import.meta.url), 'utf8').replace(+ /\/\*[\s\S]*?\*\//g,+ '',+);++/** The `@container` blocks of a stylesheet: the condition, and what is between the braces. */+function containerBlocks(source: string): Array<{ condition: string; body: string }> {+ const blocks: Array<{ condition: string; body: string }> = [];+ for (const head of source.matchAll(/@container\s*([^{]*)\{/g)) {+ const from = (head.index ?? 0) + head[0].length;+ let depth = 1;+ let at = from;+ while (depth > 0 && at < source.length) {+ if (source[at] === '{') depth += 1;+ else if (source[at] === '}') depth -= 1;+ at += 1;+ }+ blocks.push({ condition: head[1].trim(), body: source.slice(from, at - 1) });+ }+ return blocks;+}++/** The declarations of the rule written with exactly `selector`, by property. */+function declarationsOf(source: string, selector: string): Record<string, string> {+ const at = source.indexOf(`${selector} {`);+ assert.ok(at >= 0, `${selector} has a rule`);+ const body = source.slice(source.indexOf('{', at) + 1, source.indexOf('}', at));+ const entries = body+ .split(';')+ .map(declaration => declaration.split(':'))+ .filter(parts => parts.length >= 2)+ .map(([name, ...value]): [string, string] => [name.trim(), value.join(':').trim()]);+ return Object.fromEntries(entries);+}++// A length in px: rem is 16px and em is the given font size, var() is the declared custom property, and calc+// is plain arithmetic.+function lengthPx(value: string, vars: Record<string, string> = {}, emPx = 16): number {+ const expression = value+ .replace(/var\((--[\w-]+)\)/g, (_, name: string) => `(${vars[name]})`)+ .replace(/calc/g, '')+ .replace(/(-?\d*\.?\d+)rem/g, '($1*16)')+ .replace(/(-?\d*\.?\d+)em/g, `($1*${emPx})`)+ .replace(/px/g, '');+ return Function(`return (${expression})`)() as number;+}++// The older-page indicator sat in flow above the oldest bubble, so it pushed the reader's content down by its+// height and one gap when the page was requested, and back up when it landed. The loading pill's height and+// margins add up to minus the thread's gap, so it adds nothing to the scroll height, and the failure is out of+// flow, so it adds nothing at whatever height its text needs.+test('the older-page indicator takes no room in the thread, loading or failed', () => {+ const rule = (selector: string) => declarationsOf(chatsCss, selector);+ const thread = rule('.chats-page .room-messages');+ const gap = lengthPx(thread.gap);+ const padding = lengthPx(thread.padding);+ const loading = rule('.chats-page .messages-loading-older');+ const failed = rule('.chats-page .messages-loading-older.failed');+ const failedText = rule('.chats-page .messages-loading-older.failed > span');+ const text = rule('.chats-page .messages-loading-older > span');+ const own = { '--older-row-height': loading['--older-row-height'] };++ const outer =+ lengthPx(loading['margin-top'], own) + lengthPx(loading.height, own) + lengthPx(loading['margin-bottom'], own);+ assert.equal(outer, -gap, "the loading indicator's margins and height add up to the thread's gap, minus it");+ assert.equal(loading.position, 'sticky', 'the loading indicator holds to the top edge of the pane (sticky)');+ assert.ok(+ padding + lengthPx(loading['margin-top'], own) >= 0,+ 'the loading indicator is lifted no further than the padding above the first message',+ );+ // Sticky offsets are measured from the padding edge, so top is the margin that lifts it: any other value+ // pushes it down onto the first bubble when the thread is at its top.+ assert.equal(+ lengthPx(loading.top, own),+ lengthPx(loading['margin-top'], own),+ "the loading indicator's sticky offset is its lift into the padding",+ );+ assert.equal(+ loading['pointer-events'],+ 'none',+ 'the loading indicator passes pointer events to the bubbles under it',+ );++ // Out of flow, the failure adds nothing to the thread whatever its height, and it stays at the top of the+ // thread instead of following the reader. Its text wraps up to two lines, and they have to end where the text+ // of the first message begins: a reader at the top of the thread is on that message.+ assert.equal(failed.position, 'absolute', 'the failure indicator is out of flow (position: absolute)');+ assert.ok(lengthPx(failed.top, own) >= 0, 'the failure indicator starts inside the pane (top is not negative)');+ assert.match(failed['max-width'], /100%/, 'the failure indicator is no wider than the pane (max-width is a share)');+ assert.equal(failed.height, 'auto', 'the failure indicator is as tall as its text (height: auto)');+ assert.equal(failedText['white-space'], 'normal', 'the failure text wraps (white-space: normal)');+ const lineClamp = Number(failedText['-webkit-line-clamp']);+ assert.equal(lineClamp, 2, 'the failure text is limited to two lines (-webkit-line-clamp: 2)');++ const fontSize = lengthPx(failed['font-size'], own);+ const line = fontSize * Number(loading['line-height']);+ const border = lengthPx(loading.border.split(' ')[0], own);+ const paddingBlock = lengthPx(failed.padding.split(' ')[0], own);+ const clipRoom = lengthPx(text['padding-block'], own, fontSize);+ const box = Math.max(lineClamp * line + 2 * (border + paddingBlock), lengthPx(failed['min-height'], own));+ // The text paints into the room the clip leaves it below the last line, past the border.+ const ink = border + paddingBlock + lineClamp * line + clipRoom;+ const bubble = rule('.chats-page .message-bubble');+ const textStarts = padding + lengthPx(bubble.padding.split(' ')[0], own);+ assert.ok(+ lengthPx(failed.top, own) + Math.max(box, ink) <= textStarts,+ "the failure indicator, at two lines, ends above the first message's text",+ );+});++// The text of the indicator clips, for its ellipsis and for the limit on the failure's lines, and a line box is+// shorter than the glyphs of some scripts: the tails of g and p, Telugu conjuncts below the base, Arabic marks.+// The padding is the room the clip leaves them and the negative margin takes it back, so the box lays out as+// the line it is.+test('the text of the older-page indicator has room to paint beyond its line without taking any', () => {+ const text = declarationsOf(chatsCss, '.chats-page .messages-loading-older > span');+ assert.equal(text.overflow, 'hidden', 'the text clips (overflow: hidden)');+ for (const axis of ['block', 'inline']) {+ const room = lengthPx(text[`padding-${axis}`]);+ assert.ok(room > 0, `the text has room to paint beyond its line in the ${axis} direction`);+ assert.equal(+ lengthPx(text[`margin-${axis}`]),+ -room,+ `the room in the ${axis} direction is taken back by the margin`,+ );+ }+ // The tallest marks seen (Telugu below the base, in WebKit) need a quarter of the size of the text.+ assert.match(text['padding-block'], /^[\d.]+em$/, 'the room is in em, so it follows the size of the text');+ assert.ok(+ Number.parseFloat(text['padding-block']) >= 0.25,+ 'the room above and below a line is a quarter em or more',+ );+});++// The failure shows its whole sentence while the thread is wide enough for two lines of it, and only the retry+// instruction when it is not. The width that decides it is the thread's, not the viewport's: beside the list the+// thread is narrower than a phone's. Both texts are in the document and the stylesheet shows one.+test('the failure indicator shows its retry instruction alone in a thread too narrow for the sentence', () => {+ const thread = declarationsOf(chatsCss, '.chats-page .room-messages');+ assert.equal(+ thread['container-type'],+ 'inline-size',+ 'the thread is the container the failure text is sized against',+ );++ const hint = declarationsOf(chatsCss, '.chats-page .messages-loading-older.failed > .older-failure-hint');+ assert.equal(hint.display, 'none', 'the retry instruction alone is hidden while the sentence is shown');++ const blocks = containerBlocks(chatsCss);+ assert.equal(blocks.length, 2, 'the indicator changes at two widths: the failure text, and the loading label');+ const narrow = blocks.find(block => block.body.includes('.older-failure-hint'));+ assert.ok(narrow, 'the failure text has a width at which it changes');+ const limit = /^\(max-width:\s*([\d.]+)rem\)$/.exec(narrow.condition);+ assert.ok(limit, `the width is a number of rem, not of px or of the viewport: ${narrow.condition}`);+ // The container is the scroller and the query measures its content box: the client width, which leaves out a+ // scrollbar, less the padding of 1.5rem on each side.+ const clientWidth =+ Number(limit[1]) * 16 + 2 * lengthPx(declarationsOf(chatsCss, '.chats-page .room-messages').padding);+ assert.ok(+ clientWidth >= 308,+ 'the sentence is not shown at a client width under the 308px its longest translation needs',+ );+ assert.ok(+ clientWidth < 326,+ 'the sentence is shown at 326px of client width, which a 360px phone has with an overlay scrollbar',+ );+ const full = declarationsOf(narrow.body, '.chats-page .messages-loading-older.failed > .older-failure-full');+ assert.equal(full.display, 'none', 'the whole sentence is hidden in a narrow thread');+ const shown = declarationsOf(narrow.body, '.chats-page .messages-loading-older.failed > .older-failure-hint');+ assert.equal(+ shown.display,+ '-webkit-box',+ 'the retry instruction is shown in a narrow thread, clamped as the sentence is',+ );+});++// The loading label is one line while the pill fits it, and two lines under that, at the size of the failure+// text. The pill is taller there, and its margins take the height back all the same.+test('the loading indicator takes two lines in a thread narrower than its longest label, and no more room', () => {+ const blocks = containerBlocks(chatsCss);+ const wrapped = blocks.find(block => block.body.includes(':not(.failed)'));+ assert.ok(wrapped, 'the loading label has a width at which it wraps');+ const limit = /^\(max-width:\s*([\d.]+)rem\)$/.exec(wrapped.condition);+ assert.ok(limit, `the width is a number of rem, not of px or of the viewport: ${wrapped.condition}`);+ const contentPx = Number(limit[1]) * 16;+ // The French label, the longest of the translations, is 285px wide with its icon, padding and border.+ assert.ok(contentPx >= 285, 'a thread that holds the longest label on one line is not wrapped');+ assert.ok(contentPx - 285 < 16, 'the label is not wrapped in a thread with more than a rem to spare');++ const thread = declarationsOf(chatsCss, '.chats-page .room-messages');+ const gap = lengthPx(thread.gap);+ const padding = lengthPx(thread.padding);+ const base = declarationsOf(chatsCss, '.chats-page .messages-loading-older');+ const pill = declarationsOf(wrapped.body, '.chats-page .messages-loading-older:not(.failed)');+ const own = { '--older-row-height': pill['--older-row-height'] };+ assert.equal(+ lengthPx(base['margin-top'], own) + lengthPx(base.height, own) + lengthPx(base['margin-bottom'], own),+ -gap,+ 'the taller pill still adds nothing to the thread: its margins and height add up to minus the gap',+ );++ const text = declarationsOf(wrapped.body, '.chats-page .messages-loading-older:not(.failed) > span');+ assert.equal(text['white-space'], 'normal', 'the label wraps (white-space: normal)');+ const lines = Number(text['-webkit-line-clamp']);+ assert.equal(lines, 2, 'the label is limited to two lines (-webkit-line-clamp: 2)');+ const line = lengthPx(pill['font-size'], own) * Number(base['line-height']);+ const border = lengthPx(base.border.split(' ')[0], own);+ const height = lengthPx(base.height, own);+ assert.ok(lines * line + 2 * border <= height, 'the two lines fit inside the height of the pill');+ const bubble = declarationsOf(chatsCss, '.chats-page .message-bubble');+ const textStarts = padding + lengthPx(bubble.padding.split(' ')[0], own);+ const top = padding + lengthPx(base['margin-top'], own);+ assert.ok(top + height <= textStarts, "the wrapped pill ends above the first message's text");+});++test('a failed older page renders the whole sentence and the retry instruction as two texts', () => {+ const { container } = renderThread('operator', [PROMPT], CHAT, { messagesError: true });+ const pill = container.querySelector<HTMLElement>('.messages-loading-older.failed');+ assert.ok(pill, 'the failure is shown above a loaded thread');+ const full = pill.querySelector<HTMLElement>('.older-failure-full');+ const hint = pill.querySelector<HTMLElement>('.older-failure-hint');+ assert.equal(full?.textContent, "Couldn't load older messages. Scroll up to retry.");+ assert.equal(hint?.textContent, 'Scroll up to retry.');+});+// An own bubble is at the end of the pane, and the react icon of its pill is a few pixels from that end: a// popover centred on it runs past the pane, so the last emoji is clipped and the thread scrolls sideways.test('the reaction popover of an own message grows from the end of its icon, not from its centre', () => {diff --git a/dashboard/src/components/chats/ChatThread.tsx b/dashboard/src/components/chats/ChatThread.tsxindex ad1dab31e..c75200ab9 100644--- a/dashboard/src/components/chats/ChatThread.tsx+++ b/dashboard/src/components/chats/ChatThread.tsx@@ -410,15 +410,14 @@ function ChatThread({if (!pageLostFocus) keyboardFocusRef.current = null;}}>- {/* Older-page spinner, or the failure in its place. An in-flow sibling before the thread, not- an overlay — it pushes the oldest bubble down, which is why useChatScrollPosition reads- this container's height at REQUEST time (before this renders), not on whichever commit- happens to change it first. Shown whenever there IS a thread to sit above — including a- failed older-page fetch with messages already loaded, which must not fall through to the- full-screen error below: that would replace the loaded thread with a placeholder,- collapsing the scroll container so the failed page can never be retried by scrolling. */}+ {/* Older-page spinner, or the failure in its place. It takes no room in the thread (Chats.css):+ a row in flow would push the oldest bubble down when the page is requested and back up when it+ lands. Shown whenever there IS a thread to sit above, including a failed older-page fetch with+ messages already loaded, which must not fall through to the full-screen error below: that would+ replace the loaded thread with a placeholder, collapsing the scroll container so the failed+ page can never be retried by scrolling. */}{!loadingMessages && (loadingOlderMessages || (messagesError && messages.length > 0)) && (- <div className="messages-loading-older">+ <div className={loadingOlderMessages ? 'messages-loading-older' : 'messages-loading-older failed'}>{loadingOlderMessages ? (<><Loader2 className="animate-spin" size={18} />@@ -427,7 +426,11 @@ function ChatThread({) : (<><AlertCircle size={18} />- <span>{t('chats.loadOlderMessagesError')}</span>+ {/* The whole sentence, or only the retry instruction when the thread is too narrow to fit+ the whole one in two lines: Chats.css shows one of them, and hides the other from+ assistive technology as well. */}+ <span className="older-failure-full">{t('chats.loadOlderMessagesError')}</span>+ <span className="older-failure-hint">{t('chats.loadOlderMessagesRetryHint')}</span></>)}</div>diff --git a/dashboard/src/hooks/useChatScrollPosition.render.test.ts b/dashboard/src/hooks/useChatScrollPosition.render.test.tsindex f1b2b8f91..26c3ba839 100644--- a/dashboard/src/hooks/useChatScrollPosition.render.test.ts+++ b/dashboard/src/hooks/useChatScrollPosition.render.test.ts@@ -127,9 +127,15 @@ test('an older page holds the reader by their message, not by every pixel the threquest.current?.();rerender(createElement(Older, { fetching: true }));- // The page lands: 2000px of history above, and a 230px preview swapped in below m3 meanwhile.+ // A 230px preview swaps in below m3 while the page is out, on a commit of its own before the page lands.+ // Nothing is applied for it, and it must not use up what is owed to the page.+ height += 230;+ rerender(createElement(Older, { fetching: true }));+ assert.equal(el.scrollTop, 400, 'a commit while the page was out moved the reader');++ // The page lands: 2000px of history above.for (const [id, y] of [...messageTops]) messageTops.set(id, y + 2000);- height += 2000 + 230;+ height += 2000;rerender(createElement(Older, { fetching: false }));assert.equal(el.scrollTop, 400 + 2000, 'the reader moved by more or less than the history above them');diff --git a/dashboard/src/hooks/useChatScrollPosition.ts b/dashboard/src/hooks/useChatScrollPosition.tsindex 31aa9406e..fe036e0b6 100644--- a/dashboard/src/hooks/useChatScrollPosition.ts+++ b/dashboard/src/hooks/useChatScrollPosition.ts@@ -253,11 +253,12 @@ export function useChatScrollPosition(// backwards at the exact moment they asked for more.//// The reader's element and its offset are read when the page is REQUESTED and the delta applied on- // the commit where the in-flight flag falls — not on the first commit whose height changed, because- // the older-page spinner is an in-flow child of this same container (ChatThread) and its own ~46px- // arrives one commit earlier. `scrollTop` is read live at apply time, so a deliberate reposition- // made during the fetch survives. The pin/restore machinery above is not reused: it writes an- // ABSOLUTE target, which is unknowable here.+ // the commit where the in-flight flag falls, not on the first commit whose height changed, which+ // may be a live message or a preview decoding while the page is out. The older-page indicator is not+ // one of those: it takes no room in the thread (Chats.css), so it moves nothing when it appears and+ // the request-time position is still the reader's when the page lands. `scrollTop` is read live at+ // apply time, so a deliberate reposition made during the fetch survives. The pin/restore machinery+ // above is not reused: it writes an ABSOLUTE target, which is unknowable here.useLayoutEffect(() => {const el = containerRef.current;const wasFetching = wasFetchingOlderRef.current;diff --git a/dashboard/src/i18n/locales/ar.json b/dashboard/src/i18n/locales/ar.jsonindex 63ceeb7d3..c49e06a77 100644--- a/dashboard/src/i18n/locales/ar.json+++ b/dashboard/src/i18n/locales/ar.json@@ -107,6 +107,7 @@"loadingMessages": "جارٍ تحميل الرسائل...","loadingOlderMessages": "جارٍ تحميل الرسائل الأقدم...","loadOlderMessagesError": "تعذر تحميل الرسائل الأقدم. مرر لأعلى للمحاولة مرة أخرى.",+ "loadOlderMessagesRetryHint": "مرر لأعلى للمحاولة مرة أخرى.","noMessagesInChat": "لا توجد رسائل بعد. أرسل الرسالة الأولى للبدء!","downloadDocument": "تنزيل المستند","actions": {diff --git a/dashboard/src/i18n/locales/de.json b/dashboard/src/i18n/locales/de.jsonindex da1e6d8c5..5066067bd 100644--- a/dashboard/src/i18n/locales/de.json+++ b/dashboard/src/i18n/locales/de.json@@ -95,6 +95,7 @@"loadingMessages": "Nachrichten werden geladen...","loadingOlderMessages": "Ältere Nachrichten werden geladen...","loadOlderMessagesError": "Ältere Nachrichten konnten nicht geladen werden. Zum erneuten Versuch nach oben scrollen.",+ "loadOlderMessagesRetryHint": "Zum erneuten Versuch nach oben scrollen.","noMessagesInChat": "Noch keine Nachrichten. Sende die erste Nachricht, um zu beginnen!","downloadDocument": "Dokument herunterladen","actions": {diff --git a/dashboard/src/i18n/locales/en.json b/dashboard/src/i18n/locales/en.jsonindex 744d011be..5fb4afae4 100644--- a/dashboard/src/i18n/locales/en.json+++ b/dashboard/src/i18n/locales/en.json@@ -95,6 +95,7 @@"loadingMessages": "Loading messages...","loadingOlderMessages": "Loading older messages...","loadOlderMessagesError": "Couldn't load older messages. Scroll up to retry.",+ "loadOlderMessagesRetryHint": "Scroll up to retry.","noMessagesInChat": "No messages yet. Send the first message to get started!","downloadDocument": "Download document","actions": {diff --git a/dashboard/src/i18n/locales/es.json b/dashboard/src/i18n/locales/es.jsonindex 10f5542b9..68725f88c 100644--- a/dashboard/src/i18n/locales/es.json+++ b/dashboard/src/i18n/locales/es.json@@ -98,6 +98,7 @@"loadingMessages": "Cargando mensajes...","loadingOlderMessages": "Cargando mensajes anteriores...","loadOlderMessagesError": "No se pudieron cargar los mensajes anteriores. Desplázate hacia arriba para reintentar.",+ "loadOlderMessagesRetryHint": "Desplázate hacia arriba para reintentar.","noMessagesInChat": "Aún no hay mensajes. ¡Envía el primero para empezar!","downloadDocument": "Descargar documento","actions": {diff --git a/dashboard/src/i18n/locales/fr.json b/dashboard/src/i18n/locales/fr.jsonindex 2712e930f..85957645a 100644--- a/dashboard/src/i18n/locales/fr.json+++ b/dashboard/src/i18n/locales/fr.json@@ -98,6 +98,7 @@"loadingMessages": "Chargement des messages...","loadingOlderMessages": "Chargement des messages plus anciens...","loadOlderMessagesError": "Impossible de charger les messages plus anciens. Faites défiler vers le haut pour réessayer.",+ "loadOlderMessagesRetryHint": "Faites défiler vers le haut pour réessayer.","noMessagesInChat": "Aucun message pour le moment. Envoyez le premier message pour commencer !","downloadDocument": "Télécharger le document","actions": {diff --git a/dashboard/src/i18n/locales/he.json b/dashboard/src/i18n/locales/he.jsonindex 25ae8e1ca..9c3e55c5b 100644--- a/dashboard/src/i18n/locales/he.json+++ b/dashboard/src/i18n/locales/he.json@@ -101,6 +101,7 @@"loadingMessages": "טוען הודעות...","loadingOlderMessages": "טוען הודעות ישנות יותר...","loadOlderMessagesError": "טעינת ההודעות הישנות נכשלה. גלול למעלה כדי לנסות שוב.",+ "loadOlderMessagesRetryHint": "גלול למעלה כדי לנסות שוב.","noMessagesInChat": "אין הודעות עדיין. שלח את ההודעה הראשונה כדי להתחיל!","downloadDocument": "הורדת מסמך","actions": {diff --git a/dashboard/src/i18n/locales/hi.json b/dashboard/src/i18n/locales/hi.jsonindex 9c12490b9..ac67d27fb 100644--- a/dashboard/src/i18n/locales/hi.json+++ b/dashboard/src/i18n/locales/hi.json@@ -95,6 +95,7 @@"loadingMessages": "संदेश लोड हो रहे हैं...","loadingOlderMessages": "पुराने संदेश लोड हो रहे हैं...","loadOlderMessagesError": "पुराने संदेश लोड नहीं किए जा सके। पुनः प्रयास करने के लिए ऊपर स्क्रॉल करें।",+ "loadOlderMessagesRetryHint": "पुनः प्रयास करने के लिए ऊपर स्क्रॉल करें।","noMessagesInChat": "अभी तक कोई संदेश नहीं। आरंभ करने के लिए पहला संदेश भेजें!","downloadDocument": "दस्तावेज़ डाउनलोड करें","actions": {diff --git a/dashboard/src/i18n/locales/id.json b/dashboard/src/i18n/locales/id.jsonindex 84defb945..2359d3af5 100644--- a/dashboard/src/i18n/locales/id.json+++ b/dashboard/src/i18n/locales/id.json@@ -95,6 +95,7 @@"loadingMessages": "Memuat pesan...","loadingOlderMessages": "Memuat pesan lama...","loadOlderMessagesError": "Gagal memuat pesan lama. Gulir ke atas untuk mencoba lagi.",+ "loadOlderMessagesRetryHint": "Gulir ke atas untuk mencoba lagi.","noMessagesInChat": "Belum ada pesan. Kirim pesan pertama untuk memulai!","downloadDocument": "Unduh dokumen","actions": {diff --git a/dashboard/src/i18n/locales/it.json b/dashboard/src/i18n/locales/it.jsonindex 8472020b5..bb779bef3 100644--- a/dashboard/src/i18n/locales/it.json+++ b/dashboard/src/i18n/locales/it.json@@ -98,6 +98,7 @@"loadingMessages": "Caricamento messaggi...","loadingOlderMessages": "Caricamento messaggi precedenti...","loadOlderMessagesError": "Impossibile caricare i messaggi precedenti. Scorri verso l’alto per riprovare.",+ "loadOlderMessagesRetryHint": "Scorri verso l’alto per riprovare.","noMessagesInChat": "Ancora nessun messaggio. Invia il primo messaggio per iniziare!","downloadDocument": "Scarica documento","actions": {diff --git a/dashboard/src/i18n/locales/ko.json b/dashboard/src/i18n/locales/ko.jsonindex 5fcbc8f85..ca0bd35c0 100644--- a/dashboard/src/i18n/locales/ko.json+++ b/dashboard/src/i18n/locales/ko.json@@ -95,6 +95,7 @@"loadingMessages": "메시지 불러오는 중...","loadingOlderMessages": "이전 메시지 불러오는 중...","loadOlderMessagesError": "이전 메시지를 불러오지 못했습니다. 위로 스크롤하여 다시 시도하세요.",+ "loadOlderMessagesRetryHint": "위로 스크롤하여 다시 시도하세요.","noMessagesInChat": "아직 메시지가 없습니다. 첫 메시지를 보내 대화를 시작하세요!","downloadDocument": "문서 다운로드","actions": {diff --git a/dashboard/src/i18n/locales/pt-BR.json b/dashboard/src/i18n/locales/pt-BR.jsonindex e723b7826..8faa2e3f9 100644--- a/dashboard/src/i18n/locales/pt-BR.json+++ b/dashboard/src/i18n/locales/pt-BR.json@@ -98,6 +98,7 @@"loadingMessages": "Carregando mensagens...","loadingOlderMessages": "Carregando mensagens anteriores...","loadOlderMessagesError": "Não foi possível carregar mensagens anteriores. Role para cima para tentar novamente.",+ "loadOlderMessagesRetryHint": "Role para cima para tentar novamente.","noMessagesInChat": "Ainda não há mensagens. Envie a primeira para começar!","downloadDocument": "Baixar documento","actions": {diff --git a/dashboard/src/i18n/locales/te.json b/dashboard/src/i18n/locales/te.jsonindex 92cad46c9..799959ba8 100644--- a/dashboard/src/i18n/locales/te.json+++ b/dashboard/src/i18n/locales/te.json@@ -95,6 +95,7 @@"loadingMessages": "సందేశాలను లోడ్ చేస్తోంది...","loadingOlderMessages": "పాత సందేశాలను లోడ్ చేస్తోంది...","loadOlderMessagesError": "పాత సందేశాలను లోడ్ చేయడం విఫలమైంది. మళ్లీ ప్రయత్నించడానికి పైకి స్క్రోల్ చేయండి.",+ "loadOlderMessagesRetryHint": "మళ్లీ ప్రయత్నించడానికి పైకి స్క్రోల్ చేయండి.","noMessagesInChat": "ఇంకా సందేశాలు లేవు. ప్రారంభించడానికి మొదటి సందేశాన్ని పంపండి!","downloadDocument": "డాక్యుమెంట్ను డౌన్లోడ్ చేయి","actions": {diff --git a/dashboard/src/i18n/locales/tr.json b/dashboard/src/i18n/locales/tr.jsonindex ddc05b960..a2b9e76a1 100644--- a/dashboard/src/i18n/locales/tr.json+++ b/dashboard/src/i18n/locales/tr.json@@ -95,6 +95,7 @@"loadingMessages": "Mesajlar yükleniyor...","loadingOlderMessages": "Daha eski mesajlar yükleniyor...","loadOlderMessagesError": "Daha eski mesajlar yüklenemedi. Tekrar denemek için yukarı kaydırın.",+ "loadOlderMessagesRetryHint": "Tekrar denemek için yukarı kaydırın.","noMessagesInChat": "Henüz mesaj yok. Başlamak için ilk mesajı gönderin!","downloadDocument": "Belgeyi indir","actions": {diff --git a/dashboard/src/i18n/locales/zh-CN.json b/dashboard/src/i18n/locales/zh-CN.jsonindex 8ee1c8c7f..826be3ee6 100644--- a/dashboard/src/i18n/locales/zh-CN.json+++ b/dashboard/src/i18n/locales/zh-CN.json@@ -95,6 +95,7 @@"loadingMessages": "正在加载消息...","loadingOlderMessages": "正在加载更早的消息...","loadOlderMessagesError": "无法加载更早的消息。向上滚动重试。",+ "loadOlderMessagesRetryHint": "向上滚动重试。","noMessagesInChat": "暂无消息。发送第一条消息即可开始!","downloadDocument": "下载文档","actions": {diff --git a/dashboard/src/i18n/locales/zh-HK.json b/dashboard/src/i18n/locales/zh-HK.jsonindex bc00e55bb..230c9b385 100644--- a/dashboard/src/i18n/locales/zh-HK.json+++ b/dashboard/src/i18n/locales/zh-HK.json@@ -95,6 +95,7 @@"loadingMessages": "正在載入訊息...","loadingOlderMessages": "正在載入較舊的訊息...","loadOlderMessagesError": "無法載入較舊的訊息。向上捲動重試。",+ "loadOlderMessagesRetryHint": "向上捲動重試。","noMessagesInChat": "尚無訊息。傳送第一則訊息即可開始!","downloadDocument": "下載文件","actions": {diff --git a/dashboard/src/pages/Chats.css b/dashboard/src/pages/Chats.cssindex f49776417..7104cc64e 100644--- a/dashboard/src/pages/Chats.css+++ b/dashboard/src/pages/Chats.css@@ -450,6 +450,10 @@background-image: radial-gradient(var(--border) 1px, transparent 0);background-size: 24px 24px;position: relative;+ /* The failure indicator's text is set against the width of the thread (the container query below), not the+ viewport: beside the list at an 890px viewport its client width is 244px, narrower than the 286px of a+ 320px phone. */+ container-type: inline-size;}/* Floating scroll-to-bottom button. Sits at the bottom-right of the messages pane (not the footer)@@ -507,17 +511,136 @@gap: 0.75rem;}-/* Sits inline above the oldest bubble, so unlike .messages-loading it must not take the flex- remainder — that would push the thread out of view while an older page loads. */+/* The older-page indicator (ChatThread): a pill that holds to the top edge of the pane while a page loads,+ and the failure to load one. Neither takes room in the thread: a row in flow adds its height and one flex+ gap above the oldest bubble, which pushed the reader's content down by that much when the page was+ requested and back up when it landed. The loading pill's height is explicit, and its margins take it and+ the gap back (the gap is the 0.75rem of .room-messages), as the scroll-to-bottom button does, so the+ thread lays out the same with and without the row. The top margin lifts it into the 1.5rem of padding,+ clear of the first bubble when the thread is at its top, whatever its height; the bottom margin is what is+ left to add up to minus the gap. It never takes a pointer event from a bubble under it, and it must not+ take the flex remainder either. */.chats-page .messages-loading-older {+ --older-row-height: 1.25rem;+ position: sticky;+ /* Sticky offsets are measured from the scroller's padding edge: the 1.5rem of padding back out, less+ the 0.125rem the pill keeps from the pane's edge. */+ top: -1.375rem;+ z-index: 4;+ align-self: center;+ flex: none;+ box-sizing: border-box;display: flex;align-items: center;justify-content: center;- flex: 0 0 auto;+ gap: 0.375rem;+ max-width: 100%;+ height: var(--older-row-height);+ margin-top: -1.375rem;+ margin-bottom: calc(0.625rem - var(--older-row-height));+ padding: 0 0.75rem;+ border: 1px solid var(--border);+ border-radius: 999px;+ background: var(--bg-white);+ box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);color: var(--text-muted);- font-size: 0.8125rem;- gap: 0.5rem;- padding: 0.5rem 0;+ font-size: 0.75rem;+ line-height: 1.25;+ pointer-events: none;+}++.chats-page .messages-loading-older > svg {+ flex: none;+ width: 0.875rem;+ height: 0.875rem;+}++/* The text has to clip (the ellipsis, and the line limit of the failure, need overflow other than visible),+ and a line box is shorter than the glyphs of some scripts: the tails of g and p, Telugu conjuncts below the+ base, Arabic marks above and below the letters. The padding is the room the clip leaves them, and the+ negative margin takes it back, so the span lays out as the line it is. */+.chats-page .messages-loading-older > span {+ min-width: 0;+ padding-block: 0.25em;+ padding-inline: 0.15em;+ margin-block: -0.25em;+ margin-inline: -0.15em;+ overflow: hidden;+ text-overflow: ellipsis;+ white-space: nowrap;+}++/* The failure carries the retry hint, so it wraps; its height is not known, and no margin can take it back. It+ is out of flow instead, so it takes no room at any height. It is not the reader's to carry through the+ thread: it stays at the top of the thread, where scrolling up again retries. Centred by its auto margins, as+ wide as its text up to the pane less its inset. It is held to two lines, which end inside the 1.5rem of+ padding and the top padding of the first bubble: a reader at the top of the thread is on that message, and a+ third line would run over its first line of text. Two lines hold the whole sentence of every translation+ while the thread is as wide as the container query below says; under that only the retry instruction is+ shown. */+.chats-page .messages-loading-older.failed {+ position: absolute;+ top: 0.125rem;+ inset-inline: 0.25rem;+ width: max-content;+ max-width: calc(100% - 0.5rem);+ height: auto;+ min-height: var(--older-row-height);+ margin: 0 auto;+ padding: 0 0.5rem;+ border-radius: 0.875rem;+ font-size: 0.6875rem;+}++.chats-page .messages-loading-older.failed > span {+ display: -webkit-box;+ -webkit-box-orient: vertical;+ -webkit-line-clamp: 2;+ overflow-wrap: anywhere;+ text-align: center;+ white-space: normal;+}++.chats-page .messages-loading-older.failed > .older-failure-hint {+ display: none;+}++/* Where the thread is too narrow for two lines of the whole sentence, only the retry instruction is shown.+ The width queried is the content box of the thread: its client width, which leaves out a scrollbar, less+ the 1.5rem of padding on each side. 17rem of it is a client width of 320px. The longest sentence, the German+ one, needs 308px of client width for two lines in every engine. A 360px phone has 326px, and shows the+ sentence with an overlay scrollbar; a classic scrollbar of 6px leaves it 320px, and the instruction alone+ is shown. The instruction is two lines at most in the narrowest thread there is, 244px of client width+ beside the list at an 890px viewport (238px with a scrollbar of 6px). display: none takes the hidden text+ out of the accessibility tree as well, so what is read is what is shown. */+@container (max-width: 17rem) {+ .chats-page .messages-loading-older.failed > .older-failure-full {+ display: none;+ }++ .chats-page .messages-loading-older.failed > .older-failure-hint {+ display: -webkit-box;+ }+}++/* The loading label is one line while the pill fits it: the longest translation, the French one, is 285px+ wide with its icon and padding, and 18rem of content box is 288px. Under that it takes two lines, at the+ size and the height of the failure, and the pill is taller by what the second line needs: its margins take+ that back (see above), and the two lines end where the failure's do, above the first message's text. */+@container (max-width: 18rem) {+ .chats-page .messages-loading-older:not(.failed) {+ --older-row-height: 1.875rem;+ font-size: 0.6875rem;+ }++ .chats-page .messages-loading-older:not(.failed) > span {+ display: -webkit-box;+ -webkit-box-orient: vertical;+ -webkit-line-clamp: 2;+ overflow-wrap: anywhere;+ text-align: center;+ white-space: normal;+ }}.chats-page .messages-empty {diff --git a/dashboard/src/pages/Chats.test.ts b/dashboard/src/pages/Chats.test.tsindex dfc15f491..8682b1541 100644--- a/dashboard/src/pages/Chats.test.ts+++ b/dashboard/src/pages/Chats.test.ts@@ -2450,24 +2450,20 @@ test('two media downloads in flight do not clobber each other', async () => {/** Modelled heights, so a commit that changes the thread's contents changes its scrollHeight. */const BUBBLE_PX = 30;-const OLDER_SPINNER_PX = 46;/*** Give the thread container a scrollable geometry. jsdom lays nothing out, so every offset reads 0* and the page would never see a thread it can scroll.*- * `scrollHeight` is a getter over the live DOM rather than a constant: the older-page spinner is an- * in-flow child of this container, so it grows the thread on its own commit, one commit BEFORE the- * page lands. A constant cannot tell those two commits apart, and the scroll-restore test below- * turns entirely on the difference.+ * `scrollHeight` is a getter over the live DOM rather than a constant, so a commit that adds or+ * removes bubbles changes it. Only bubbles are modelled: whether the older-page indicator takes room+ * in the thread is the stylesheet's, and ChatThread.test.ts pins it there.*/function makeScrollable(thread: HTMLElement, scrollTop: number): void {Object.defineProperty(thread, 'clientHeight', { value: 600, configurable: true });Object.defineProperty(thread, 'scrollHeight', {configurable: true,- get: () =>- thread.querySelectorAll('.message-bubble').length * BUBBLE_PX +- (thread.querySelector('.messages-loading-older') ? OLDER_SPINNER_PX : 0),+ get: () => thread.querySelectorAll('.message-bubble').length * BUBBLE_PX,});let top = scrollTop;Object.defineProperty(thread, 'scrollTop', {@@ -2541,6 +2537,7 @@ test('a failed older-page fetch does not blank an already-loaded thread', asyncconst inline = thread.querySelector('.messages-loading-older');assert.ok(inline, 'expected an inline failure indicator');assert.match(inline!.textContent ?? '', /couldn.t load older messages/i);+ assert.ok(inline!.classList.contains('failed'), 'the failure is styled to stay at the top of the thread');});});@@ -2593,17 +2590,13 @@ test('the reading position is held across the commit that lands an older page',fireEvent.scroll(thread);await waitFor(() => assert.ok(thread.querySelector('.messages-loading-older')));- assert.equal(thread.scrollHeight, before + OLDER_SPINNER_PX);releaseOlderPage();await within(thread).findByText('paged message 0');await waitFor(() => assert.equal(thread.querySelector('.messages-loading-older') === null, true));// The thread grew upward by the new bubbles, so the row the user was reading has to move down by- // exactly that much. The regression this locks out: measuring the growth on the first commit that- // changed scrollHeight caught the older-page SPINNER entering the flow, one commit early, and- // spent the correction on its ~46px — leaving the real prepend uncorrected and the view thrown a- // full page backwards.+ // exactly that much.assert.equal(thread.scrollHeight - before, PAGED_OLDEST.length * BUBBLE_PX);assert.equal(thread.scrollTop, PAGED_OLDEST.length * BUBBLE_PX);});