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(desktop): open notification links the tab routers cannot serve in the system browser (#22963)

Innei0f25cc53e996
diff --git a/src/features/HomeSidebar/Header/components/InboxModal/NotificationItem.tsx b/src/features/HomeSidebar/Header/components/InboxModal/NotificationItem.tsx
index c498d32a227..72a918ca7be 100644
--- a/src/features/HomeSidebar/Header/components/InboxModal/NotificationItem.tsx
+++ b/src/features/HomeSidebar/Header/components/InboxModal/NotificationItem.tsx
@@ -22,10 +22,14 @@ import { useTranslation } from 'react-i18next';
import AgentAvatar from '@/components/AgentAvatar';
import { ProductLogo } from '@/components/Branding';
import { useWorkspaceAwareNavigate } from '@/features/Workspace/useWorkspaceAwareNavigate';
+import { useAppOrigin } from '@/hooks/useAppOrigin';
import type { NativeContextMenuItem } from '@/libs/contextMenu/types';
+import { openTrustedExternalUrl } from '@/utils/openTrustedExternalUrl';
import { formatNotificationRelativeTime } from './formatNotificationRelativeTime';
import { createNotificationDetailModal } from './NotificationDetailModal';
+import { getNotificationTabRoutes } from './notificationTabRoutes';
+import { resolveNotificationAction } from './resolveNotificationAction';
import { toNotificationPreview } from './toNotificationPreview';
import { useNotificationAgentMeta } from './useNotificationAgentMeta';
@@ -78,6 +82,7 @@ const NotificationItem = memo<NotificationItemProps>(
const { i18n, t } = useTranslation('notification');
const { close } = useModalContext();
const navigate = useWorkspaceAwareNavigate();
+ const appOrigin = useAppOrigin();
const TypeIcon = TYPE_ICON_MAP[type] || BellIcon;
const dateLocale = i18n.resolvedLanguage || i18n.language;
const preview = useMemo(() => toNotificationPreview(content), [content]);
@@ -93,13 +98,18 @@ const NotificationItem = memo<NotificationItemProps>(
if (!actionUrl) return;
- if (/^https?:\/\//i.test(actionUrl)) {
- window.open(actionUrl, '_blank', 'noopener,noreferrer');
+ const action = resolveNotificationAction(actionUrl, {
+ appOrigin,
+ desktopTabRoutes: getNotificationTabRoutes(),
+ });
+
+ if (action.type === 'external') {
+ openTrustedExternalUrl(action.url);
} else {
- navigate(actionUrl);
+ navigate(action.path);
close();
}
- }, [actionUrl, close, handleMarkAsRead, navigate]);
+ }, [actionUrl, appOrigin, close, handleMarkAsRead, navigate]);
// The row only shows a two-line preview, so a click must always give access
// to the full body — the detail modal is the only place a content-only
diff --git a/src/features/HomeSidebar/Header/components/InboxModal/notificationTabRoutes.desktop.test.ts b/src/features/HomeSidebar/Header/components/InboxModal/notificationTabRoutes.desktop.test.ts
new file mode 100644
index 00000000000..e818d160b2d
--- /dev/null
+++ b/src/features/HomeSidebar/Header/components/InboxModal/notificationTabRoutes.desktop.test.ts
@@ -0,0 +1,30 @@
+import { describe, expect, it } from 'vitest';
+
+import { mainAreaMetaRoutes } from '@/spa/router/desktopRouter.config.desktop';
+
+import { resolveNotificationAction } from './resolveNotificationAction';
+
+const env = { appOrigin: 'https://lobehub.com', desktopTabRoutes: mainAreaMetaRoutes };
+
+describe('notification actions against the desktop tab route table', () => {
+ it.each(['/invite/tok_123', '/onboarding'])('opens %s in the system browser', (actionUrl) => {
+ expect(resolveNotificationAction(actionUrl, env)).toEqual({
+ type: 'external',
+ url: `https://lobehub.com${actionUrl}`,
+ });
+ });
+
+ it.each([
+ '/agent/agent-1/topic-1',
+ '/acme/agent/agent-1/topic-1?comment=c1',
+ '/acme/settings/members',
+ '/settings/notification',
+ '/image?topic=topic-1',
+ '/acme',
+ ])('keeps %s inside the tab', (actionUrl) => {
+ expect(resolveNotificationAction(actionUrl, env)).toEqual({
+ path: actionUrl,
+ type: 'navigate',
+ });
+ });
+});
diff --git a/src/features/HomeSidebar/Header/components/InboxModal/notificationTabRoutes.desktop.ts b/src/features/HomeSidebar/Header/components/InboxModal/notificationTabRoutes.desktop.ts
new file mode 100644
index 00000000000..ee31cdb7096
--- /dev/null
+++ b/src/features/HomeSidebar/Header/components/InboxModal/notificationTabRoutes.desktop.ts
@@ -0,0 +1,5 @@
+import type { RouteObject } from 'react-router';
+
+import { mainAreaMetaRoutes } from '@/spa/router/desktopRouter.config';
+
+export const getNotificationTabRoutes = (): RouteObject[] | undefined => mainAreaMetaRoutes;
diff --git a/src/features/HomeSidebar/Header/components/InboxModal/notificationTabRoutes.ts b/src/features/HomeSidebar/Header/components/InboxModal/notificationTabRoutes.ts
new file mode 100644
index 00000000000..13139ccbed3
--- /dev/null
+++ b/src/features/HomeSidebar/Header/components/InboxModal/notificationTabRoutes.ts
@@ -0,0 +1,3 @@
+import type { RouteObject } from 'react-router';
+
+export const getNotificationTabRoutes = (): RouteObject[] | undefined => undefined;
diff --git a/src/features/HomeSidebar/Header/components/InboxModal/resolveNotificationAction.test.ts b/src/features/HomeSidebar/Header/components/InboxModal/resolveNotificationAction.test.ts
new file mode 100644
index 00000000000..c1abcccf859
--- /dev/null
+++ b/src/features/HomeSidebar/Header/components/InboxModal/resolveNotificationAction.test.ts
@@ -0,0 +1,85 @@
+import type { RouteObject } from 'react-router';
+import { describe, expect, it } from 'vitest';
+
+import { resolveNotificationAction } from './resolveNotificationAction';
+
+const desktopTabRoutes: RouteObject[] = [
+ {
+ children: [
+ { path: 'agent/:agentId/:topicId?' },
+ { children: [{ path: 'billing' }, { path: 'credits' }], path: 'subscription' },
+ { children: [{ path: 'notification' }], path: 'settings' },
+ {
+ children: [{ index: true }, { path: 'task/:taskId' }, { path: 'settings/:tab' }],
+ path: ':workspaceSlug',
+ },
+ { index: true },
+ { path: '*' },
+ ],
+ path: '/',
+ },
+];
+
+const desktop = { appOrigin: 'https://lobehub.com', desktopTabRoutes };
+const web = { appOrigin: 'https://lobehub.com' };
+
+describe('resolveNotificationAction', () => {
+ it('opens a workspace invite in the system browser on desktop', () => {
+ expect(resolveNotificationAction('/invite/tok_123', desktop)).toEqual({
+ type: 'external',
+ url: 'https://lobehub.com/invite/tok_123',
+ });
+ });
+
+ it('keeps the query string of a path the tab routers cannot serve', () => {
+ expect(resolveNotificationAction('/waitlist/workspace?from=inbox', desktop)).toEqual({
+ type: 'external',
+ url: 'https://lobehub.com/waitlist/workspace?from=inbox',
+ });
+ });
+
+ it('opens a reserved root the tab routers would read as a workspace slug externally', () => {
+ expect(resolveNotificationAction('/onboarding', desktop)).toEqual({
+ type: 'external',
+ url: 'https://lobehub.com/onboarding',
+ });
+ });
+
+ it('navigates in-app to a workspace invite on web', () => {
+ expect(resolveNotificationAction('/invite/tok_123', web)).toEqual({
+ path: '/invite/tok_123',
+ type: 'navigate',
+ });
+ });
+
+ it.each([
+ '/agent/agent-1/topic-1',
+ '/subscription/billing',
+ '/acme/task/T-1',
+ '/acme/settings/billing?issue=payment_failed',
+ '/settings/notification',
+ '/acme',
+ '/',
+ ])('navigates in-app on desktop for a path the tab routers serve: %s', (actionUrl) => {
+ expect(resolveNotificationAction(actionUrl, desktop)).toEqual({
+ path: actionUrl,
+ type: 'navigate',
+ });
+ });
+
+ it.each([desktop, web])('opens an absolute link externally', (env) => {
+ expect(resolveNotificationAction('https://example.com/changelog', env)).toEqual({
+ type: 'external',
+ url: 'https://example.com/changelog',
+ });
+ });
+
+ it('falls back to in-app navigation on desktop when no app origin is configured', () => {
+ expect(
+ resolveNotificationAction('/invite/tok_123', { appOrigin: '', desktopTabRoutes }),
+ ).toEqual({
+ path: '/invite/tok_123',
+ type: 'navigate',
+ });
+ });
+});
diff --git a/src/features/HomeSidebar/Header/components/InboxModal/resolveNotificationAction.ts b/src/features/HomeSidebar/Header/components/InboxModal/resolveNotificationAction.ts
new file mode 100644
index 00000000000..c52e16e6660
--- /dev/null
+++ b/src/features/HomeSidebar/Header/components/InboxModal/resolveNotificationAction.ts
@@ -0,0 +1,39 @@
+import { matchRoutes, type RouteObject } from 'react-router';
+import urlJoin from 'url-join';
+
+import { RESERVED_ROOT_SEGMENTS } from '@/features/Workspace/rootSegments';
+
+export type NotificationAction =
+ { type: 'external'; url: string } | { path: string; type: 'navigate' };
+
+interface NotificationActionEnv {
+ appOrigin: string;
+ desktopTabRoutes?: RouteObject[];
+}
+
+const ABSOLUTE_URL_REGEX = /^https?:\/\//i;
+
+const isRoutableInTab = (desktopTabRoutes: RouteObject[], path: string): boolean => {
+ const leaf = matchRoutes(desktopTabRoutes, path)?.at(-1);
+ if (!leaf || leaf.route.path === '*') return false;
+
+ // A reserved root with no literal tab route (`/onboarding`) is otherwise
+ // read as a workspace slug and lands on a workspace-not-found page.
+ const { workspaceSlug } = leaf.params;
+ return !workspaceSlug || !RESERVED_ROOT_SEGMENTS.has(workspaceSlug);
+};
+
+export const resolveNotificationAction = (
+ actionUrl: string,
+ { appOrigin, desktopTabRoutes }: NotificationActionEnv,
+): NotificationAction => {
+ if (ABSOLUTE_URL_REGEX.test(actionUrl)) return { type: 'external', url: actionUrl };
+
+ // Desktop tabs mount only the main-area routes, so a root-level page such as
+ // `/invite/:token` would hit the tab catch-all and bounce to home.
+ if (desktopTabRoutes && appOrigin && !isRoutableInTab(desktopTabRoutes, actionUrl)) {
+ return { type: 'external', url: urlJoin(appOrigin, actionUrl) };
+ }
+
+ return { path: actionUrl, type: 'navigate' };
+};