Skip to content

🀯 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.

πŸ› fix: open sidebar pull request links on web (#23314)

Bryan2000238d83d4
diff --git a/src/features/Conversation/WorkingSidebar/PullRequest/ActivityTimeline.tsx b/src/features/Conversation/WorkingSidebar/PullRequest/ActivityTimeline.tsx
index 28acdcca731..bb12b294470 100644
--- a/src/features/Conversation/WorkingSidebar/PullRequest/ActivityTimeline.tsx
+++ b/src/features/Conversation/WorkingSidebar/PullRequest/ActivityTimeline.tsx
@@ -12,8 +12,8 @@ import { CheckIcon, CircleSlashIcon, EyeIcon, GitCommitHorizontalIcon, XIcon } f
import { memo, useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next';
-import { electronSystemService } from '@/services/electron/system';
import { sx } from '@/styles/sx';
+import { openTrustedExternalUrl } from '@/utils/openTrustedExternalUrl';
import type { Tone } from './mergeDockData';
import { timeAgo, TONE_COLOR, type TranslateKey } from './prVisual';
@@ -195,7 +195,7 @@ const ActivityTimeline = memo<ActivityTimelineProps>(
<code
{...stylex.props(styles.eventCode, styles.sha)}
onClick={() =>
- void electronSystemService.openExternalLink(
+ openTrustedExternalUrl(
`https://github.com/${detail.repo.owner}/${detail.repo.name}/pull/${detail.number}/commits/${entry.sha}`,
)
}
diff --git a/src/features/Conversation/WorkingSidebar/PullRequest/ChecksList.tsx b/src/features/Conversation/WorkingSidebar/PullRequest/ChecksList.tsx
index 8c860f7919c..fb9a85a123f 100644
--- a/src/features/Conversation/WorkingSidebar/PullRequest/ChecksList.tsx
+++ b/src/features/Conversation/WorkingSidebar/PullRequest/ChecksList.tsx
@@ -6,7 +6,7 @@ import { ExternalLinkIcon } from 'lucide-react';
import { memo } from 'react';
import { useTranslation } from 'react-i18next';
-import { electronSystemService } from '@/services/electron/system';
+import { openTrustedExternalUrl } from '@/utils/openTrustedExternalUrl';
import { OverviewRow } from '../Overview/OverviewRow';
import { formatCheckDuration, getCheckVisual, TONE_COLOR } from './prVisual';
@@ -26,6 +26,7 @@ const ChecksList = memo<ChecksListProps>(({ checks }) => {
return (
<div {...stylex.props(styles.list)}>
{checks.map((check, index) => {
+ const { detailsUrl } = check;
const visual = getCheckVisual(check.status);
const duration =
check.status === 'pending' && !check.startedAt
@@ -46,14 +47,10 @@ const ChecksList = memo<ChecksListProps>(({ checks }) => {
<span>{t('workingPanel.pr.check.optional')}</span>
)}
{duration && <span {...stylex.props(styles.duration)}>{duration}</span>}
- {check.detailsUrl && <Icon icon={ExternalLinkIcon} size={12} />}
+ {detailsUrl && <Icon icon={ExternalLinkIcon} size={12} />}
</>
}
- onClick={
- check.detailsUrl
- ? () => void electronSystemService.openExternalLink(check.detailsUrl!)
- : undefined
- }
+ onClick={detailsUrl ? () => openTrustedExternalUrl(detailsUrl) : undefined}
/>
);
})}
diff --git a/src/features/Conversation/WorkingSidebar/PullRequest/Header.tsx b/src/features/Conversation/WorkingSidebar/PullRequest/Header.tsx
index d3688cd95c7..81d86f8c115 100644
--- a/src/features/Conversation/WorkingSidebar/PullRequest/Header.tsx
+++ b/src/features/Conversation/WorkingSidebar/PullRequest/Header.tsx
@@ -18,8 +18,8 @@ import {
import { memo, useState } from 'react';
import { useTranslation } from 'react-i18next';
-import { electronSystemService } from '@/services/electron/system';
import { useGitRemoteBranches } from '@/store/device';
+import { openTrustedExternalUrl } from '@/utils/openTrustedExternalUrl';
import { rowStyles } from '../Overview/OverviewRow';
import PrHead, { headStyles, PrStatePill, PrTitle } from './Head';
@@ -37,6 +37,7 @@ interface HeaderProps {
const Header = memo<HeaderProps>(
({ actionsDisabled, activityLoaded = true, detail, deviceId, onAction, workingDirectory }) => {
const { t } = useTranslation('chat');
+ const openOnGithubLabel = t('workingPanel.pr.menu.openOnGithub');
const canChangeBase = detail.viewerCanWrite && detail.state === 'open';
const [basePickerOpen, setBasePickerOpen] = useState(false);
const { data: remoteBranches } = useGitRemoteBranches(
@@ -58,8 +59,6 @@ const Header = memo<HeaderProps>(
}))
: [{ disabled: true, key: 'loading', label: t('workingPanel.review.baseRef.loading') }];
- const openOnGithub = () => void electronSystemService.openExternalLink(detail.url);
-
const menuItems: DropdownItem[] = [
{
icon: <Icon icon={LinkIcon} size={14} />,
@@ -97,10 +96,11 @@ const Header = memo<HeaderProps>(
actions={
<>
<ActionIcon
+ aria-label={openOnGithubLabel}
icon={ExternalLinkIcon}
size={'small'}
- title={t('workingPanel.pr.menu.openOnGithub')}
- onClick={openOnGithub}
+ title={openOnGithubLabel}
+ onClick={() => openTrustedExternalUrl(detail.url)}
/>
<DropdownMenu items={menuItems} placement={'bottomRight'}>
<ActionIcon icon={EllipsisIcon} size={'small'} />
diff --git a/src/features/Conversation/WorkingSidebar/PullRequest/index.tsx b/src/features/Conversation/WorkingSidebar/PullRequest/index.tsx
index 830d5eb4c16..5acb27f8ff3 100644
--- a/src/features/Conversation/WorkingSidebar/PullRequest/index.tsx
+++ b/src/features/Conversation/WorkingSidebar/PullRequest/index.tsx
@@ -6,13 +6,13 @@ import { GlobeIcon, RefreshCwIcon, TriangleAlertIcon } from 'lucide-react';
import { memo, useMemo } from 'react';
import { useTranslation } from 'react-i18next';
-import { electronSystemService } from '@/services/electron/system';
import {
useFetchGitAheadBehind,
useFetchGitPullRequestActivity,
useFetchGitPullRequestDetail,
useFetchGitPullRequestMergeContext,
} from '@/store/device';
+import { openTrustedExternalUrl } from '@/utils/openTrustedExternalUrl';
import { OverviewRow } from '../Overview/OverviewRow';
import { sectionProps } from '../Overview/sectionStyles';
@@ -167,7 +167,7 @@ const PullRequest = memo<PullRequestProps>(
<Button
icon={<Icon icon={GlobeIcon} size={12} />}
size={'small'}
- onClick={() => void electronSystemService.openExternalLink(externalUrl)}
+ onClick={() => openTrustedExternalUrl(externalUrl)}
>
{t('workingPanel.pr.ghMissing.open')}
</Button>
diff --git a/src/features/Conversation/WorkingSidebar/__tests__/index.test.tsx b/src/features/Conversation/WorkingSidebar/__tests__/index.test.tsx
index b8b3f6b96e2..2ad7ea901d6 100644
--- a/src/features/Conversation/WorkingSidebar/__tests__/index.test.tsx
+++ b/src/features/Conversation/WorkingSidebar/__tests__/index.test.tsx
@@ -1,12 +1,11 @@
import type { DeviceGitPullRequestDetail } from '@lobechat/types';
import { act, fireEvent, render, screen, waitFor } from '@testing-library/react';
-import type { ComponentType } from 'react';
-import { beforeAll, describe, expect, it, vi } from 'vitest';
+import { describe, expect, it, vi } from 'vitest';
+import { electronSystemService } from '@/services/electron/system';
import { PortalViewType } from '@/store/chat/slices/portal/initialState';
import { messageMapKey } from '@/store/chat/utils/messageMapKey';
-import PullRequestSections from '../PullRequest/Sections';
import {
agentStore,
browserPanes,
@@ -27,11 +26,9 @@ import {
} from './harness';
// Loaded after the mock harness so module mocks are registered first.
-let AgentWorkingSidebar: ComponentType<{ availableWidth?: number }>;
-
-beforeAll(async () => {
- AgentWorkingSidebar = (await import('../index')).default;
-});
+const { default: AgentWorkingSidebar } = await import('../index');
+const { default: PullRequestHeader } = await import('../PullRequest/Header');
+const { default: PullRequestSections } = await import('../PullRequest/Sections');
describe('AgentWorkingSidebar β€” controlled panel width', () => {
it('opens a scoped saved PR before branch lookup and discards it after authoritative empty lookup', () => {
@@ -362,45 +359,68 @@ describe('AgentWorkingSidebar β€” controlled panel width', () => {
});
});
-describe('Pull request Markdown', () => {
- it('renders standard Markdown without creating raw HTML elements', () => {
- const rawHtml = '<aside data-raw-html="true">raw HTML</aside>';
- const detail: DeviceGitPullRequestDetail = {
- additions: 1,
- author: 'lobehub',
- autoMerge: null,
- baseBehindBy: 0,
- baseRefName: 'canary',
- body: `**description-safe**\n\n${rawHtml}`,
- changedFiles: 1,
- checks: [],
- comments: [
- {
- author: 'contributor',
- body: `**comment-safe**\n\n${rawHtml}`,
- createdAt: '2026-09-24T00:00:00Z',
- id: 'comment-1',
- },
- ],
- commits: [],
- deletions: 0,
- headRefName: 'fix/markdown',
- headRefOid: 'a'.repeat(40),
- isCrossRepository: false,
- isDraft: false,
- mergeable: 'MERGEABLE',
- mergeStateStatus: 'CLEAN',
- number: 1,
- repo: { name: 'lobehub', owner: 'lobehub' },
- reviewDecision: null,
- reviews: [],
- state: 'open',
- title: 'Markdown rendering',
- url: 'https://github.com/lobehub/lobehub/pull/1',
- viewerCanBypass: false,
- viewerCanWrite: true,
- };
+describe('Pull request panel', () => {
+ const rawHtml = '<aside data-raw-html="true">raw HTML</aside>';
+ const detail: DeviceGitPullRequestDetail = {
+ additions: 1,
+ author: 'lobehub',
+ autoMerge: null,
+ baseBehindBy: 0,
+ baseRefName: 'canary',
+ body: `**description-safe**\n\n${rawHtml}`,
+ changedFiles: 1,
+ checks: [],
+ comments: [
+ {
+ author: 'contributor',
+ body: `**comment-safe**\n\n${rawHtml}`,
+ createdAt: '2026-09-24T00:00:00Z',
+ id: 'comment-1',
+ },
+ ],
+ commits: [],
+ deletions: 0,
+ headRefName: 'fix/markdown',
+ headRefOid: 'a'.repeat(40),
+ isCrossRepository: false,
+ isDraft: false,
+ mergeable: 'MERGEABLE',
+ mergeStateStatus: 'CLEAN',
+ number: 1,
+ repo: { name: 'lobehub', owner: 'lobehub' },
+ reviewDecision: null,
+ reviews: [],
+ state: 'open',
+ title: 'Markdown rendering',
+ url: 'https://github.com/lobehub/lobehub/pull/1',
+ viewerCanBypass: false,
+ viewerCanWrite: true,
+ };
+
+ it.each(['web', 'desktop'])('opens the PR externally on %s', (surface) => {
+ platform.isDesktop = surface === 'desktop';
+ const openBrowserTab = vi.spyOn(window, 'open').mockReturnValue(null);
+ const openSystemBrowser = vi
+ .spyOn(electronSystemService, 'openExternalLink')
+ .mockResolvedValue();
+
+ render(<PullRequestHeader detail={detail} workingDirectory="/repo" onAction={vi.fn()} />);
+ fireEvent.click(screen.getByRole('button', { name: 'workingPanel.pr.menu.openOnGithub' }));
+
+ if (surface === 'desktop') {
+ expect(openSystemBrowser).toHaveBeenCalledExactlyOnceWith(detail.url);
+ expect(openBrowserTab).not.toHaveBeenCalled();
+ } else {
+ expect(openBrowserTab).toHaveBeenCalledExactlyOnceWith(
+ detail.url,
+ '_blank',
+ 'noopener,noreferrer',
+ );
+ expect(openSystemBrowser).not.toHaveBeenCalled();
+ }
+ });
+ it('renders standard Markdown without creating raw HTML elements', () => {
const { container } = render(
<PullRequestSections
detail={detail}