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(workspace): keep LobeHub prefix on copied group and acceptance links (#21381)

Rdmclin2697a6572e8b2
diff --git a/src/features/Acceptance/Viewer/AcceptanceOverview.test.tsx b/src/features/Acceptance/Viewer/AcceptanceOverview.test.tsx
index 2f7db8b5e17..642f03e80af 100644
--- a/src/features/Acceptance/Viewer/AcceptanceOverview.test.tsx
+++ b/src/features/Acceptance/Viewer/AcceptanceOverview.test.tsx
@@ -19,6 +19,8 @@ vi.mock('./Comments/hooks', () => ({
}));
vi.mock('./Comments/discussionTimeline', () => ({ countDiscussionMessages: () => 0 }));
vi.mock('@/services/verify', () => ({ verifyService: { setAcceptanceVisibility: vi.fn() } }));
+// Desktop renders from `app://renderer`; shared links must use the server origin instead.
+vi.mock('@/hooks/useAppOrigin', () => ({ useAppOrigin: () => 'https://app.lobehub.com' }));
// Everything else in the page is out of scope here: the test is about which
// header controls the main SPA mounts, not how the record's body renders.
@@ -72,6 +74,20 @@ describe('AcceptanceOverview sharing', () => {
expect(screen.getByText('report.actions.copyLink')).toBeTruthy();
});
+ it('copies the acceptance link under the app origin, not the page origin', async () => {
+ bundle.current = buildBundle({ canReview: true, visibility: 'private' });
+ const writeText = vi.fn().mockResolvedValue(undefined);
+ vi.spyOn(navigator, 'clipboard', 'get').mockReturnValue({ writeText } as unknown as Clipboard);
+ renderOverview();
+
+ fireEvent.click(screen.getByRole('button', { name: /acceptance\.share\.title/ }));
+ fireEvent.click(await screen.findByText('report.actions.copyLink'));
+
+ await vi.waitFor(() =>
+ expect(writeText).toHaveBeenCalledWith('https://app.lobehub.com/acceptance/acc-1'),
+ );
+ });
+
it('offers to make a public acceptance private', async () => {
bundle.current = buildBundle({ canReview: true, visibility: 'public' });
renderOverview();
diff --git a/src/features/Acceptance/Viewer/Comments/CommentCard.test.tsx b/src/features/Acceptance/Viewer/Comments/CommentCard.test.tsx
new file mode 100644
index 00000000000..197a55e609b
--- /dev/null
+++ b/src/features/Acceptance/Viewer/Comments/CommentCard.test.tsx
@@ -0,0 +1,44 @@
+import type { AcceptanceCommentItem } from '@lobechat/types';
+import { cleanup, fireEvent, render, screen } from '@testing-library/react';
+import { afterEach, describe, expect, it, vi } from 'vitest';
+
+import CommentCard from './CommentCard';
+
+vi.mock('@/hooks/useActivityTime', () => ({
+ useActivityTime: () => ({ text: 'just now', title: 'just now' }),
+}));
+// Desktop renders from `app://renderer`; shared links must use the server origin instead.
+vi.mock('@/hooks/useAppOrigin', () => ({ useAppOrigin: () => 'https://app.lobehub.com' }));
+vi.mock('@/store/user', () => ({
+ useUserStore: (selector: (state: Record<string, unknown>) => unknown) => selector({}),
+}));
+vi.mock('@/store/user/selectors', () => ({ userProfileSelectors: { userId: () => 'user-1' } }));
+vi.mock('./CommentContent', () => ({ default: () => null }));
+vi.mock('./CommentReactions', () => ({ default: () => null }));
+
+const comment = {
+ author: { fullName: 'Reviewer', status: 'active', type: 'user' },
+ authorUserId: 'user-2',
+ canDelete: false,
+ createdAt: new Date('2026-10-21T00:00:00Z'),
+ id: 'c1',
+} as unknown as AcceptanceCommentItem;
+
+afterEach(cleanup);
+
+describe('CommentCard permalink', () => {
+ it('copies the comment link under the app origin, not the page origin', async () => {
+ window.history.replaceState(null, '', '/lobehub/project/p1/acceptance/a1');
+ const writeText = vi.fn().mockResolvedValue(undefined);
+ vi.spyOn(navigator, 'clipboard', 'get').mockReturnValue({ writeText } as unknown as Clipboard);
+ render(<CommentCard anchored comment={comment} />);
+
+ fireEvent.click(screen.getByTitle('acceptance.comments.copyLinkHint'));
+
+ await vi.waitFor(() =>
+ expect(writeText).toHaveBeenCalledWith(
+ 'https://app.lobehub.com/lobehub/project/p1/acceptance/a1#comment-c1',
+ ),
+ );
+ });
+});
diff --git a/src/features/Acceptance/Viewer/Comments/CommentCard.tsx b/src/features/Acceptance/Viewer/Comments/CommentCard.tsx
index b51343bab5e..d98e16459d9 100644
--- a/src/features/Acceptance/Viewer/Comments/CommentCard.tsx
+++ b/src/features/Acceptance/Viewer/Comments/CommentCard.tsx
@@ -19,6 +19,7 @@ import { memo, type ReactNode, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useActivityTime } from '@/hooks/useActivityTime';
+import { useAppOrigin } from '@/hooks/useAppOrigin';
import { useUserStore } from '@/store/user';
import { userProfileSelectors } from '@/store/user/selectors';
@@ -86,6 +87,7 @@ const CommentCard = memo<CommentCardProps>(
}) => {
const { t } = useTranslation('verify');
const time = useActivityTime(comment.createdAt);
+ const appOrigin = useAppOrigin();
const [deleting, setDeleting] = useState(false);
const name = nameOverride ?? commentAuthorName(comment.author);
const viewerId = useUserStore(userProfileSelectors.userId);
@@ -93,7 +95,7 @@ const CommentCard = memo<CommentCardProps>(
const copyAnchor = async () => {
try {
- await navigator.clipboard.writeText(commentAnchorUrl(comment.id));
+ await navigator.clipboard.writeText(commentAnchorUrl(comment.id, appOrigin));
toast.success(t('acceptance.comments.linkCopied'));
} catch (cause) {
console.error('[acceptance:comments]', cause);
diff --git a/src/features/Acceptance/Viewer/Comments/anchor.test.ts b/src/features/Acceptance/Viewer/Comments/anchor.test.ts
index 39ba31ace3a..0563d6a35fb 100644
--- a/src/features/Acceptance/Viewer/Comments/anchor.test.ts
+++ b/src/features/Acceptance/Viewer/Comments/anchor.test.ts
@@ -16,6 +16,14 @@ describe('comment anchors', () => {
// A bare prefix names no comment.
expect(commentIdFromHash('#comment-')).toBeUndefined();
});
+
+ it('links to this page under the app origin, not the renderer shell', () => {
+ window.history.replaceState(null, '', '/lobehub/project/p1/acceptance/a1?round=2');
+
+ expect(commentAnchorUrl('c1', 'https://app.lobehub.com')).toBe(
+ 'https://app.lobehub.com/lobehub/project/p1/acceptance/a1?round=2#comment-c1',
+ );
+ });
});
describe('comment links', () => {
@@ -24,7 +32,7 @@ describe('comment links', () => {
it('links to the comment on the current report', () => {
window.history.replaceState(null, '', '/acceptance/acc_1?r=2');
- expect(commentAnchorUrl('c1')).toBe(
+ expect(commentAnchorUrl('c1', window.location.origin)).toBe(
`${window.location.origin}/acceptance/acc_1?r=2#${commentAnchorId('c1')}`,
);
});
@@ -34,7 +42,7 @@ describe('comment links', () => {
it('drops the workspace prefix so the shared link opens outside the workspace', () => {
window.history.replaceState(null, '', '/acme/acceptance/acc_1/check/chk_1?r=2');
- expect(commentAnchorUrl('c1')).toBe(
+ expect(commentAnchorUrl('c1', window.location.origin)).toBe(
`${window.location.origin}/acceptance/acc_1/check/chk_1?r=2#${commentAnchorId('c1')}`,
);
});
@@ -42,7 +50,7 @@ describe('comment links', () => {
it('leaves a project-hosted report path alone', () => {
window.history.replaceState(null, '', '/project/prj_1/acceptance/acc_1');
- expect(commentAnchorUrl('c1')).toBe(
+ expect(commentAnchorUrl('c1', window.location.origin)).toBe(
`${window.location.origin}/project/prj_1/acceptance/acc_1#${commentAnchorId('c1')}`,
);
});
diff --git a/src/features/Acceptance/Viewer/Comments/anchor.ts b/src/features/Acceptance/Viewer/Comments/anchor.ts
index 97662b1aec2..40dc7b1da5c 100644
--- a/src/features/Acceptance/Viewer/Comments/anchor.ts
+++ b/src/features/Acceptance/Viewer/Comments/anchor.ts
@@ -18,14 +18,18 @@ export const commentIdFromHash = (hash: string): string | undefined => {
return value.startsWith(PREFIX) ? value.slice(PREFIX.length) || undefined : undefined;
};
-/** The link to hand someone else β€” this page, this comment. */
-export const commentAnchorUrl = (commentId: string) => {
+/**
+ * The link to hand someone else β€” this page, this comment. `appOrigin` comes
+ * from `useAppOrigin`, not `window.location`: on desktop that is the
+ * `app://renderer` shell, which nobody else can open.
+ */
+export const commentAnchorUrl = (commentId: string, appOrigin: string) => {
if (typeof window === 'undefined') return '';
- const { origin, pathname, search } = window.location;
+ const { pathname, search } = window.location;
// A shared link must open for anyone the report is public to, and the
// workspace-prefixed route only mounts for members β€” drop the slug.
const publicPath = pathname.replace(/^\/[^/]+(?=\/acceptance\/)/, '');
- return `${origin}${publicPath}${search}#${commentAnchorId(commentId)}`;
+ return `${appOrigin}${publicPath}${search}#${commentAnchorId(commentId)}`;
};
/** How long a linked comment is held in view while the evidence above it loads. */
diff --git a/src/features/Acceptance/Viewer/Header/AcceptanceShare.tsx b/src/features/Acceptance/Viewer/Header/AcceptanceShare.tsx
index bd72710ad69..41ef1c11329 100644
--- a/src/features/Acceptance/Viewer/Header/AcceptanceShare.tsx
+++ b/src/features/Acceptance/Viewer/Header/AcceptanceShare.tsx
@@ -2,6 +2,7 @@ import { Button, confirmModal, DropdownMenu, toast } from '@lobehub/ui';
import { Share2 } from 'lucide-react';
import { useTranslation } from 'react-i18next';
+import { useAppOrigin } from '@/hooks/useAppOrigin';
import { mutate as globalMutate } from '@/libs/swr';
import { isAcceptanceListKey } from '@/libs/swr/keys';
import { verifyService } from '@/services/verify';
@@ -15,6 +16,7 @@ const AcceptanceShare = () => {
const { t } = useTranslation('verify');
const { acceptanceId } = useAcceptanceScope();
const { data, mutate } = useAcceptanceBundle(acceptanceId);
+ const appOrigin = useAppOrigin();
if (!canReviewAcceptance(data)) return null;
const isPublic = data?.acceptance.visibility === 'public';
@@ -53,7 +55,7 @@ const AcceptanceShare = () => {
label: t('report.actions.copyLink'),
onClick: async () => {
try {
- const url = new URL(`/acceptance/${acceptanceId}`, window.location.origin);
+ const url = new URL(`/acceptance/${acceptanceId}`, appOrigin);
await navigator.clipboard.writeText(url.toString());
toast.success(t('report.actions.copyLinkSuccess'));
} catch {
diff --git a/src/routes/(main)/group/_layout/Sidebar/Topic/List/Item/useDropdownMenu.test.tsx b/src/routes/(main)/group/_layout/Sidebar/Topic/List/Item/useDropdownMenu.test.tsx
index e2b5786bcec..e95606bc257 100644
--- a/src/routes/(main)/group/_layout/Sidebar/Topic/List/Item/useDropdownMenu.test.tsx
+++ b/src/routes/(main)/group/_layout/Sidebar/Topic/List/Item/useDropdownMenu.test.tsx
@@ -10,6 +10,7 @@ const permissionMock = vi.hoisted(() => ({
create_content: true,
edit_own_content: true,
}));
+const workspaceMock = vi.hoisted(() => ({ slug: null as string | null }));
vi.mock('antd', async (importOriginal) => ({
...(await importOriginal<object>()),
@@ -25,6 +26,10 @@ vi.mock('antd', async (importOriginal) => ({
},
}));
+vi.mock('@/business/client/hooks/useActiveWorkspaceSlug', () => ({
+ useActiveWorkspaceSlug: () => workspaceMock.slug,
+}));
+
vi.mock('@/const/version', () => ({
isDesktop: false,
}));
@@ -85,6 +90,7 @@ describe('group useTopicItemDropdownMenu', () => {
beforeEach(() => {
permissionMock.create_content = true;
permissionMock.edit_own_content = true;
+ workspaceMock.slug = null;
});
it('disables topic management actions for workspace viewers', () => {
@@ -106,4 +112,35 @@ describe('group useTopicItemDropdownMenu', () => {
expect(getMenuItem(items, 'copySessionId')).not.toMatchObject({ disabled: true });
expect(getMenuItem(items, 'copyLink')).not.toMatchObject({ disabled: true });
});
+
+ const copyLink = (items: ReturnType<ReturnType<typeof useTopicItemDropdownMenu>>) => {
+ const item = getMenuItem(items, 'copyLink');
+ if (!item || !('onClick' in item)) throw new Error('Missing copy link');
+ (item.onClick as () => void)();
+ };
+
+ it('copies the personal link outside a workspace', () => {
+ const writeText = vi.fn();
+ vi.spyOn(navigator, 'clipboard', 'get').mockReturnValue({ writeText } as unknown as Clipboard);
+ const { result } = renderHook(() =>
+ useTopicItemDropdownMenu({ id: 'topic-1', toggleEditing: vi.fn() }),
+ );
+
+ copyLink(result.current());
+
+ expect(writeText).toHaveBeenCalledWith('https://example.com/group/group-1/topic-1');
+ });
+
+ it('keeps the active workspace prefix in the copied link', () => {
+ workspaceMock.slug = 'lobehub';
+ const writeText = vi.fn();
+ vi.spyOn(navigator, 'clipboard', 'get').mockReturnValue({ writeText } as unknown as Clipboard);
+ const { result } = renderHook(() =>
+ useTopicItemDropdownMenu({ id: 'topic-1', toggleEditing: vi.fn() }),
+ );
+
+ copyLink(result.current());
+
+ expect(writeText).toHaveBeenCalledWith('https://example.com/lobehub/group/group-1/topic-1');
+ });
});
diff --git a/src/routes/(main)/group/_layout/Sidebar/Topic/List/Item/useDropdownMenu.tsx b/src/routes/(main)/group/_layout/Sidebar/Topic/List/Item/useDropdownMenu.tsx
index bdafc1f62e0..44a890ef48e 100644
--- a/src/routes/(main)/group/_layout/Sidebar/Topic/List/Item/useDropdownMenu.tsx
+++ b/src/routes/(main)/group/_layout/Sidebar/Topic/List/Item/useDropdownMenu.tsx
@@ -156,7 +156,10 @@ export const useTopicItemDropdownMenu = ({
label: t('actions.copyLink'),
onClick: () => {
if (!activeGroupId) return;
- const url = `${appOrigin}${GROUP_CHAT_TOPIC_URL(activeGroupId, id)}`;
+ const url = `${appOrigin}${buildWorkspaceAwarePath(
+ GROUP_CHAT_TOPIC_URL(activeGroupId, id),
+ activeWorkspaceSlug,
+ )}`;
navigator.clipboard.writeText(url);
toast.success(t('actions.copyLinkSuccess'));
},