Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .changeset/35981-app-route-boot-frame.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
'@object-ui/app-shell': patch
'@object-ui/console': patch
---

perf(console): an app route draws the console's frame right after the session read, and the chrome no longer waits for the route's own metadata

Clause-②: no
Metadata-protocol: none

Opening an app page by its URL (a reload, a pasted link) showed the full-screen splash until the permission answer, the app list, the admin verdict and the page's own metadata reads had all arrived. On a hosted environment the permission answer alone takes seconds.

- `LoadingFallback` (the console's boot-gate fallback) and `AppContent`'s readiness gate now draw `ConsoleBootShell` on an `/apps/:app/*` route once the session has answered with a user: the chrome's frame (the sidebar at the width the reader left it, from 768 px up with grey blocks where its head and foot put the app menu, the search, the bell and the account; the top bar on a phone, except on a record page, and on an app's docs pages, which have no sidebar; the route's skeleton in the slot: the shape the chrome draws on that route), with no app name, no navigation entry and nothing to press, because those are what the gates still decide. The splash stays for the session read itself and for every other route. The console's permission scope uses the same fallback.
- `AppContent` mounts the console chrome once the app list, the permission answer, the admin verdict and the deployment flags (`/auth/config`, which the chrome's navigation gates read) are in; the route's own metadata reads no longer hold it on the first paint. The route slot draws the route's skeleton until they land, and a route element whose chunk is still loading draws the same skeleton instead of the full-screen splash inside the chrome.
- The frame and the first route skeleton carry `data-boot-splash`, so readiness waits and the reads deferred to the first paint past the splash wait exactly as before; `data-boot-shell` tells the frame apart.
7 changes: 5 additions & 2 deletions ui/apps/console/src/AppContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import { lazy, Suspense, useEffect, useMemo, type ReactNode } from 'react';
import { Route, useParams, useLocation, Navigate } from 'react-router-dom';
import { DefaultAppContent, ENVIRONMENT_SCOPE_QUERY, LauncherAppsProvider, LoadingScreen, setupMetadataStudioPath, useAdapter } from '@object-ui/app-shell';
import { DefaultAppContent, ENVIRONMENT_SCOPE_QUERY, LauncherAppsProvider, LoadingFallback, LoadingScreen, setupMetadataStudioPath, useAdapter } from '@object-ui/app-shell';
import { AdapterCtx } from '@object-ui/react';
import { MePermissionsProvider, ServerReadScope, releaseMePermissionsRequest, startMePermissionsRequest } from '@object-ui/permissions';
import { createAuthenticatedFetch, useAuth } from '@object-ui/auth';
Expand Down Expand Up @@ -456,7 +456,10 @@ export function ConsolePermissionsScope({ children }: { children: ReactNode }) {
endpoint={endpoint}
fetcher={authFetch}
requestKey={requestKey}
loadingFallback={<LoadingScreen />}
// objectstack#35981 — the console's boot fallback: on an app route, the
// chrome's empty frame while the answer is out (it draws no navigation
// entry, which is what the answer decides); the splash on `/home`.
loadingFallback={<LoadingFallback />}
// Without this, the provider's error state renders `loadingFallback` too —
// an eternal spinner with a `retry` nobody can reach. The provider already
// re-attempts a transient failure (a cold environment kernel answers 503 +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ vi.mock('@object-ui/app-shell', async (importOriginal) => ({
RequireOrganization: ({ children }: { children?: ReactNode }) => <>{children}</>,
ConsoleToaster: () => null,
LoadingScreen: () => <div data-testid="loading-screen" />,
// objectstack#35981 — the permission scope's loading fallback is the console's
// boot fallback, which is the splash off an app route.
LoadingFallback: () => <div data-testid="loading-screen" />,
DefaultHomePage: () => <HomeRosterProbe />,
DefaultAppContent: () => <AppContentProbe />,
BuilderLanding: () => <StudioBuilderProbe />,
Expand Down
17 changes: 11 additions & 6 deletions ui/apps/console/src/__tests__/AppContent.systemHubRoutes.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
import '@testing-library/jest-dom/vitest';
import { describe, it, expect, vi, beforeEach } from 'vitest';
import React from 'react';
import { render, screen, fireEvent } from '@testing-library/react';
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
import { MemoryRouter, Routes, Route, Navigate, useLocation, useParams } from 'react-router-dom';

// AGENTS.md §测试纪律 — the lazily-imported page modules are stubbed so no
Expand Down Expand Up @@ -187,11 +187,14 @@ vi.mock('@object-ui/i18n', async (importOriginal) => ({
// on that chrome-less screen (pinned in
// `packages/app-shell/src/console/__tests__/AppContent.inaccessibleAppStrand.test.tsx`).
// The legacy `/system/*` redirect targets this file measures are unchanged.
// One function for every render, as `AuthProvider`'s `useCallback` gives
// (objectstack#35981: the chrome waits for its answer).
const getAuthConfig = vi.hoisted(() => async () => ({ features: {} }));
vi.mock('@object-ui/auth', async (importOriginal) => ({
...(await importOriginal<Record<string, unknown>>()),
useAuth: () => ({
user: null,
getAuthConfig: async () => ({ features: {} }),
getAuthConfig,
activeOrganization: null,
}),
useWorkspaceAdminStatus: () => ({ isAdmin: true, isResolved: true }),
Expand Down Expand Up @@ -287,20 +290,22 @@ describe('system-hub entries reach the framework system objects (objectui#3655)'
expect(screen.queryByText('Page not found')).not.toBeInTheDocument();
});

it('preserves the app prefix rather than stripping to the root', () => {
it('preserves the app prefix rather than stripping to the root', async () => {
// `prefix` is cut with a regex off `location.pathname`; every case above
// uses the same two-segment prefix, so a mistake there is invisible in them.
renderConsoleAt('/apps/my-app/system/users');

expect(chain).toEqual(['/apps/my-app/system/users', '/apps/my-app/sys_user']);
// objectstack#35981 — the chrome (and the routes under it) mount once the
// deployment flags have answered, a promise even when answered at once.
await waitFor(() => expect(chain).toEqual(['/apps/my-app/system/users', '/apps/my-app/sys_user']));
});

it('an app segment spelled `system` survives the rewrite', () => {
it('an app segment spelled `system` survives the rewrite', async () => {
// The regex is end-anchored precisely so the LAST `/system/<seg>` is the
// one removed. An unanchored cut would leave `/apps` here.
renderConsoleAt('/apps/system/system/users');

expect(chain).toEqual(['/apps/system/system/users', '/apps/system/sys_user']);
await waitFor(() => expect(chain).toEqual(['/apps/system/system/users', '/apps/system/sys_user']));
});

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ vi.mock('@object-ui/app-shell', async (importOriginal) => ({
RequireOrganization: ({ children }: { children?: ReactNode }) => <>{children}</>,
ConsoleToaster: () => null,
LoadingScreen: () => <div data-testid="loading-screen" />,
// objectstack#35981 — the permission scope's loading fallback is the console's
// boot fallback, which is the splash off an app route.
LoadingFallback: () => <div data-testid="loading-screen" />,
DefaultHomePage: () => <HomeProbe />,
DefaultAppContent: () => null,
BuilderLanding: () => null,
Expand Down
14 changes: 9 additions & 5 deletions ui/packages/app-shell/src/chrome/RedirectWithSplash.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@
*
* ## Why the splash, and why it cannot itself flicker
*
* The component renders the SAME `LoadingScreen` the gate one line above was
* already rendering, so the handoff changes no pixels: the transition now runs
* The component renders the SAME fallback the gate one line above was
* already rendering (`ConsoleBootFallback`: the splash, or on an app route
* after the session read the console's frame, objectstack#35981), so the
* handoff changes no pixels: the transition now runs
* underneath an unchanged screen instead of underneath a blank one. That is
* also why this is not "add a spinner" — a different holding image would
* introduce a visual change where today there is a blank, and the goal is for
Expand All @@ -52,7 +54,7 @@
*/

import { Navigate } from 'react-router-dom';
import { LoadingScreen } from './LoadingScreen.js';
import { ConsoleBootFallback } from '../console/ConsoleBootShell.js';

export interface RedirectWithSplashProps {
/** Where to go — the same value a bare `<Navigate to={…}>` would take. */
Expand All @@ -66,8 +68,10 @@ export function RedirectWithSplash({ to, replace }: RedirectWithSplashProps) {
<>
{/* Order is not load-bearing — `<Navigate>` renders null — but the
splash is written first so the element that OCCUPIES the screen reads
first at every call site. */}
<LoadingScreen />
first at every call site. objectstack#35981 — the boot gates' own
fallback, so on an app route after the session read it is the
console's frame those gates were showing, and the splash elsewhere. */}
<ConsoleBootFallback />
<Navigate to={to} replace={replace} />
</>
);
Expand Down
75 changes: 45 additions & 30 deletions ui/packages/app-shell/src/console/AppContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import { ConsoleLayout } from '../layout/ConsoleLayout.js';
import { CommandPalette } from '../chrome/CommandPalette.js';
import { ErrorBoundary } from '../chrome/ErrorBoundary.js';
import { LoadingScreen } from '../chrome/LoadingScreen.js';
import { ConsoleBootShell, RouteMetadataSkeleton } from './ConsoleBootShell.js';
import { BackToHomeButton, NotFoundState } from '../components/NotFoundState.js';
import { RedirectWithSplash } from '../chrome/RedirectWithSplash.js';
// `ObjectNotFoundState` from its own module, not through `ObjectView`: the
Expand All @@ -67,7 +68,7 @@ import {
navEntriesShownOncePendingReadsShow,
} from '../hooks/useNavMemberGates.js';
import { resolveSetupAppPath } from './ConsoleShell.js';
import { APP_ROUTE_METADATA_READS, collectRoutePaths, metadataReadsForAppRoute, type LazyMetadataType } from './appRouteMetadataReads.js';
import { APP_ROUTE_METADATA_READS, collectRoutePaths, metadataReadsForAppRoute } from './appRouteMetadataReads.js';
import { enterAppBundle, objectViewRouteObject, prefetchObjectViewRows, readAppObjectScope } from './appObjectScope.js';
import { preferLocal } from '../utils/preferLocal.js';
import {
Expand All @@ -77,7 +78,7 @@ import {
setupMetadataStudioPath,
} from '../views/studio-design/setupMetadataRedirect.js';
import { NO_RECORD_DRAWERS_OPENING, NO_RECORD_PAGE_DRAWERS_OPEN, RecordDrawerOpeningProvider, RecordPageDrawerOpenProvider, useRecordFormOpensOverDrawers, type RecordDrawersOpening, type RecordPageDrawersOpen } from '../views/recordDrawerStack.js';
import { SkeletonDashboard, SkeletonDetail, SkeletonGrid } from '../skeletons/index.js';
import { SkeletonGrid } from '../skeletons/index.js';

// Route-based code splitting — lazy-load less-frequently-used routes.
//
Expand Down Expand Up @@ -331,15 +332,29 @@ export function AppContent({ extraRoutes, extraRoutesNoApp }: AppContentProps =
// it empty until the fetch resolves so predicates default to "visible"
// and we don't briefly hide UI on slow networks.
const [features, setFeatures] = useState<Record<string, any>>({});
// objectstack#35981 — whether that answer (or its failure) is in. The
// readiness gate below holds the chrome on it: the chrome's navigation
// gates bind `features`, and a navigation predicate that names a flag not
// bound yet FAULTS and withholds its entry (objectui#12700), so a chrome
// mounted before the answer would hide a flag-gated entry and then draw it.
// Until the chrome stopped waiting for the route's own reads, that answer
// was in first only by timing.
const [featuresSettled, setFeaturesSettled] = useState(false);
useEffect(() => {
let cancelled = false;
if (typeof getAuthConfig !== 'function') {
setFeaturesSettled(true);
return;
}
getAuthConfig()
.then((cfg) => {
if (cancelled) return;
setFeatures((cfg?.features as Record<string, any>) ?? {});
setFeaturesSettled(true);
})
.catch(() => {
/* leave empty — predicates default to visible */
if (!cancelled) setFeaturesSettled(true);
});
return () => {
cancelled = true;
Expand Down Expand Up @@ -609,10 +624,11 @@ export function AppContent({ extraRoutes, extraRoutesNoApp }: AppContentProps =
if (!viewReadObject || !viewReadReady || !bundleAppName || previewDrafts) return;
prefetchObjectViewRows(dataSource, viewReadObject);
}, [dataSource, viewReadObject, viewReadReady, bundleAppName, previewDrafts]);
// Set once the first frame past the splash has rendered. After it, a route
// waiting on its buckets draws its skeleton inside the console chrome rather
// than taking the whole console back to the splash.
const firstPaintDone = useRef(false);
// objectstack#35981 — set once this page load's first route has drawn. Until
// then the route slot's skeleton is the boot wait (`RouteMetadataSkeleton`'s
// `boot`), so what waits for the first paint past the splash still waits for
// the route (objectui#12980), while the chrome is already on screen.
const firstRouteDrawn = useRef(false);

// A normal app was requested but isn't present in the loaded metadata — the
// post-publish readiness lag, or a genuinely-missing app. Applies in BOTH
Expand Down Expand Up @@ -1214,17 +1230,21 @@ export function AppContent({ extraRoutes, extraRoutesNoApp }: AppContentProps =
// `positions[]` leg, which is every admin on a session minted with an active
// organization stamped) waits exactly zero extra frames. What does wait is
// the viewer whose verdict genuinely is not known yet — and for them a
// LoadingScreen is the honest frame, not a screen built on a guess.
// frame that decides nothing is the honest one, not a screen built on a guess.
//
// objectui#12809 — of the lazy metadata, the splash waits only for what the
// current route reads (`routeReadsSettled`), and only until the first paint.
if (
!dataSource ||
metadataLoading ||
!isWorkspaceAdminResolved ||
(!firstPaintDone.current && !routeReadsSettled)
) return <LoadingScreen />;
firstPaintDone.current = true;
// objectui#12809 — the lazy metadata the current route reads does not hold
// the gate at all (objectstack#35981): the chrome decides nothing from it,
// so it mounts once the inputs above are in, and the route slot draws the
// route's skeleton until its reads land (`routeReadsSettled`, below).
//
// objectstack#35981 — while the gate holds, the console chrome's empty frame
// (`ConsoleBootShell`), not the full-screen splash: it names no app and draws
// no navigation entry, which is exactly what the inputs above decide.
//
// objectstack#35981 — and the deployment flags (`featuresSettled`, above):
// the chrome's navigation gates read them.
if (!dataSource || metadataLoading || !isWorkspaceAdminResolved || !featuresSettled) return <ConsoleBootShell />;
if (routeReadsSettled) firstRouteDrawn.current = true;

// ADR-0037 — preview mode renders its OWN empty/error states and never
// falls through to the generic "No Apps Configured" guard below: inside a
Expand Down Expand Up @@ -1296,7 +1316,7 @@ export function AppContent({ extraRoutes, extraRoutesNoApp }: AppContentProps =
// page; `denied` is the screen above, and every other verdict falls through
// to the pseudo-route rendering below, unchanged.
if (appSurfaceAwaitsVerdict && !previewDrafts) {
if (accessVerdict === null) return <LoadingScreen />;
if (accessVerdict === null) return <ConsoleBootShell />;
if (accessVerdict === 'denied') return renderAppAccessDenied();
}

Expand All @@ -1305,7 +1325,7 @@ export function AppContent({ extraRoutes, extraRoutesNoApp }: AppContentProps =
// different app, and don't show the misleading "no apps configured" screen
// below (there ARE apps). requestedAppMissing already excludes pseudo-routes.
if (requestedAppMissing) {
if (missingRecheck !== 'done' || accessVerdict === null) return <LoadingScreen />;
if (missingRecheck !== 'done' || accessVerdict === null) return <ConsoleBootShell />;
if (accessVerdict === 'denied') return renderAppAccessDenied();
// objectui#9262 — the remaining verdicts, each saying only what the probe
// obtained. The screen this replaced asserted ONE transient deploy state
Expand Down Expand Up @@ -1416,7 +1436,7 @@ export function AppContent({ extraRoutes, extraRoutesNoApp }: AppContentProps =
// guard reads only the per-user-filtered list that ships today.
if (!activeApp && !isCreateAppRoute && !isSystemRoute && !isMetadataRoute && !isWorkspaceAdmin) {
// `RedirectWithSplash`, not a bare `<Navigate>` (objectui#6378 / #6507).
// Every readiness gate above this branch renders `LoadingScreen`, and the
// Every readiness gate above this branch renders a boot frame, and the
// branch returns ABOVE the single `ConsoleLayout` mount — so a bare
// redirect, which renders null, hands the WHOLE viewport back to the page
// background while `/home` renders at transition priority. Measured on the
Expand Down Expand Up @@ -1571,11 +1591,15 @@ export function AppContent({ extraRoutes, extraRoutesNoApp }: AppContentProps =
<OnboardingWalkthrough />
<DraftReviewNavigator appName={appName} />
<ErrorBoundary>
<Suspense fallback={<LoadingScreen />}>
{/* objectstack#35981 — a route element whose chunk is still loading
draws the route's skeleton in the slot, not the full-screen
splash inside the chrome. It is the boot wait as that splash
was (`data-boot-splash`), whenever it shows. */}
<Suspense fallback={<RouteMetadataSkeleton reads={routeReadsKey || 'object'} boot />}>
<RouteFader className="h-full">
{/* objectui#12809 — the route's metadata has not landed: its
skeleton, never its empty or "not found" state. */}
{!routeReadsSettled ? <RouteMetadataSkeleton reads={routeReadsKey || 'object'} /> : objectScope && routeObjectReadsFailed.length > 0 ? (
{!routeReadsSettled ? <RouteMetadataSkeleton reads={routeReadsKey || 'object'} boot={!firstRouteDrawn.current} /> : objectScope && routeObjectReadsFailed.length > 0 ? (
// objectui#13052 — the route's object read failed (a 5xx, a
// network drop, a code this build does not know): say so in
// the shell, and let Retry ask those names once more.
Expand Down Expand Up @@ -2328,12 +2352,3 @@ function useLazyMetadataSettled(
return settled;
}

/** The route slot while its metadata loads, shaped like what will land there. */
function RouteMetadataSkeleton({ reads }: { reads: string }) {
const types = reads.split(',') as LazyMetadataType[];
return (
<div data-testid="route-metadata-skeleton" className="h-full">
{types[0] === 'dashboard' ? <SkeletonDashboard /> : types.includes('page') ? <SkeletonDetail /> : <SkeletonGrid />}
</div>
);
}
Loading
Loading