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(mobile): open /page/:id in the PWA instead of redirecting home (#20018)

Arvin Xuc6c0318bfd7c
diff --git a/src/features/Conversation/Markdown/plugins/Link/Render/InternalEntityLink.tsx b/src/features/Conversation/Markdown/plugins/Link/Render/InternalEntityLink.tsx
index 3e4bc0980dc..08b577106cb 100644
--- a/src/features/Conversation/Markdown/plugins/Link/Render/InternalEntityLink.tsx
+++ b/src/features/Conversation/Markdown/plugins/Link/Render/InternalEntityLink.tsx
@@ -170,6 +170,13 @@ export const InternalEntityLink = memo<InternalEntityLinkProps>(({ href, label,
return;
}
+ // The mobile portal is a modal over the chat, too cramped to read or edit
+ // a page in β€” open the standalone page route instead, so back returns here.
+ if (reference.type === 'document' && typeof __MOBILE__ !== 'undefined' && __MOBILE__) {
+ navigate(reference.pathname);
+ return;
+ }
+
switch (reference.type) {
case 'acceptance': {
// The conversation is the working surface β€” the acceptance opens
diff --git a/src/features/Conversation/Markdown/plugins/Link/Render/index.test.tsx b/src/features/Conversation/Markdown/plugins/Link/Render/index.test.tsx
index 723c10d23ae..8a395cfa463 100644
--- a/src/features/Conversation/Markdown/plugins/Link/Render/index.test.tsx
+++ b/src/features/Conversation/Markdown/plugins/Link/Render/index.test.tsx
@@ -336,6 +336,25 @@ describe('Link Render β€” internal entities', () => {
expect(mockNavigate).not.toHaveBeenCalled();
});
+ it('opens page links as the standalone page on mobile instead of the portal modal', () => {
+ vi.stubGlobal('__MOBILE__', true);
+
+ try {
+ const { getByRole } = renderLink({
+ linkHref: '/page/doc1',
+ linkKind: 'generic',
+ linkLabel: 'Meeting notes',
+ });
+
+ fireEvent.click(getByRole('link', { name: 'Meeting notes' }));
+
+ expect(mockNavigate).toHaveBeenCalledWith('/page/doc1');
+ expect(mockOpenDocument).not.toHaveBeenCalled();
+ } finally {
+ vi.unstubAllGlobals();
+ }
+ });
+
it('opens tasks and agents in their portal views', () => {
const task = renderLink({
linkHref: '/task/T-198',
diff --git a/src/features/PageExplorer/index.tsx b/src/features/PageExplorer/index.tsx
index dd0f5cb3af6..3942947d521 100644
--- a/src/features/PageExplorer/index.tsx
+++ b/src/features/PageExplorer/index.tsx
@@ -14,6 +14,8 @@ interface PageExplorerProps {
*/
header?: ReactNode | null;
pageId: string;
+ /** Forwarded to PageEditor. Mobile has no room for the copilot / comments panel. */
+ rightPanel?: boolean;
}
/**
@@ -21,7 +23,7 @@ interface PageExplorerProps {
*
* Work together with a sidebar @/features/Pages/PageLayout/Body
*/
-const PageExplorer = memo<PageExplorerProps>(({ pageId, header, fullWidthHeader }) => {
+const PageExplorer = memo<PageExplorerProps>(({ pageId, header, fullWidthHeader, rightPanel }) => {
const updatePageOptimistically = usePageStore((s) => s.updatePageOptimistically);
// Get document title and emoji from PageStore
@@ -51,6 +53,7 @@ const PageExplorer = memo<PageExplorerProps>(({ pageId, header, fullWidthHeader
header={header}
key={pageId}
pageId={pageId}
+ rightPanel={rightPanel}
title={title}
onEmojiChange={handleEmojiChange}
onTitleChange={handleTitleChange}
diff --git a/src/features/Pages/MobilePageHeader/index.tsx b/src/features/Pages/MobilePageHeader/index.tsx
new file mode 100644
index 00000000000..f535f9c96fb
--- /dev/null
+++ b/src/features/Pages/MobilePageHeader/index.tsx
@@ -0,0 +1,51 @@
+'use client';
+
+import { Flexbox } from '@lobehub/ui';
+import { Avatar } from '@lobehub/ui/base-ui';
+import { ChatHeader } from '@lobehub/ui/mobile';
+import { memo } from 'react';
+import { useTranslation } from 'react-i18next';
+import { useLocation, useNavigate } from 'react-router';
+
+import { usePageEditorStore } from '@/features/PageEditor/store';
+import { mobileHeaderSticky } from '@/styles/mobileHeader';
+
+/**
+ * Mobile header for `/page/:id`. Rendered through PageEditor's `header` slot so
+ * it reads the live title/emoji from the editor store.
+ */
+const MobilePageHeader = memo(() => {
+ const { t } = useTranslation('file');
+ const navigate = useNavigate();
+ const location = useLocation();
+ const [emoji, title] = usePageEditorStore((s) => [s.emoji, s.title]);
+
+ // Mobile has no page list; go back to wherever the link was opened from, or
+ // home when the page is the first entry (e.g. opened from a shared link).
+ const handleBack = () => {
+ if (location.key === 'default') navigate('/');
+ else navigate(-1);
+ };
+
+ return (
+ <ChatHeader
+ showBackButton
+ style={mobileHeaderSticky}
+ center={
+ <ChatHeader.Title
+ title={
+ <Flexbox horizontal align={'center'} gap={6}>
+ {emoji && <Avatar avatar={emoji} shape={'square'} size={20} />}
+ {title || t('pageEditor.titlePlaceholder')}
+ </Flexbox>
+ }
+ />
+ }
+ onBackClick={handleBack}
+ />
+ );
+});
+
+MobilePageHeader.displayName = 'MobilePageHeader';
+
+export default MobilePageHeader;
diff --git a/src/routes/(mobile)/page/[id]/index.tsx b/src/routes/(mobile)/page/[id]/index.tsx
new file mode 100644
index 00000000000..5d8e9795062
--- /dev/null
+++ b/src/routes/(mobile)/page/[id]/index.tsx
@@ -0,0 +1,41 @@
+'use client';
+
+import { useUnmount } from 'ahooks';
+import { memo, Suspense } from 'react';
+import { useParams } from 'react-router';
+import { createStoreUpdater } from 'zustand-utils';
+
+import { delayed } from '@/components/Skeleton/Delayed';
+import SurfaceSkeleton from '@/components/Skeleton/Surface';
+import PageExplorer from '@/features/PageExplorer';
+import MobilePageHeader from '@/features/Pages/MobilePageHeader';
+import { usePageStore } from '@/store/page';
+import { getIdFromIdentifier } from '@/utils/identifier';
+
+const MobilePageDetail = memo(() => {
+ const storeUpdater = createStoreUpdater(usePageStore);
+ const params = useParams<{ id: string }>();
+
+ const pageId = getIdFromIdentifier(params.id ?? '', 'docs');
+
+ // Mobile mounts no page list, so load this page into the store directly β€”
+ // PageEditor reads title, emoji and workspace lock state from it.
+ const useFetchPageDetail = usePageStore((s) => s.useFetchPageDetail);
+ useFetchPageDetail(pageId);
+
+ useUnmount(() => {
+ usePageStore.setState({ selectedPageId: undefined });
+ });
+
+ storeUpdater('selectedPageId', pageId);
+
+ return (
+ <Suspense fallback={delayed(<SurfaceSkeleton variant={'editor'} />)}>
+ <PageExplorer header={<MobilePageHeader />} pageId={pageId} rightPanel={false} />
+ </Suspense>
+ );
+});
+
+MobilePageDetail.displayName = 'MobilePageDetail';
+
+export default MobilePageDetail;
diff --git a/src/spa/router/mobileRouter.config.tsx b/src/spa/router/mobileRouter.config.tsx
index 9298cfe544e..75a354213c5 100644
--- a/src/spa/router/mobileRouter.config.tsx
+++ b/src/spa/router/mobileRouter.config.tsx
@@ -289,6 +289,23 @@ export const sharedMainAreaChildren: RouteObject[] = [
),
},
+ // Page detail. Mobile has no page list, so `/page` itself goes home; without
+ // these routes `/page/:id` fell through to the `*` redirect.
+ {
+ children: [
+ {
+ element: redirectElement('..'),
+ index: true,
+ },
+ {
+ element: dynamicElement(() => import('@/routes/(mobile)/page/[id]'), 'Mobile > Page'),
+ path: ':id',
+ },
+ ],
+ errorElement: <ErrorBoundary />,
+ path: 'page',
+ },
+
...BusinessMobileRoutesWithMainLayout,
];
diff --git a/src/spa/router/mobileRouter.test.tsx b/src/spa/router/mobileRouter.test.tsx
index c15c302704c..8b587f1c886 100644
--- a/src/spa/router/mobileRouter.test.tsx
+++ b/src/spa/router/mobileRouter.test.tsx
@@ -96,3 +96,19 @@ describe('mobile community route layouts', () => {
).toBe(true);
});
});
+
+describe('mobileRouter page routes', () => {
+ it('renders /page/:id instead of falling through to the catch-all redirect', () => {
+ const matches = matchRoutes(mobileRoutes, '/page/docs_abc123');
+
+ expect(matches?.at(-1)?.route.path).toBe(':id');
+ expect(matches?.at(-1)?.params).toMatchObject({ id: 'docs_abc123' });
+ });
+
+ it('mirrors the page detail route under a workspace slug', () => {
+ const matches = matchRoutes(mobileRoutes, '/my-team/page/docs_abc123');
+
+ expect(matches?.some((match) => match.route.path === ':workspaceSlug')).toBe(true);
+ expect(matches?.at(-1)?.route.path).toBe(':id');
+ });
+});
diff --git a/src/store/page/slices/crud/action.test.ts b/src/store/page/slices/crud/action.test.ts
new file mode 100644
index 00000000000..d099a144e46
--- /dev/null
+++ b/src/store/page/slices/crud/action.test.ts
@@ -0,0 +1,72 @@
+import { renderHook } from '@testing-library/react';
+import { beforeEach, describe, expect, it, vi } from 'vitest';
+
+import type * as SwrModule from '@/libs/swr';
+import { useClientDataSWRWithSync } from '@/libs/swr';
+import { DocumentSourceType, type LobeDocument } from '@/types/document';
+
+import { usePageStore } from '../../store';
+
+vi.mock('@/libs/swr', async (importOriginal) => {
+ const actual = await importOriginal<typeof SwrModule>();
+ return {
+ ...actual,
+ useClientDataSWRWithSync: vi.fn(() => ({ data: undefined, isValidating: false })),
+ };
+});
+
+const doc = (id: string, title: string): LobeDocument => ({
+ content: null,
+ createdAt: new Date('2026-01-01T00:00:00.000Z'),
+ editorData: null,
+ fileType: 'custom/document',
+ filename: title,
+ id,
+ metadata: {},
+ source: 'document',
+ sourceType: DocumentSourceType.EDITOR,
+ title,
+ totalCharCount: 0,
+ totalLineCount: 0,
+ updatedAt: new Date('2026-01-01T00:00:00.000Z'),
+});
+
+const captureOnData = (pageId: string) => {
+ renderHook(() => usePageStore.getState().useFetchPageDetail(pageId));
+ const swrCall = vi.mocked(useClientDataSWRWithSync).mock.calls.at(-1);
+ return swrCall?.[2]?.onData as (data: LobeDocument | null) => void;
+};
+
+describe('useFetchPageDetail onData', () => {
+ beforeEach(() => {
+ vi.mocked(useClientDataSWRWithSync).mockClear();
+ usePageStore.setState({ documents: undefined });
+ });
+
+ it('adds a deep-linked page that is not in the loaded list', () => {
+ usePageStore.setState({ documents: [doc('docs_other', 'Other')] });
+
+ captureOnData('docs_target')(doc('docs_target', 'Target'));
+
+ expect(usePageStore.getState().documents?.map((d) => d.id)).toEqual([
+ 'docs_target',
+ 'docs_other',
+ ]);
+ });
+
+ it('adds the page when no list has been fetched (mobile)', () => {
+ captureOnData('docs_target')(doc('docs_target', 'Target'));
+
+ expect(usePageStore.getState().documents).toEqual([doc('docs_target', 'Target')]);
+ });
+
+ it('updates the page in place when it is already in the list', () => {
+ usePageStore.setState({ documents: [doc('docs_target', 'Old'), doc('docs_other', 'Other')] });
+
+ captureOnData('docs_target')(doc('docs_target', 'New'));
+
+ const { documents } = usePageStore.getState();
+ expect(documents).toHaveLength(2);
+ expect(documents?.find((d) => d.id === 'docs_target')?.title).toBe('New');
+ });
+});
diff --git a/src/store/page/slices/crud/action.ts b/src/store/page/slices/crud/action.ts
index ebb4d48b7cf..0ed26ffc1a2 100644
--- a/src/store/page/slices/crud/action.ts
+++ b/src/store/page/slices/crud/action.ts
@@ -413,15 +413,15 @@ export class CrudActionImpl {
onData: (document) => {
if (!document || !pageId) return;
- // Auto-sync to documents array via internal dispatch
+ // Auto-sync to documents array via internal dispatch. A deep-linked page
+ // may be outside the paginated sidebar list (or no list is mounted, as
+ // on mobile); add it so title, emoji and workspace lock state resolve.
const { documents } = this.#get();
- if (documents?.some((doc) => doc.id === pageId)) {
- this.#get().internal_dispatchDocuments({
- document,
- id: pageId,
- type: 'updateDocument',
- });
- }
+ this.#get().internal_dispatchDocuments(
+ documents?.some((doc) => doc.id === pageId)
+ ? { document, id: pageId, type: 'updateDocument' }
+ : { document, type: 'addDocument' },
+ );
},
revalidateOnFocus: true,
},