π€― LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
π fix(topic): refresh the linked PR state when the meta hover card opens (#17435)
Arvin Xu80ff39783479
diff --git a/src/routes/(main)/agent/_layout/Sidebar/Topic/List/Item/MetaHoverCard.test.tsx b/src/routes/(main)/agent/_layout/Sidebar/Topic/List/Item/MetaHoverCard.test.tsxindex c75d13f8ce6..85a98f18d1f 100644--- a/src/routes/(main)/agent/_layout/Sidebar/Topic/List/Item/MetaHoverCard.test.tsx+++ b/src/routes/(main)/agent/_layout/Sidebar/Topic/List/Item/MetaHoverCard.test.tsx@@ -3,14 +3,21 @@*/import type { ChatTopicMetadata } from '@lobechat/types';import { render, screen } from '@testing-library/react';-import { describe, expect, it, vi } from 'vitest';+import { afterEach, describe, expect, it, vi } from 'vitest';import MetaHoverCard from './MetaHoverCard';+const fetchTopicLinkedPullRequestMock = vi.hoisted(() => vi.fn());+vi.mock('@lobehub/ui', () => ({Icon: () => <span data-testid="meta-card-icon" />,}));+vi.mock('@/store/chat', () => ({+ useChatStore: (selector: (state: unknown) => unknown) =>+ selector({ useFetchTopicLinkedPullRequest: fetchTopicLinkedPullRequestMock }),+}));+vi.mock('antd-style', () => ({createStaticStyles: () => ({card: 'card',@@ -43,7 +50,49 @@ vi.mock('@/features/ChatInput/ControlBar/DirIcon', () => ({default: ({ size }: { size?: number }) => <span data-size={size} data-testid="dir-icon" />,}));+afterEach(() => {+ vi.clearAllMocks();+});+describe('MetaHoverCard', () => {+ it('re-fetches the linked PR state on mount (popover open) for the hovered topic', () => {+ const metadata: ChatTopicMetadata = {+ workingDirectory: '/repo',+ workingDirectoryConfig: {+ git: {+ branch: 'fix/cold-hydration-cache-inject',+ github: {+ pullRequest: {+ number: 17_392,+ state: 'open',+ title: 'keep the hydration gate up',+ url: 'https://github.com/lobehub/lobehub/pull/17392',+ },+ pullRequestStatus: 'ok',+ },+ },+ path: '/repo',+ repoType: 'github',+ },+ };++ render(<MetaHoverCard metadata={metadata} title="Topic" topicId="topic-1" />);++ // The card mounts only while the hover popover is open, so wiring the SWR+ // hook to the topic id is what turns "open the card" into a PR refresh β+ // background topics otherwise keep their last persisted snapshot forever.+ expect(fetchTopicLinkedPullRequestMock).toHaveBeenCalledWith('topic-1', metadata);+ });++ it('still mounts the refresh hook when the topic has no git context', () => {+ const { container } = render(<MetaHoverCard metadata={undefined} title="Topic" />);++ // No git context β nothing renders, but the hook is still called+ // unconditionally (rules of hooks); it no-ops via a null SWR key.+ expect(container).toBeEmptyDOMElement();+ expect(fetchTopicLinkedPullRequestMock).toHaveBeenCalledWith(undefined, undefined);+ });+it('shows persisted git context without the branch explanation note', () => {const metadata: ChatTopicMetadata = {workingDirectory: '/repo-fix',diff --git a/src/routes/(main)/agent/_layout/Sidebar/Topic/List/Item/MetaHoverCard.tsx b/src/routes/(main)/agent/_layout/Sidebar/Topic/List/Item/MetaHoverCard.tsxindex bdc765eac45..154f3faee8b 100644--- a/src/routes/(main)/agent/_layout/Sidebar/Topic/List/Item/MetaHoverCard.tsx+++ b/src/routes/(main)/agent/_layout/Sidebar/Topic/List/Item/MetaHoverCard.tsx@@ -15,6 +15,7 @@ import { memo } from 'react';import { useTranslation } from 'react-i18next';import DirIcon from '@/features/ChatInput/ControlBar/DirIcon';+import { useChatStore } from '@/store/chat';import { getPullRequestState, getTopicMetaCard, PR_STATE_VISUAL } from './metaCardData';@@ -139,6 +140,8 @@ interface MetaHoverCardProps {metadata: ChatTopicMetadata | undefined;time?: ReactNode;title: string;+ /** Enables the open-time PR/CI refresh below; without it the card is a pure snapshot reader. */+ topicId?: string;}/**@@ -146,8 +149,16 @@ interface MetaHoverCardProps {* branch / worktree / linked-PR / CI context on the right of the sidebar without* cluttering the row itself.*/-const MetaHoverCard = memo<MetaHoverCardProps>(({ metadata, title, time }) => {+const MetaHoverCard = memo<MetaHoverCardProps>(({ metadata, title, time, topicId }) => {const { t } = useTranslation('topic');+ // The card only mounts while the popover is open, so hosting the linked-PR+ // SWR hook here re-fetches the persisted PR/CI snapshot exactly when the+ // user is looking at it (the hook dedupes to once a minute per PR).+ // ChatHydration runs the same hook for the active topic only β without this,+ // a background topic's badge stays frozen on whatever was last persisted.+ const useFetchTopicLinkedPullRequest = useChatStore((s) => s.useFetchTopicLinkedPullRequest);+ useFetchTopicLinkedPullRequest(topicId, metadata);+const card = getTopicMetaCard(metadata);if (!card) return null;diff --git a/src/routes/(main)/agent/_layout/Sidebar/Topic/List/Item/index.tsx b/src/routes/(main)/agent/_layout/Sidebar/Topic/List/Item/index.tsxindex 57c772fa1e4..8e52258a4f8 100644--- a/src/routes/(main)/agent/_layout/Sidebar/Topic/List/Item/index.tsx+++ b/src/routes/(main)/agent/_layout/Sidebar/Topic/List/Item/index.tsx@@ -463,7 +463,7 @@ const TopicItem = memo<TopicItemProps>({metaCard ? (<Popoverarrow={false}- content={<MetaHoverCard metadata={metadata} title={title} />}+ content={<MetaHoverCard metadata={metadata} title={title} topicId={id} />}mouseEnterDelay={0.8}placement={'right'}styles={META_HOVER_CARD_STYLES}