From d8352d2f5b69e383151d9f63baae2c30fea7854f Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 3 Nov 2026 02:12:07 +0000 Subject: [PATCH 1/2] fix(app-shell): an app whose navigation holds only doc entries opens its first doc The app root landed on object, page, dashboard, report and component entries only and rendered nothing when none was shown, so a doc-only app opened to an empty main. When no other entry lands, the root now opens the first doc entry the member is shown, in the in-app docs portal. The designer preview's landing mirror follows. Co-authored-by: Claude Claude-Session: https://claude.ai/code/session_01QsR2jRL46SawdHef859orD --- .changeset/29678-doc-only-app-landing.md | 13 + .../app-shell/src/console/AppContent.tsx | 47 +-- .../AppContent.docOnlyLanding-29678.test.tsx | 328 ++++++++++++++++++ .../AppPreview.docEntry-11197.test.tsx | 20 ++ .../metadata-admin/previews/AppPreview.tsx | 23 +- 5 files changed, 402 insertions(+), 29 deletions(-) create mode 100644 .changeset/29678-doc-only-app-landing.md create mode 100644 ui/packages/app-shell/src/console/__tests__/AppContent.docOnlyLanding-29678.test.tsx diff --git a/.changeset/29678-doc-only-app-landing.md b/.changeset/29678-doc-only-app-landing.md new file mode 100644 index 00000000000..8040fffb1b4 --- /dev/null +++ b/.changeset/29678-doc-only-app-landing.md @@ -0,0 +1,13 @@ +--- +'@object-ui/app-shell': patch +--- + +Clause-②: no +Metadata-protocol: none + +An app whose navigation holds only `doc` entries now opens its first doc in the in-app docs portal, instead of an empty page (#29678). + +- The app root still opens the declared landing first, then the first object, page, dashboard, report or component entry the member is shown. Only when none of those lands does it open the first `doc` entry the member is shown, groups included. +- An app whose first entry is a doc, followed by working entries, opens on its first working entry, as before. +- The doc is gated as a declared `doc` landing is: by the server's audience gate on the app and doc reads. +- The app designer's preview names that doc as the app's landing, as the console does. diff --git a/ui/packages/app-shell/src/console/AppContent.tsx b/ui/packages/app-shell/src/console/AppContent.tsx index 074489843e4..7627983876a 100644 --- a/ui/packages/app-shell/src/console/AppContent.tsx +++ b/ui/packages/app-shell/src/console/AppContent.tsx @@ -1759,27 +1759,25 @@ export function AppContent({ extraRoutes, extraRoutesNoApp }: AppContentProps = ); } -function findFirstRoute(items: any[], ctx?: NavTemplateContext): string { +// objectui#12113 — a `component` entry lands too: its URL is the one the +// sidebar follows, through `buildItemRoute` → `resolveHref`. Without it the +// Studio app, whose navigation is all `component` entries, had no landing at +// all. +const WORKING_LANDING_TYPES: ReadonlySet = new Set(['object', 'page', 'dashboard', 'report', 'component']); +// objectstack-ai/objectstack#29678 — the last resort: a `doc` entry opens the +// in-app docs portal (`/docs/BOOK[/DOC]` under the app, `resolveHref`). +const DOC_LANDING_TYPES: ReadonlySet = new Set(['doc']); + +function findFirstRoute(items: any[], ctx?: NavTemplateContext, types: ReadonlySet = WORKING_LANDING_TYPES): string { if (!items || items.length === 0) return ''; for (const item of items) { - // objectui#12113 — a `component` entry lands too: its URL is the one the - // sidebar follows, through `buildItemRoute` → `resolveHref`. Without it - // the Studio app, whose navigation is all `component` entries, had no - // landing at all. - if ( - item.type === 'object' || - item.type === 'page' || - item.type === 'dashboard' || - item.type === 'report' || - item.type === 'component' - ) { + if (types.has(item.type)) { const route = buildItemRoute(item, ctx); if (route) return route; continue; } - if (item.type === 'url') continue; if (item.type === 'group' && item.children) { - const childRoute = findFirstRoute(item.children, ctx); + const childRoute = findFirstRoute(item.children, ctx, types); if (childRoute !== '') return childRoute; } } @@ -1819,8 +1817,16 @@ function buildItemRoute(item: any, ctx?: NavTemplateContext): string { * shown (`navigation` arrives already gated, objectui#12426) — `findFirstRoute` * walks groups and lands on an `object`, `page`, `dashboard`, `report` or * `component` entry (objectui#12113 added `component`). It skips the item - * types that address nothing inside the app (`url`, `separator`, `action`), - * and a `doc` entry is never that fallback landing (objectui#11197). Which app + * types that address nothing inside the app (`url`, `separator`, `action`). + * A `doc` entry is passed over there: a working entry outranks reading + * material, so an app whose first entry is its manual still opens on its first + * working entry. Only when no entry lands does the root open the FIRST `doc` + * entry the member is shown, in the in-app docs portal + * (objectstack-ai/objectstack#29678): an app whose navigation holds only docs + * used to render an empty `main`. That doc is gated as a declared `doc` + * landing is (objectstack-ai/objectstack#28450): by the server's audience gate + * on the app read and on the doc read, not by the sidebar's doc-readability + * answer, which is a lazy list read the root would have to wait on. Which app * the ROOT lands on is a separate question, decided by `isDefault`. * * The retired `app.homePageId` (spec 17.0.0, objectstack#4667) is not read: it @@ -1837,7 +1843,8 @@ function resolveLandingRoute( const declared = resolveDeclaredLandingRoute(app?.landing, shownTrees, evaluateVisibility, (item) => buildItemRoute(item, ctx), ); - return declared || findFirstRoute(shownTrees[0] ?? [], ctx); + const tree = shownTrees[0] ?? []; + return declared || findFirstRoute(tree, ctx) || findFirstRoute(tree, ctx, DOC_LANDING_TYPES); } /** @@ -1967,9 +1974,9 @@ function AppRootLanding({ if (appServesNoNavigation(shownApp)) { return ; } - // A navigation with no landing: every entry the sidebar draws is a `url`, - // `action` or `doc` link, or the items live only under `areas`, which the - // resolver does not walk. The root renders no page of its own and the + // A navigation with no landing: every entry the sidebar draws is a `url` or + // `action` link, or the items live only under `areas`, which the resolver + // does not walk. (A `doc` entry lands, objectstack-ai/objectstack#29678.) The root renders no page of its own and the // sidebar offers the entries. It used to render the Studio app's overview, // `StudioHomePage`, which objectui#12113 retired. return null; diff --git a/ui/packages/app-shell/src/console/__tests__/AppContent.docOnlyLanding-29678.test.tsx b/ui/packages/app-shell/src/console/__tests__/AppContent.docOnlyLanding-29678.test.tsx new file mode 100644 index 00000000000..2ac5d1b17c0 --- /dev/null +++ b/ui/packages/app-shell/src/console/__tests__/AppContent.docOnlyLanding-29678.test.tsx @@ -0,0 +1,328 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * objectstack-ai/objectstack#29678 — an app whose navigation holds only `doc` + * entries opens its first doc, instead of an empty `main`. + * + * `findFirstRoute` lands on an object, page, dashboard, report or component + * entry and passes over a `doc` entry, and `AppRootLanding` rendered `null` + * when nothing landed: the QA runner (#29672) measured a blank page for admin, + * reader and outsider. The root now opens the first `doc` entry the member is + * shown, in the in-app docs portal, when no other entry lands. + * + * What is pinned here, through the real `AppContent`, the real + * `ExpressionProvider` it mounts and the real `MePermissionsProvider` above it + * (harness as in `AppContent.landingWaitsReads-13097.test.tsx`): + * - a doc-only app lands on its first doc entry (a book), and on a doc entry + * inside a group behind a `url` link; + * - CONTROL: an app whose FIRST entry is a doc still lands on its first + * working entry, as before; + * - CONTROL: an object-entry app redirects to the object, as before; + * - CONTROL: an app that shows the member no navigation keeps + * `AppNoAccessEmptyState`; + * - CONTROL: a pending read ahead of the doc still holds the skeleton, and + * the doc is landed on only once that read fails. + * + * NOTE ON SCOPE: routing only. `ConsoleLayout`, the lazily imported pages and + * the host's docs portal are stubbed. + */ + +import '@testing-library/jest-dom/vitest'; +import { describe, it, expect, vi, beforeEach } from 'vitest'; +import React from 'react'; +import { render, screen, waitFor, act } from '@testing-library/react'; +import { MemoryRouter, Routes, Route, useLocation, useParams } from 'react-router-dom'; +import { MePermissionsProvider, type MePermissionsResponse } from '@object-ui/permissions'; +import { SchemaRendererContext, type ApiFetch } from '@object-ui/react'; + +// AGENTS.md §测试纪律 — the lazy page modules are stubbed so no unbounded +// `import()` races a bounded `findBy` window. +vi.mock('../../views/metadata-admin', () => ({ + MetadataDirectoryPage: () =>
, + MetadataResourceListPage: () =>
, + MetadataResourceEditPage: () =>
, + MetadataResourceHistoryPage: () =>
, + MetadataDiagnosticsPage: () =>
, +})); + +vi.mock('@object-ui/plugin-designer', async (importOriginal) => ({ + ...(await importOriginal()), + CreateAppPage: () =>
, + EditAppPage: () =>
, + DashboardDesignPage: () =>
, +})); + +vi.mock('../../layout/ConsoleLayout', () => ({ + ConsoleLayout: ({ activeAppName, children }: { activeAppName?: string; children?: React.ReactNode }) => ( +
+ {children} +
+ ), +})); +vi.mock('../../chrome/CommandPalette', () => ({ CommandPalette: () => null })); +vi.mock('../../chrome/KeyboardShortcutsDialog', () => ({ KeyboardShortcutsDialog: () => null })); +vi.mock('../../chrome/OnboardingWalkthrough', () => ({ OnboardingWalkthrough: () => null })); +vi.mock('../../views/ObjectView', () => ({ + ObjectView: () =>
, +})); + +vi.mock('@object-ui/i18n', async (importOriginal) => ({ + ...(await importOriginal>()), + useObjectTranslation: () => ({ + t: (key: string, options?: Record) => + String(options?.defaultValue ?? key).replace(/\{\{(\w+)\}\}/g, (_m, name: string) => String(options?.[name] ?? '')), + }), + useObjectLabel: () => ({ + objectLabel: ({ label }: { label?: string }) => label, + objectPluralLabel: ({ label }: { label?: string }) => label, + appLabel: ({ name, label }: { name: string; label?: string }) => label ?? name, + }), +})); + +// One auth value for every render, as the real provider memoises it: +// `AppContent` re-reads the auth config whenever `getAuthConfig`'s identity +// changes, so a fresh function per render re-renders it without end once +// anything re-renders it. +const authValue = { + user: { id: 'u_1', name: 'Member', email: 'member@example.com', role: 'member' }, + getAuthConfig: async () => ({ features: {} }), + activeOrganization: { id: 'org_1', name: 'Org' }, +}; +vi.mock('@object-ui/auth', async (importOriginal) => ({ + ...(await importOriginal>()), + useAuth: () => authValue, + useWorkspaceAdminStatus: () => ({ isAdmin: false, isResolved: true }), +})); + +const dataSourceStub = { + onConnectionStateChange: () => () => {}, + getConnectionState: () => 'connected', +}; +vi.mock('../../providers/AdapterProvider', async (importOriginal) => ({ + ...(await importOriginal>()), + useAdapter: () => dataSourceStub, +})); + +/** The app list as the server hands it to this session. */ +let metadataApps: unknown[] = []; +vi.mock('../../providers/MetadataProvider', async (importOriginal) => ({ + ...(await importOriginal>()), + useMetadata: () => ({ + apps: metadataApps, + objects: [], + loading: false, + ensureType: undefined, + error: null, + refresh: vi.fn(async () => {}), + }), +})); + +const actionRunnerStub = { registerHandler: vi.fn(), getContext: () => ({}) }; +vi.mock('@object-ui/react', async (importOriginal) => ({ + ...(await importOriginal>()), + useActionRunner: () => ({ execute: vi.fn(), runner: actionRunnerStub }), + useGlobalUndo: () => {}, + useMutationInvalidationBridge: () => {}, +})); + +import { AppContent } from '../AppContent'; + +function LocationProbe() { + const location = useLocation(); + return
{location.pathname}
; +} + +const EVERYTHING_READABLE = { + authenticated: true, + userId: 'u_1', + tenantId: null, + positions: [], + hasAnyQueue: false, + permissionSets: [], + objects: { '*': { allowRead: true } }, + fields: {}, +} as MePermissionsResponse; + +let urlSeq = 0; +/** A URL no earlier case asked for. */ +function freshUrl(): string { + urlSeq += 1; + return `/api/v1/landing-probe/${urlSeq}`; +} + +/** An `apiFetch` whose answers the test releases, one per URL. */ +function heldApiFetch() { + const releases = new Map void>(); + const apiFetch = vi.fn( + (url) => + new Promise((resolve) => { + releases.set(String(url), (status, body) => + resolve({ ok: status >= 200 && status < 300, status, json: async () => body } as unknown as Response), + ); + }), + ); + /** Answer `url`, then let the settled read reach the state it sets. */ + const answer = async (url: string, status: number, body?: unknown) => { + await waitFor(() => expect(releases.has(url)).toBe(true)); + await act(async () => { + releases.get(url)!(status, body); + await new Promise((resolve) => setTimeout(resolve, 20)); + }); + }; + return { apiFetch, answer }; +} + +/** An object entry bound to `url`: shown when the bound `total` is 1. */ +function boundEntry(id: string, objectName: string, url: string) { + return { + id, + type: 'object', + objectName, + label: objectName, + visible: 'data.total == 1', + dataSource: { provider: 'api', read: { url }, path: 'summary' }, + }; +} + +const plainEntry = (id: string, objectName: string) => ({ id, type: 'object', objectName, label: objectName }); + +/** + * The console host's in-app docs portal, stubbed: `ui/apps/console` hands + * app-shell a `docs` route (book landing `:slug`, page `:slug/:name`) in its + * `extraRoutes`, which a `doc` entry's href addresses. + */ +function DocsProbe() { + const { '*': rest } = useParams(); + return
{rest}
; +} +const DOCS_ROUTES = } />; + +function renderConsoleAt(initialUrl: string, apiFetch: ApiFetch) { + return render( + + + + + + } /> + + + + , + ); +} + +const pathname = () => screen.getByTestId('pathname').textContent; +const SHOWN = { summary: { total: 1 } }; + +const docEntry = (id: string, target: { book?: string; doc?: string }, label = id) => ({ id, type: 'doc', label, ...target }); + +describe('objectstack-ai/objectstack#29678 — a doc-only app opens its first doc', () => { + beforeEach(() => { + metadataApps = []; + }); + + it('lands on the first doc entry when the navigation holds only docs', async () => { + metadataApps = [ + { + name: 'crm_help', + label: 'CRM Help', + navigation: [docEntry('nav_manual', { book: 'crm_manual' }), docEntry('nav_guide', { book: 'crm_manual', doc: 'crm_lead_guide' })], + }, + ]; + const { apiFetch } = heldApiFetch(); + renderConsoleAt('/apps/crm_help', apiFetch); + + expect(await screen.findByTestId('docs-probe')).toHaveTextContent('crm_manual'); + expect(pathname()).toBe('/apps/crm_help/docs/crm_manual'); + expect(screen.queryByTestId('app-no-access-empty-state')).not.toBeInTheDocument(); + expect(screen.queryByTestId('app-landing-pending')).not.toBeInTheDocument(); + }); + + it('walks groups and passes over a `url` link to reach the first doc', async () => { + metadataApps = [ + { + name: 'crm_help', + label: 'CRM Help', + navigation: [ + { id: 'nav_site', type: 'url', label: 'Website', url: 'https://example.com' }, + { + id: 'group_guides', + type: 'group', + label: 'Guides', + children: [docEntry('nav_guide', { book: 'crm_manual', doc: 'crm_lead_guide' })], + }, + ], + }, + ]; + const { apiFetch } = heldApiFetch(); + renderConsoleAt('/apps/crm_help', apiFetch); + + expect(await screen.findByTestId('docs-probe')).toHaveTextContent('crm_manual/crm_lead_guide'); + expect(pathname()).toBe('/apps/crm_help/docs/crm_manual/crm_lead_guide'); + }); + + it('CONTROL: an app whose first entry is a doc still lands on its first working entry', async () => { + metadataApps = [ + { name: 'crm', label: 'CRM', navigation: [docEntry('nav_manual', { book: 'crm_manual' }), plainEntry('nav_accounts', 'crm_account')] }, + ]; + const { apiFetch } = heldApiFetch(); + renderConsoleAt('/apps/crm', apiFetch); + + expect(await screen.findByTestId('object-view')).toBeInTheDocument(); + expect(pathname()).toBe('/apps/crm/crm_account'); + expect(screen.queryByTestId('docs-probe')).not.toBeInTheDocument(); + }); + + it('CONTROL: an object-entry app redirects to the object, as before', async () => { + metadataApps = [{ name: 'crm', label: 'CRM', navigation: [plainEntry('nav_cases', 'crm_case')] }]; + const { apiFetch } = heldApiFetch(); + renderConsoleAt('/apps/crm', apiFetch); + + expect(await screen.findByTestId('object-view')).toBeInTheDocument(); + expect(pathname()).toBe('/apps/crm/crm_case'); + }); + + it('CONTROL: an app that shows the member no navigation keeps the no-access empty state', async () => { + metadataApps = [{ name: 'crm_help', label: 'CRM Help', navigation: [] }]; + const { apiFetch } = heldApiFetch(); + renderConsoleAt('/apps/crm_help', apiFetch); + + expect(await screen.findByTestId('app-no-access-empty-state')).toBeInTheDocument(); + expect(pathname()).toBe('/apps/crm_help'); + expect(screen.queryByTestId('docs-probe')).not.toBeInTheDocument(); + }); + + it('CONTROL: a pending read ahead of the doc holds the skeleton; answered and shown, it lands on the bound entry', async () => { + const envUrl = freshUrl(); + metadataApps = [ + { name: 'crm', label: 'CRM', navigation: [boundEntry('nav_env', 'crm_env', envUrl), docEntry('nav_manual', { book: 'crm_manual' })] }, + ]; + const { apiFetch, answer } = heldApiFetch(); + renderConsoleAt('/apps/crm', apiFetch); + + await waitFor(() => expect(apiFetch).toHaveBeenCalledWith(envUrl, expect.objectContaining({ method: 'GET' }))); + expect(screen.getByTestId('app-landing-pending')).toBeInTheDocument(); + expect(pathname()).toBe('/apps/crm'); + + await answer(envUrl, 200, SHOWN); + expect(await screen.findByTestId('object-view')).toBeInTheDocument(); + expect(pathname()).toBe('/apps/crm/crm_env'); + }); + + it('CONTROL: a pending read ahead of the doc that fails lands on the doc', async () => { + const envUrl = freshUrl(); + metadataApps = [ + { name: 'crm', label: 'CRM', navigation: [boundEntry('nav_env', 'crm_env', envUrl), docEntry('nav_manual', { book: 'crm_manual' })] }, + ]; + const { apiFetch, answer } = heldApiFetch(); + renderConsoleAt('/apps/crm', apiFetch); + + await waitFor(() => expect(apiFetch).toHaveBeenCalled()); + expect(screen.getByTestId('app-landing-pending')).toBeInTheDocument(); + + await answer(envUrl, 500); + expect(await screen.findByTestId('docs-probe')).toHaveTextContent('crm_manual'); + expect(pathname()).toBe('/apps/crm/docs/crm_manual'); + }); +}); diff --git a/ui/packages/app-shell/src/views/metadata-admin/previews/AppPreview.docEntry-11197.test.tsx b/ui/packages/app-shell/src/views/metadata-admin/previews/AppPreview.docEntry-11197.test.tsx index 25028d6cf8e..46abadaa1f9 100644 --- a/ui/packages/app-shell/src/views/metadata-admin/previews/AppPreview.docEntry-11197.test.tsx +++ b/ui/packages/app-shell/src/views/metadata-admin/previews/AppPreview.docEntry-11197.test.tsx @@ -42,6 +42,26 @@ describe('objectui#11197 — AppPreview (read-only) draws a `doc` entry', () => render(); expect(screen.getByText('→ Accounts')).toBeTruthy(); }); + + // objectstack-ai/objectstack#29678 — the runtime lands on a `doc` entry when + // no other entry lands, so the preview names it as the landing then. + it('names the first `doc` entry as the landing when no other entry lands', () => { + render( + , + ); + expect(screen.getByText('→ Help Centre')).toBeTruthy(); + }); }); describe('objectui#11197 — AppNavCanvas (design mode) draws a `doc` entry', () => { diff --git a/ui/packages/app-shell/src/views/metadata-admin/previews/AppPreview.tsx b/ui/packages/app-shell/src/views/metadata-admin/previews/AppPreview.tsx index 9380ab18fc6..0c63caf880f 100644 --- a/ui/packages/app-shell/src/views/metadata-admin/previews/AppPreview.tsx +++ b/ui/packages/app-shell/src/views/metadata-admin/previews/AppPreview.tsx @@ -254,20 +254,21 @@ function kindIcon(kind?: NavKind) { * something inside the app. Mirrors `findFirstRoute` / `resolveLandingRoute` * in `console/AppContent.tsx` — `group` recurses, and `url` / `separator` / * `action` are skipped because none of them yields an in-app route. + * + * `docs` picks the pass: the first pass passes over `doc` entries, which the + * runtime lands on only when no other entry lands; the second takes only + * them (objectstack-ai/objectstack#29678). A `component` entry lands here as it + * does there, which the runtime learned in objectui#12113. */ -function findFirstLanding(items: NavItem[]): NavItem | undefined { +function findFirstLanding(items: NavItem[], docs = false): NavItem | undefined { for (const it of items) { if (it.kind === 'group') { - const hit = it.children ? findFirstLanding(it.children) : undefined; + const hit = it.children ? findFirstLanding(it.children, docs) : undefined; if (hit) return hit; continue; } if (it.kind === 'url' || it.kind === 'separator' || it.kind === 'action') continue; - // A `doc` entry has an href (the docs portal) but is never a landing: the - // runtime's `findFirstRoute` lands on object / page / dashboard / report / - // component only (objectui#11197). A `component` entry lands here as it - // does there, which the runtime learned in objectui#12113. - if (it.kind === 'doc') continue; + if ((it.kind === 'doc') !== docs) continue; if (it.href) return it; } return undefined; @@ -308,8 +309,12 @@ export function AppPreview({ name, draft, editing, selection, onSelectionChange, // Resolve the landing entry the same way `resolveLandingRoute` does in the // console shell, so the author sees WHICH entry the app will open on: // depth-first, first item that yields a route (`group` recurses; `url`, - // `separator` and `action` address nothing inside the app). - const homeItem = React.useMemo(() => findFirstLanding(navItems), [navItems]); + // `separator` and `action` address nothing inside the app; a `doc` entry + // only when nothing else lands). + const homeItem = React.useMemo( + () => findFirstLanding(navItems) ?? findFirstLanding(navItems, true), + [navItems], + ); const areas = readAreas(draft.areas, locale); From e5ff19414856ada87a9054bc95d3a128f4b0a547 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 3 Nov 2026 03:17:26 +0000 Subject: [PATCH 2/2] fix(app-shell): rewrap the landing fallback comment Co-authored-by: Claude Claude-Session: https://claude.ai/code/session_01QsR2jRL46SawdHef859orD --- ui/packages/app-shell/src/console/AppContent.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ui/packages/app-shell/src/console/AppContent.tsx b/ui/packages/app-shell/src/console/AppContent.tsx index 7627983876a..5deaa80c170 100644 --- a/ui/packages/app-shell/src/console/AppContent.tsx +++ b/ui/packages/app-shell/src/console/AppContent.tsx @@ -1976,9 +1976,10 @@ function AppRootLanding({ } // A navigation with no landing: every entry the sidebar draws is a `url` or // `action` link, or the items live only under `areas`, which the resolver - // does not walk. (A `doc` entry lands, objectstack-ai/objectstack#29678.) The root renders no page of its own and the - // sidebar offers the entries. It used to render the Studio app's overview, - // `StudioHomePage`, which objectui#12113 retired. + // does not walk (a `doc` entry lands, objectstack-ai/objectstack#29678). The + // root renders no page of its own and the sidebar offers the entries. It used + // to render the Studio app's overview, `StudioHomePage`, which objectui#12113 + // retired. return null; }