Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

🖱️ feat: Open the Pull Request Card When Hovering Anywhere on a Conversation Row (#16895)

Marco Berettad0281184840b
diff --git a/client/src/components/Chat/PullRequest/Panel.tsx b/client/src/components/Chat/PullRequest/Panel.tsx
index fb8ffb3587..c114671a15 100644
--- a/client/src/components/Chat/PullRequest/Panel.tsx
+++ b/client/src/components/Chat/PullRequest/Panel.tsx
@@ -1,5 +1,6 @@
import * as Ariakit from '@ariakit/react';
import type { TConversationPullRequest } from 'librechat-data-provider';
+import type { RefObject } from 'react';
import { useLocalize } from '~/hooks';
import PullRequestCard from './Card';
import { cn } from '~/utils';
@@ -32,9 +33,12 @@ export default function PullRequestPanel({
pullRequest,
refreshFailed,
onRetry,
+ finalFocus,
className = panelClass,
}: {
className?: string;
+ /** Where focus returns on close, when the anchor the card hangs from is not focusable. */
+ finalFocus?: RefObject<HTMLElement | null>;
store: Ariakit.HovercardStore;
pullRequest: TConversationPullRequest;
refreshFailed: boolean;
@@ -51,6 +55,7 @@ export default function PullRequestPanel({
portal
unmountOnHide
autoFocusOnShow={false}
+ finalFocus={finalFocus}
aria-label={localize('com_ui_pull_request')}
className={className}
onClick={stop}
diff --git a/client/src/components/Chat/PullRequest/RowMark.tsx b/client/src/components/Chat/PullRequest/RowMark.tsx
index d0e3aaac85..fc328840cc 100644
--- a/client/src/components/Chat/PullRequest/RowMark.tsx
+++ b/client/src/components/Chat/PullRequest/RowMark.tsx
@@ -1,12 +1,14 @@
-import { memo, useEffect } from 'react';
+import { memo, useRef, useEffect } from 'react';
import * as Ariakit from '@ariakit/react';
import { Button } from '@librechat/client';
import { TriangleAlert } from 'lucide-react';
+import type { RefObject } from 'react';
import type React from 'react';
import { useRowPullRequestQuery } from '~/data-provider/PullRequest';
import { TONE_DOT_CLASS, presentPullRequest } from './status';
import PullRequestPanel, { panelClass } from './Panel';
import { summarizePullRequest } from './summary';
+import useRowHover from './useRowHover';
import { useLocalize } from '~/hooks';
import PullRequestIcon from './Icon';
import { cn } from '~/utils';
@@ -28,6 +30,7 @@ function PullRequestRowMark({
labelId,
selected,
onDescribed,
+ rowRef,
}: {
conversationId: string;
/** The id the row lists in `aria-describedby`, so a screen reader hears what the colors say. */
@@ -35,6 +38,8 @@ function PullRequestRowMark({
selected: boolean;
/** Tells the row whether `labelId` is in the page, so it never points at text that is not. */
onDescribed?: (described: boolean) => void;
+ /** The row the mark sits in. Resting the pointer anywhere on it opens the card, not just on the icon. */
+ rowRef?: RefObject<HTMLElement | null>;
}) {
const localize = useLocalize();
const store = Ariakit.useHovercardStore({
@@ -47,6 +52,14 @@ function PullRequestRowMark({
const pullRequest = data?.pullRequest;
const described = pullRequest != null || isError;
+ /* The row is not focusable, so a card it opened hands focus back to the icon on close, and
+ focus or a click on the icon makes the icon the anchor again. */
+ const markRef = useRef<HTMLButtonElement>(null);
+ const finalFocus = rowRef == null ? undefined : markRef;
+ const anchorToMark = (event: React.SyntheticEvent<HTMLElement>) =>
+ store.setAnchorElement(event.currentTarget);
+ useRowHover(store, rowRef, described);
+
useEffect(() => {
onDescribed?.(described);
return () => onDescribed?.(false);
@@ -59,13 +72,18 @@ function PullRequestRowMark({
return (
<Ariakit.HovercardProvider store={store}>
<Ariakit.HovercardAnchor
- render={<Ariakit.Button />}
+ render={<Ariakit.Button ref={markRef} />}
aria-label={failed}
aria-expanded={open}
+ showOnHover={rowRef == null}
data-testid="convo-pull-request-failed"
- onFocus={() => store.show()}
- onClick={(event: React.MouseEvent) => {
+ onFocus={(event: React.FocusEvent<HTMLElement>) => {
+ anchorToMark(event);
+ store.show();
+ }}
+ onClick={(event: React.MouseEvent<HTMLElement>) => {
event.stopPropagation();
+ anchorToMark(event);
store.show();
}}
onKeyDown={(event: React.KeyboardEvent) => {
@@ -84,6 +102,7 @@ function PullRequestRowMark({
portal
unmountOnHide
autoFocusOnShow={false}
+ finalFocus={finalFocus}
aria-label={localize('com_ui_pull_request')}
className={cn(panelClass, 'w-auto')}
onClick={(event) => event.stopPropagation()}
@@ -111,14 +130,19 @@ function PullRequestRowMark({
return (
<Ariakit.HovercardProvider store={store}>
<Ariakit.HovercardAnchor
- render={<Ariakit.Button />}
+ render={<Ariakit.Button ref={markRef} />}
aria-label={summary}
aria-expanded={open}
+ showOnHover={rowRef == null}
data-testid="convo-pull-request"
- onFocus={() => store.show()}
- onClick={(event: React.MouseEvent) => {
+ onFocus={(event: React.FocusEvent<HTMLElement>) => {
+ anchorToMark(event);
+ store.show();
+ }}
+ onClick={(event: React.MouseEvent<HTMLElement>) => {
/* The row itself opens the conversation on click; this opens the card instead. */
event.stopPropagation();
+ anchorToMark(event);
store.show();
}}
onKeyDown={(event: React.KeyboardEvent) => {
@@ -142,6 +166,7 @@ function PullRequestRowMark({
pullRequest={pullRequest}
refreshFailed={isError}
onRetry={() => void refetch()}
+ finalFocus={finalFocus}
/>
</Ariakit.HovercardProvider>
);
diff --git a/client/src/components/Chat/PullRequest/__tests__/RowMark.test.tsx b/client/src/components/Chat/PullRequest/__tests__/RowMark.test.tsx
index d30faa5dad..6d8ecaa5e6 100644
--- a/client/src/components/Chat/PullRequest/__tests__/RowMark.test.tsx
+++ b/client/src/components/Chat/PullRequest/__tests__/RowMark.test.tsx
@@ -65,17 +65,23 @@ const movePointerOver = (element: HTMLElement) => {
});
};
-const renderMark = (props: Partial<React.ComponentProps<typeof PullRequestRowMark>> = {}) => {
+const renderMark = (
+ props: Partial<React.ComponentProps<typeof PullRequestRowMark>> = {},
+ withRow = false,
+) => {
+ const rowRef = React.createRef<HTMLDivElement>();
const rowClick = jest.fn();
const rowKey = jest.fn();
const client = new QueryClient({ defaultOptions: { queries: { retry: false } } });
const view = render(
<QueryClientProvider client={client}>
- <div data-testid="row" onClick={rowClick} onKeyDown={rowKey}>
+ <div data-testid="row" ref={rowRef} onClick={rowClick} onKeyDown={rowKey}>
+ <span data-testid="row-title">{String(1)}</span>
<PullRequestRowMark
conversationId="convo-1"
labelId="pr-label"
selected={false}
+ rowRef={withRow ? rowRef : undefined}
{...props}
/>
</div>
@@ -373,6 +379,171 @@ describe('PullRequestRowMark', () => {
await waitFor(() => expect(screen.queryByTestId('pull-request-card')).not.toBeInTheDocument());
});
+ it('opens the card when the pointer rests anywhere on the row, not only on the icon', async () => {
+ mockGetMany.mockResolvedValue(answer('convo-1', pr));
+ renderMark({}, true);
+ await screen.findByTestId('convo-pull-request');
+ movePointerOver(screen.getByTestId('row-title'));
+ movePointerOver(screen.getByTestId('row-title'));
+ expect(await screen.findByTestId('pull-request-card')).toHaveTextContent(pr.title);
+ });
+
+ it('does not open the card from the row when the row is not handed to the mark', async () => {
+ mockGetMany.mockResolvedValue(answer('convo-1', pr));
+ renderMark();
+ await screen.findByTestId('convo-pull-request');
+ movePointerOver(screen.getByTestId('row-title'));
+ movePointerOver(screen.getByTestId('row-title'));
+ await new Promise((resolve) => setTimeout(resolve, 250));
+ expect(screen.queryByTestId('pull-request-card')).not.toBeInTheDocument();
+ });
+
+ it('closes the card when the pointer leaves the row', async () => {
+ mockGetMany.mockResolvedValue(answer('convo-1', pr));
+ renderMark({}, true);
+ await screen.findByTestId('convo-pull-request');
+ const title = screen.getByTestId('row-title');
+ movePointerOver(title);
+ movePointerOver(title);
+ await screen.findByTestId('pull-request-card');
+ fireEvent.mouseLeave(screen.getByTestId('row'));
+ fireEvent.mouseMove(document.body, { screenX: 900, screenY: 900, movementX: 7, movementY: 7 });
+ await waitFor(() => expect(screen.queryByTestId('pull-request-card')).not.toBeInTheDocument());
+ });
+
+ it('opens the card from a single sampled move into the row', async () => {
+ mockGetMany.mockResolvedValue(answer('convo-1', pr));
+ renderMark({}, true);
+ await screen.findByTestId('convo-pull-request');
+ movePointerOver(screen.getByTestId('row-title'));
+ expect(await screen.findByTestId('pull-request-card')).toHaveTextContent(pr.title);
+ });
+
+ it('does not open the card when the row scrolls under a still pointer', async () => {
+ mockGetMany.mockResolvedValue(answer('convo-1', pr));
+ renderMark({}, true);
+ await screen.findByTestId('convo-pull-request');
+ const title = screen.getByTestId('row-title');
+ /* The pointer rests at one spot; the list then scrolls the row under it. */
+ fireEvent.mouseMove(document.body, { screenX: 50, screenY: 50, movementX: 0, movementY: 0 });
+ fireEvent.mouseMove(title, { screenX: 50, screenY: 50, movementX: 0, movementY: 0 });
+ fireEvent.mouseMove(title, { screenX: 50, screenY: 50, movementX: 0, movementY: 0 });
+ await new Promise((resolve) => setTimeout(resolve, 250));
+ expect(screen.queryByTestId('pull-request-card')).not.toBeInTheDocument();
+ });
+
+ it('does not open the card after the row is clicked before the hover delay ends', async () => {
+ mockGetMany.mockResolvedValue(answer('convo-1', pr));
+ renderMark({}, true);
+ await screen.findByTestId('convo-pull-request');
+ const title = screen.getByTestId('row-title');
+ movePointerOver(title);
+ movePointerOver(title);
+ fireEvent.mouseDown(title);
+ fireEvent.mouseUp(title);
+ fireEvent.click(title);
+ await new Promise((resolve) => setTimeout(resolve, 250));
+ expect(screen.queryByTestId('pull-request-card')).not.toBeInTheDocument();
+ });
+
+ it('does not open the card while the row is dragged with a button held', async () => {
+ mockGetMany.mockResolvedValue(answer('convo-1', pr));
+ renderMark({}, true);
+ await screen.findByTestId('convo-pull-request');
+ const title = screen.getByTestId('row-title');
+ fireEvent.mouseDown(title, { buttons: 1 });
+ fireEvent.mouseMove(title, {
+ screenX: 300,
+ screenY: 300,
+ movementX: 3,
+ movementY: 3,
+ buttons: 1,
+ });
+ fireEvent.mouseMove(title, {
+ screenX: 303,
+ screenY: 303,
+ movementX: 3,
+ movementY: 3,
+ buttons: 1,
+ });
+ await new Promise((resolve) => setTimeout(resolve, 250));
+ expect(screen.queryByTestId('pull-request-card')).not.toBeInTheDocument();
+ });
+
+ it('does not open the card when the list scrolls before the hover delay ends', async () => {
+ mockGetMany.mockResolvedValue(answer('convo-1', pr));
+ renderMark({}, true);
+ await screen.findByTestId('convo-pull-request');
+ const title = screen.getByTestId('row-title');
+ movePointerOver(title);
+ fireEvent.scroll(document.body);
+ await new Promise((resolve) => setTimeout(resolve, 250));
+ expect(screen.queryByTestId('pull-request-card')).not.toBeInTheDocument();
+ });
+
+ it('closes a card the row opened once the list scrolls the row away', async () => {
+ mockGetMany.mockResolvedValue(answer('convo-1', pr));
+ renderMark({}, true);
+ await screen.findByTestId('convo-pull-request');
+ movePointerOver(screen.getByTestId('row-title'));
+ await screen.findByTestId('pull-request-card');
+ fireEvent.scroll(document.body);
+ await waitFor(() => expect(screen.queryByTestId('pull-request-card')).not.toBeInTheDocument());
+ });
+
+ it('keeps the card open when a scroller that does not hold the row scrolls', async () => {
+ mockGetMany.mockResolvedValue(answer('convo-1', pr));
+ renderMark({}, true);
+ await screen.findByTestId('convo-pull-request');
+ const messages = document.createElement('div');
+ document.body.appendChild(messages);
+ try {
+ movePointerOver(screen.getByTestId('row-title'));
+ await screen.findByTestId('pull-request-card');
+ fireEvent.scroll(messages);
+ await new Promise((resolve) => setTimeout(resolve, 250));
+ expect(screen.getByTestId('pull-request-card')).toBeInTheDocument();
+ } finally {
+ messages.remove();
+ }
+ });
+
+ it('keeps the card open when its own content scrolls', async () => {
+ mockGetMany.mockResolvedValue(answer('convo-1', pr));
+ renderMark({}, true);
+ await screen.findByTestId('convo-pull-request');
+ movePointerOver(screen.getByTestId('row-title'));
+ const card = await screen.findByTestId('pull-request-card');
+ fireEvent.scroll(card);
+ await new Promise((resolve) => setTimeout(resolve, 250));
+ expect(screen.getByTestId('pull-request-card')).toBeInTheDocument();
+ });
+
+ it('returns focus to the icon when a card opened from the row is dismissed', async () => {
+ /* jsdom has no layout, and Ariakit only restores focus to an element it can see. */
+ const rects = jest
+ .spyOn(Element.prototype, 'getClientRects')
+ .mockReturnValue([new DOMRect(0, 0, 16, 16)] as unknown as DOMRectList);
+ try {
+ mockGetMany.mockResolvedValue(answer('convo-1', pr));
+ renderMark({}, true);
+ const mark = await screen.findByTestId('convo-pull-request');
+ const title = screen.getByTestId('row-title');
+ movePointerOver(title);
+ movePointerOver(title);
+ await screen.findByTestId('pull-request-card');
+ const link = screen.getByTestId('pull-request-github-link');
+ link.focus();
+ fireEvent.keyDown(link, { key: 'Escape' });
+ await waitFor(() =>
+ expect(screen.queryByTestId('pull-request-card')).not.toBeInTheDocument(),
+ );
+ await waitFor(() => expect(mark).toHaveFocus());
+ } finally {
+ rects.mockRestore();
+ }
+ });
+
it('does not open the row when the card is clicked', async () => {
mockGetMany.mockResolvedValue(answer('convo-1', pr));
const { rowClick } = renderMark();
diff --git a/client/src/components/Chat/PullRequest/useRowHover.ts b/client/src/components/Chat/PullRequest/useRowHover.ts
new file mode 100644
index 0000000000..b46a93560f
--- /dev/null
+++ b/client/src/components/Chat/PullRequest/useRowHover.ts
@@ -0,0 +1,105 @@
+import { useEffect } from 'react';
+import type * as Ariakit from '@ariakit/react';
+import type { RefObject } from 'react';
+
+/** The pointer's position before the current move, wherever it was, so the first move into a
+ * row can tell travel from a row scrolling under a still pointer. One listener for every row. */
+let previous: { x: number; y: number } | null = null;
+let current: { x: number; y: number } | null = null;
+let tracking = false;
+const track = () => {
+ if (tracking) {
+ return;
+ }
+ tracking = true;
+ document.addEventListener(
+ 'mousemove',
+ (event) => {
+ previous = current;
+ current = { x: event.screenX, y: event.screenY };
+ },
+ { capture: true, passive: true },
+ );
+};
+const hasTraveled = (event: MouseEvent) => {
+ if (event.movementX || event.movementY) {
+ return true;
+ }
+ return previous != null && (event.screenX !== previous.x || event.screenY !== previous.y);
+};
+
+/**
+ * Opens a hovercard when the pointer rests anywhere on the row that owns it, not only on the
+ * mark inside it. The row becomes the card's anchor, so the card stays open while the pointer
+ * moves across the row and closes once it leaves the row and the card.
+ *
+ * Like the anchor's own hover intent, only real pointer travel counts: a row that scrolls under
+ * a still pointer, or a tap on touch, does not open it. Pressing a button or a key on the row,
+ * or moving with a button held (a drag), cancels a pending open, so selecting or dragging the
+ * conversation does not pop the card over it. Scrolling the list that holds the row cancels it
+ * too, and closes a card the row opened, since the row no longer sits under the pointer.
+ */
+export default function useRowHover(
+ store: Ariakit.HovercardStore,
+ rowRef: RefObject<HTMLElement | null> | undefined,
+ /** Changes when the mark appears or disappears, so the listener follows the row's content. */
+ active: boolean,
+) {
+ useEffect(() => {
+ const row = rowRef?.current;
+ if (!row || !active) {
+ return;
+ }
+ track();
+ let timer = 0;
+
+ const clear = () => {
+ window.clearTimeout(timer);
+ timer = 0;
+ };
+ const onMove = (event: MouseEvent) => {
+ if (event.buttons !== 0) {
+ clear();
+ return;
+ }
+ if (!hasTraveled(event) || timer || store.getState().open) {
+ return;
+ }
+ const { showTimeout, timeout } = store.getState();
+ timer = window.setTimeout(() => {
+ timer = 0;
+ store.setAnchorElement(row);
+ store.show();
+ }, showTimeout ?? timeout);
+ };
+ /* Only a scroller that holds the row moves it: the message list or the card's own content
+ scrolling leaves the row where it was. */
+ const onScroll = (event: Event) => {
+ const { target } = event;
+ if (!(target instanceof Node) || (target !== document && !target.contains(row))) {
+ return;
+ }
+ const { anchorElement, open } = store.getState();
+ clear();
+ if (open && anchorElement === row) {
+ store.hide();
+ }
+ };
+
+ row.addEventListener('mousemove', onMove);
+ row.addEventListener('mouseleave', clear);
+ row.addEventListener('mousedown', clear);
+ row.addEventListener('keydown', clear);
+ row.addEventListener('dragstart', clear);
+ document.addEventListener('scroll', onScroll, { capture: true, passive: true });
+ return () => {
+ clear();
+ row.removeEventListener('mousemove', onMove);
+ row.removeEventListener('mouseleave', clear);
+ row.removeEventListener('mousedown', clear);
+ row.removeEventListener('keydown', clear);
+ row.removeEventListener('dragstart', clear);
+ document.removeEventListener('scroll', onScroll, { capture: true });
+ };
+ }, [store, rowRef, active]);
+}
diff --git a/client/src/components/Conversations/Convo.tsx b/client/src/components/Conversations/Convo.tsx
index 18210f6683..b0de2640bc 100644
--- a/client/src/components/Conversations/Convo.tsx
+++ b/client/src/components/Conversations/Convo.tsx
@@ -480,6 +480,7 @@ function Conversation({
conversationId={conversationId ?? ''}
labelId={pullRequestLabelId}
onDescribed={setPullRequestDescribed}
+ rowRef={containerRef}
selected={isActiveConvo || isPopoverActive}
/>
</span>
diff --git a/client/src/components/Conversations/__tests__/Convo.pullRequest.spec.tsx b/client/src/components/Conversations/__tests__/Convo.pullRequest.spec.tsx
index 731f762dad..56e773e620 100644
--- a/client/src/components/Conversations/__tests__/Convo.pullRequest.spec.tsx
+++ b/client/src/components/Conversations/__tests__/Convo.pullRequest.spec.tsx
@@ -154,6 +154,12 @@ describe('Conversation row pull request', () => {
expect(mockMarkProps[0]).toMatchObject({ conversationId: 'convo-1', selected: true });
});
+ it('hands the mark its own row, so hovering anywhere on the row can open the card', () => {
+ renderRow();
+ const rowRef = mockMarkProps[0].rowRef as { current: HTMLElement | null };
+ expect(rowRef.current).toBe(screen.getByTestId('convo-item'));
+ });
+
it('reserves no space around the mark, since an absent mark must leave the row unchanged', () => {
renderRow();
const wrapper = screen.getByTestId('convo-pull-request').parentElement as HTMLElement;