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(acceptance): open acceptance pages on the app origin on desktop (#22074)

Rdmclin255b6f427d011
diff --git a/src/features/Acceptance/Viewer/Comments/CommentCard.tsx b/src/features/Acceptance/Viewer/Comments/CommentCard.tsx
index d98e16459d9..b285389a566 100644
--- a/src/features/Acceptance/Viewer/Comments/CommentCard.tsx
+++ b/src/features/Acceptance/Viewer/Comments/CommentCard.tsx
@@ -18,8 +18,8 @@ import { Link2, MoreHorizontal, Trash2 } from 'lucide-react';
import { memo, type ReactNode, useState } from 'react';
import { useTranslation } from 'react-i18next';
+import { useAcceptanceOrigin } from '@/features/Acceptance/origin';
import { useActivityTime } from '@/hooks/useActivityTime';
-import { useAppOrigin } from '@/hooks/useAppOrigin';
import { useUserStore } from '@/store/user';
import { userProfileSelectors } from '@/store/user/selectors';
@@ -87,7 +87,7 @@ const CommentCard = memo<CommentCardProps>(
}) => {
const { t } = useTranslation('verify');
const time = useActivityTime(comment.createdAt);
- const appOrigin = useAppOrigin();
+ const appOrigin = useAcceptanceOrigin();
const [deleting, setDeleting] = useState(false);
const name = nameOverride ?? commentAuthorName(comment.author);
const viewerId = useUserStore(userProfileSelectors.userId);
diff --git a/src/features/Acceptance/Viewer/Comments/anchor.ts b/src/features/Acceptance/Viewer/Comments/anchor.ts
index 40dc7b1da5c..393b39af6d1 100644
--- a/src/features/Acceptance/Viewer/Comments/anchor.ts
+++ b/src/features/Acceptance/Viewer/Comments/anchor.ts
@@ -20,7 +20,7 @@ export const commentIdFromHash = (hash: string): string | undefined => {
/**
* The link to hand someone else β€” this page, this comment. `appOrigin` comes
- * from `useAppOrigin`, not `window.location`: on desktop that is the
+ * from `useAcceptanceOrigin`, not `window.location`: on desktop that is the
* `app://renderer` shell, which nobody else can open.
*/
export const commentAnchorUrl = (commentId: string, appOrigin: string) => {
diff --git a/src/features/Acceptance/Viewer/Header/AcceptanceShare.tsx b/src/features/Acceptance/Viewer/Header/AcceptanceShare.tsx
index fe94da3d6ee..a88fa495d73 100644
--- a/src/features/Acceptance/Viewer/Header/AcceptanceShare.tsx
+++ b/src/features/Acceptance/Viewer/Header/AcceptanceShare.tsx
@@ -4,7 +4,7 @@ import { Button, confirmModal, DropdownMenu, Icon, toast } from '@lobehub/ui';
import { Check, Share2 } from 'lucide-react';
import { useTranslation } from 'react-i18next';
-import { useAppOrigin } from '@/hooks/useAppOrigin';
+import { useAcceptanceOrigin } from '@/features/Acceptance/origin';
import { mutate as globalMutate } from '@/libs/swr';
import { isAcceptanceListKey } from '@/libs/swr/keys';
import { verifyService } from '@/services/verify';
@@ -59,7 +59,7 @@ const AcceptanceShare = () => {
const { t } = useTranslation('verify');
const { acceptanceId } = useAcceptanceScope();
const { data, mutate } = useAcceptanceBundle(acceptanceId);
- const appOrigin = useAppOrigin();
+ const appOrigin = useAcceptanceOrigin();
if (!data || !canReviewAcceptance(data)) return null;
const current = data.acceptance.visibility;
diff --git a/src/features/Acceptance/origin.test.ts b/src/features/Acceptance/origin.test.ts
new file mode 100644
index 00000000000..ef8aa77eeb1
--- /dev/null
+++ b/src/features/Acceptance/origin.test.ts
@@ -0,0 +1,18 @@
+import { describe, expect, it } from 'vitest';
+
+import { acceptanceOrigin } from './origin';
+
+describe('acceptanceOrigin', () => {
+ it('moves the cloud gateway apex to the app origin', () => {
+ // The apex serves `/acceptance/<id>` from the marketing site, not the app.
+ expect(acceptanceOrigin('https://lobehub.com')).toBe('https://app.lobehub.com');
+ expect(acceptanceOrigin('https://lobehub.com/')).toBe('https://app.lobehub.com');
+ });
+
+ it('keeps every other origin', () => {
+ expect(acceptanceOrigin('https://app.lobehub.com')).toBe('https://app.lobehub.com');
+ expect(acceptanceOrigin('https://chat.example.com')).toBe('https://chat.example.com');
+ expect(acceptanceOrigin('http://localhost:3010')).toBe('http://localhost:3010');
+ expect(acceptanceOrigin('')).toBe('');
+ });
+});
diff --git a/src/features/Acceptance/origin.ts b/src/features/Acceptance/origin.ts
new file mode 100644
index 00000000000..31f11e3ad17
--- /dev/null
+++ b/src/features/Acceptance/origin.ts
@@ -0,0 +1,18 @@
+import { OFFICIAL_CLOUD_URL, OFFICIAL_URL } from '@lobechat/const';
+
+import { useAppOrigin } from '@/hooks/useAppOrigin';
+
+/**
+ * Origin for acceptance and verify-report pages opened or shared outside the app.
+ *
+ * Desktop in cloud mode reports the gateway apex (`OFFICIAL_CLOUD_URL`) as its
+ * app origin. The apex forwards most app routes, but `/acceptance/<id>` and
+ * `/verify/<id>` belong to the marketing site there (it has its own
+ * `/acceptance` page), so the report would land on a landing page or a 404.
+ * Point those links at the app origin instead, matching the web build. Every
+ * other origin (web, self-hosted) passes through unchanged.
+ */
+export const acceptanceOrigin = (appOrigin: string): string =>
+ appOrigin.replace(/\/+$/, '') === OFFICIAL_CLOUD_URL ? OFFICIAL_URL : appOrigin;
+
+export const useAcceptanceOrigin = () => acceptanceOrigin(useAppOrigin());
diff --git a/src/features/EntityLink/Render/InternalEntityPreview.tsx b/src/features/EntityLink/Render/InternalEntityPreview.tsx
index ff4fdbecbef..95747c96441 100644
--- a/src/features/EntityLink/Render/InternalEntityPreview.tsx
+++ b/src/features/EntityLink/Render/InternalEntityPreview.tsx
@@ -26,9 +26,9 @@ import { useTranslation } from 'react-i18next';
import { useActiveWorkspaceSlug } from '@/business/client/hooks/useActiveWorkspaceSlug';
import { ArticleSkeleton } from '@/components/Skeleton';
+import { useAcceptanceOrigin } from '@/features/Acceptance/origin';
import { goalStatusKey } from '@/features/AgentGoals/goalPresentation';
import { buildWorkspaceAwarePath } from '@/features/Workspace/workspaceAwarePath';
-import { useAppOrigin } from '@/hooks/useAppOrigin';
import { useClientDataSWR } from '@/libs/swr';
import { agentService } from '@/services/agent';
import { documentService } from '@/services/document';
@@ -247,7 +247,7 @@ export const InternalEntityPreview = memo<InternalEntityPreviewProps>(
const { t } = useTranslation('chat');
const { t: tVerify } = useTranslation('verify');
const [open, setOpen] = useState(false);
- const appOrigin = useAppOrigin();
+ const appOrigin = useAcceptanceOrigin();
const activeWorkspaceSlug = useActiveWorkspaceSlug();
// A click on the link opens the acceptance in the side panel; this is the
// explicit way out to a full browser page. Without an origin the URL would
diff --git a/src/features/EntityLink/Render/index.test.tsx b/src/features/EntityLink/Render/index.test.tsx
index 65648dca19f..5b61d0f46aa 100644
--- a/src/features/EntityLink/Render/index.test.tsx
+++ b/src/features/EntityLink/Render/index.test.tsx
@@ -293,6 +293,25 @@ describe('Link Render β€” internal entities', () => {
expect(mockOpenAcceptance).not.toHaveBeenCalled();
});
+ it('opens the app, not the gateway apex, from the desktop cloud preview', () => {
+ // Desktop in cloud mode reports `https://lobehub.com` as its origin, where
+ // `/acceptance/<id>` is the marketing site's page rather than the report.
+ mockAppOrigin = 'https://lobehub.com';
+ mockEntityPreview = { title: 'Workspace publishing' };
+ const { container, getByRole } = renderLink({
+ linkHref: '/acceptance/acceptance-1',
+ linkKind: 'generic',
+ linkLabel: 'Acceptance',
+ });
+ fireEvent.mouseEnter(container.firstElementChild!);
+
+ fireEvent.click(getByRole('button', { name: 'report.actions.openInBrowser' }));
+
+ expect(mockOpenTrustedExternalUrl).toHaveBeenCalledWith(
+ 'https://app.lobehub.com/acceptance/acceptance-1',
+ );
+ });
+
it('offers no browser action without an app origin to resolve against', () => {
mockAppOrigin = '';
const { container, queryByRole } = renderLink({
diff --git a/src/features/Portal/Acceptance/usePageUrl.ts b/src/features/Portal/Acceptance/usePageUrl.ts
index e6203ec7d9a..faf17edaa7c 100644
--- a/src/features/Portal/Acceptance/usePageUrl.ts
+++ b/src/features/Portal/Acceptance/usePageUrl.ts
@@ -1,12 +1,12 @@
import { useActiveWorkspaceSlug } from '@/business/client/hooks/useActiveWorkspaceSlug';
+import { useAcceptanceOrigin } from '@/features/Acceptance/origin';
import { buildWorkspaceAwarePath } from '@/features/Workspace/workspaceAwarePath';
-import { useAppOrigin } from '@/hooks/useAppOrigin';
import { useChatStore } from '@/store/chat';
import { chatPortalSelectors } from '@/store/chat/selectors';
/** Web URL of the acceptance the portal shows; `undefined` until an id is known. */
export const useAcceptancePageUrl = () => {
- const appOrigin = useAppOrigin();
+ const appOrigin = useAcceptanceOrigin();
const activeWorkspaceSlug = useActiveWorkspaceSlug();
const acceptanceId = useChatStore(chatPortalSelectors.acceptancePortalId);
const pagePath = acceptanceId
diff --git a/src/features/Portal/AcceptanceCheck/useMoreMenu.ts b/src/features/Portal/AcceptanceCheck/useMoreMenu.ts
index 46c1371f077..ea662423320 100644
--- a/src/features/Portal/AcceptanceCheck/useMoreMenu.ts
+++ b/src/features/Portal/AcceptanceCheck/useMoreMenu.ts
@@ -1,3 +1,5 @@
+import { useActiveWorkspaceSlug } from '@/business/client/hooks/useActiveWorkspaceSlug';
+import { useAcceptanceOrigin } from '@/features/Acceptance/origin';
import { acceptanceCheckPath } from '@/features/Acceptance/Viewer/routes';
import { type PortalMoreMenuConfig } from '@/features/Portal/components/PortalMoreMenu/types';
import { useChatStore } from '@/store/chat';
@@ -5,12 +7,16 @@ import { chatPortalSelectors } from '@/store/chat/selectors';
import { useVerifyStore } from '@/store/verify';
import { openTrustedExternalUrl } from '@/utils/openTrustedExternalUrl';
-import { usePortalShareUrl } from '../components/PortalMoreMenu/shareUrl';
+import { buildPortalShareUrl } from '../components/PortalMoreMenu/shareUrl';
export const useAcceptanceCheckMoreMenu = (): PortalMoreMenuConfig | undefined => {
const portal = useChatStore(chatPortalSelectors.acceptanceCheckPortal);
- const shareUrl = usePortalShareUrl(
+ const appOrigin = useAcceptanceOrigin();
+ const workspaceSlug = useActiveWorkspaceSlug();
+ const shareUrl = buildPortalShareUrl(
+ appOrigin,
portal ? acceptanceCheckPath(portal.acceptanceId, portal.checkId) : undefined,
+ workspaceSlug,
);
if (!portal) return;
diff --git a/src/features/Portal/VerifyReport/useReportUrl.ts b/src/features/Portal/VerifyReport/useReportUrl.ts
index a96fdcdc91a..fbb20268b4a 100644
--- a/src/features/Portal/VerifyReport/useReportUrl.ts
+++ b/src/features/Portal/VerifyReport/useReportUrl.ts
@@ -1,6 +1,6 @@
import { useVerifyReportBundle } from '@/features/Acceptance/hooks';
+import { useAcceptanceOrigin } from '@/features/Acceptance/origin';
import { buildAcceptanceRoundPath } from '@/features/Acceptance/roundLink';
-import { useAppOrigin } from '@/hooks/useAppOrigin';
import { useChatStore } from '@/store/chat';
import { chatPortalSelectors } from '@/store/chat/selectors';
@@ -10,7 +10,7 @@ import { chatPortalSelectors } from '@/store/chat/selectors';
* once it turns out to be `standalone` (no acceptance, so nothing to open).
*/
export const useVerifyReportUrl = () => {
- const appOrigin = useAppOrigin();
+ const appOrigin = useAcceptanceOrigin();
const runId = useChatStore(chatPortalSelectors.verifyReportRunId);
// Same SWR key as the portal's title and body, so this shares their request.
const { data } = useVerifyReportBundle(runId ?? null);