Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(dashboard): drop an armed follow when an older page lands
Yudhi Armyndharisd8ec435331ec
diff --git a/dashboard/src/hooks/useChatScrollPosition.render.test.ts b/dashboard/src/hooks/useChatScrollPosition.render.test.tsindex 89e07d8f8..989f587bd 100644--- a/dashboard/src/hooks/useChatScrollPosition.render.test.ts+++ b/dashboard/src/hooks/useChatScrollPosition.render.test.ts@@ -254,8 +254,16 @@ const hookRef: MutableRefObject<ReturnType<typeof useChatScrollPosition> | null>const hook = (): ReturnType<typeof useChatScrollPosition> =>hookRef.current as ReturnType<typeof useChatScrollPosition>;-function Probe({ chatId, loaded = chatId !== null }: { chatId: string | null; loaded?: boolean }) {- const result = useChatScrollPosition(chatId, loaded, false);+function Probe({+ chatId,+ loaded = chatId !== null,+ fetching = false,+}: {+ chatId: string | null;+ loaded?: boolean;+ fetching?: boolean;+}) {+ const result = useChatScrollPosition(chatId, loaded, fetching);useEffect(() => {hookRef.current = result;});@@ -678,3 +686,34 @@ test('a thread pinned to the bottom stays there as media decodes, until the readrestore();}});++// ── Older pages landing under a position the memory holds ────────────────────++// The echo of a send from the page can reach it after the composer reconciled its placeholder: the cache write+// merges into the existing row, the thread does not grow, and the follow the announcement armed has no commit to+// meet. The page that lands next is not that message.+test('a message announced without growing the thread does not pin the reader when an older page lands', async () => {+ const { render, screen, fireEvent, cleanup } = rtl;+ cleanup();+ const g: Geometry = { height: 4600, top: 0 };+ const restore = installGeometry(g);+ try {+ const { rerender } = render(createElement(Probe, { chatId: 'A' }));+ const el = screen.getByTestId('thread');+ fireEvent.scroll(el);++ hook().onMessageAppended('incoming');+ rerender(createElement(Probe, { chatId: 'A' })); // its commit: the thread did not grow+ await nextFrame();++ readerScrollsTo(el, 50); // the reader goes to the top to read back+ hook().onOlderMessagesRequested();+ rerender(createElement(Probe, { chatId: 'A', fetching: true }));+ g.height += 4600; // the page lands above them+ rerender(createElement(Probe, { chatId: 'A', fetching: false }));+ await nextFrame();+ assert.equal(el.scrollTop, 50 + 4600, 'the landing page took the reader to the bottom');+ } finally {+ restore();+ }+});diff --git a/dashboard/src/hooks/useChatScrollPosition.ts b/dashboard/src/hooks/useChatScrollPosition.tsindex 9c1b4ed9d..f5d18efea 100644--- a/dashboard/src/hooks/useChatScrollPosition.ts+++ b/dashboard/src/hooks/useChatScrollPosition.ts@@ -294,6 +294,10 @@ export function useChatScrollPosition(// a media decode, another query resolving — would otherwise consume the pending correction.if (!el || isFetchingOlderMessages || !wasFetching || !awaitingOlderPageRef.current) return;awaitingOlderPageRef.current = false;+ // A follow still armed belongs to a message announced before the reader went back for history; the page that+ // lands is not its row, and consuming it here would take the reader from the message they were held on to the+ // bottom.+ pendingFollowRef.current = null;// How far the element the reader was on moved down. Measured on the element, not as a change of the// whole thread's height: a preview that swapped in below the reader, or a live message at the// bottom, while the page was in flight is inside that height delta and moves nothing on screen, so