diff --git a/client/src/components/Chat/Messages/MessageParts.tsx b/client/src/components/Chat/Messages/MessageParts.tsx index 19aee8b90c..9a909b9cc0 100644 --- a/client/src/components/Chat/Messages/MessageParts.tsx +++ b/client/src/components/Chat/Messages/MessageParts.tsx @@ -127,6 +127,17 @@ function MessageParts(props: TMessageProps) { isEditing={edit} footer={ + {/* The reading holds the column start: it takes over the slot the streaming + dot vacates, so the retry navigation beside it — whose width the footer + reserves whether or not hover has revealed it — must never push the + timer inboard of that column. */} + {shouldShowElapsed({ + isSubmitting, + isLatestMessage: messageId === latestMessageId, + isCreatedByUser, + siblingIdx, + siblingCount, + }) && } {/* While the answer is generating every other action is withheld, which would otherwise leave this counter sitting alone under a half-written response. It reveals on hover there, like the actions it sits with. */} @@ -138,13 +149,6 @@ function MessageParts(props: TMessageProps) { isSubmitting && messageId === latestMessageId && revealOnRowHoverClasses, )} /> - {shouldShowElapsed({ - isSubmitting, - isLatestMessage: messageId === latestMessageId, - isCreatedByUser, - siblingIdx, - siblingCount, - }) && } { const useMemoizedChatContext = jest.requireActual( '~/hooks/Messages/useMemoizedChatContext', ).default; + const useMessageHelpers = jest.requireActual('~/hooks/Messages/useMessageHelpers').default; return { useMessageProcess, + useMessageHelpers, useMemoizedChatContext, useContentMetadata: () => ({ hasParallelContent: false }), useAttachments: () => ({ attachments: [], searchResults: undefined }), @@ -140,14 +143,18 @@ function createQueryClient() { }); } +type RowComponent = typeof Message; + function DerivedStreamingRow({ structured = false, submitting = true, siblingIdx = 1, + row, }: { structured?: boolean; submitting?: boolean; siblingIdx?: number; + row?: RowComponent; }) { const queryClient = useQueryClient(); const latestMessage = useLatestMessage(0); @@ -183,7 +190,7 @@ function DerivedStreamingRow({ return null; } - const MessageComponent = structured ? StructuredMessage : Message; + const MessageComponent = row ?? (structured ? StructuredMessage : Message); return ( @@ -200,7 +207,12 @@ function DerivedStreamingRow({ ); } -function renderStreamingRow(structured = false, submitting = true, siblingIdx = 1) { +function renderStreamingRow( + structured = false, + submitting = true, + siblingIdx = 1, + row?: RowComponent, +) { const queryClient = createQueryClient(); queryClient.setQueryData( [QueryKeys.messages, conversation.conversationId], @@ -220,6 +232,7 @@ function renderStreamingRow(structured = false, submitting = true, siblingIdx = structured={structured} submitting={submitting} siblingIdx={siblingIdx} + row={row} /> @@ -316,6 +329,26 @@ describe('streaming hover actions', () => { expect(screen.getByTestId('stream-elapsed')).toBeInTheDocument(); }); + /** + * The retry navigation holds its width in the footer whether or not hover has + * revealed it, so a row with siblings would otherwise indent the timer past the + * column the streaming dot just vacated. The reading stays at the column start. + */ + it.each([ + ['a plain text', Message], + ['a structured', StructuredMessage], + ['a flat-thread', MessageParts], + ])('keeps the elapsed reading left-most in %s streaming footer', (_label, row) => { + renderStreamingRow(false, true, 1, row); + + const timer = screen.getByTestId('stream-elapsed'); + const footer = screen.getByRole('navigation', { + name: 'com_ui_sibling_navigation', + }).parentElement; + + expect(footer?.firstElementChild).toContainElement(timer); + }); + it('renders no elapsed timer once the row is not submitting', () => { renderStreamingRow(false, false); diff --git a/client/src/components/Chat/Messages/ui/MessageRender.tsx b/client/src/components/Chat/Messages/ui/MessageRender.tsx index 73bd0a1825..0770506378 100644 --- a/client/src/components/Chat/Messages/ui/MessageRender.tsx +++ b/client/src/components/Chat/Messages/ui/MessageRender.tsx @@ -173,6 +173,17 @@ const MessageRender = memo(function MessageRender({ plain={wakeupDisplay != null && !edit} footer={ + {/* The reading holds the column start: it takes over the slot the streaming + dot vacates, so the retry navigation beside it — whose width the footer + reserves whether or not hover has revealed it — must never push the + timer inboard of that column. */} + {shouldShowElapsed({ + isSubmitting, + isLatestMessage, + isCreatedByUser: msg.isCreatedByUser, + siblingIdx, + siblingCount, + }) && } {/* A user turn is right-aligned, so its retry navigation belongs at the outer edge under the bubble rather than inboard of the actions. @@ -188,13 +199,6 @@ const MessageRender = memo(function MessageRender({ isSubmitting && isLatestMessage && revealOnRowHoverClasses, )} /> - {shouldShowElapsed({ - isSubmitting, - isLatestMessage, - isCreatedByUser: msg.isCreatedByUser, - siblingIdx, - siblingCount, - }) && } + {/* The reading holds the column start: it takes over the slot the streaming + dot vacates, so the retry navigation beside it — whose width the footer + reserves whether or not hover has revealed it — must never push the + timer inboard of that column. */} + {shouldShowElapsed({ + isSubmitting, + isLatestMessage, + isCreatedByUser: msg.isCreatedByUser, + siblingIdx, + siblingCount, + }) && } {/* While the answer is generating every other action is withheld, which would otherwise leave this counter sitting alone under a half-written response. It reveals on hover there, like the actions it sits with. */} @@ -182,13 +193,6 @@ const ContentRender = memo(function ContentRender({ setSiblingIdx={setSiblingIdx} className={cn(isSubmitting && isLatestMessage && revealOnRowHoverClasses)} /> - {shouldShowElapsed({ - isSubmitting, - isLatestMessage, - isCreatedByUser: msg.isCreatedByUser, - siblingIdx, - siblingCount, - }) && }