Skip to content

Commit 92a6f43

Browse files
committed
fix(console): a native push route is hosted under an app, as the inbox hosts it
The native navigate listener resolves the shell's route through the inbox's resolveNotificationTarget under the app the person is in or last had open, and the catch-all hosts an unmatched app-relative path under the default app instead of dropping it on Home. app-shell publishes the resolver and the console root-segment table from its root. Claude-Session: https://claude.ai/code/session_01QsR2jVL7fzYGjxa3ani6k8 Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 6f09464 commit 92a6f43

4 files changed

Lines changed: 182 additions & 5 deletions

File tree

‎ui/apps/console/src/App.tsx‎

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
* with extra `<Route>` children.
1313
*/
1414

15-
import { lazy, Suspense, useEffect, useMemo } from 'react';
16-
import { BrowserRouter, Routes, Route, Navigate, Outlet, useLocation, useNavigate } from 'react-router-dom';
15+
import { lazy, Suspense, useCallback, useEffect, useMemo } from 'react';
16+
import { BrowserRouter, Routes, Route, Navigate, Outlet, matchPath, useLocation, useNavigate } from 'react-router-dom';
1717
import { useNativeHostRouting } from '@object-ui/mobile';
1818
import { AuthProvider, useAuth, createAuthenticatedFetch } from '@object-ui/auth';
1919
import { UploadProvider, createObjectStackUploadAdapter } from '@object-ui/providers';
@@ -37,7 +37,8 @@ import {
3737
DefaultInvitationsPage,
3838
DefaultSettingsPage,
3939
DefaultAcceptInvitationPage,
40-
RedirectWithSplash,
40+
useMetadata,
41+
useNavigationContext,
4142
} from '@object-ui/app-shell';
4243

4344
import { AppContent, ConsolePermissionsRequest, ConsolePermissionsScope } from './AppContent';
@@ -47,6 +48,8 @@ import { RootLandingRedirect } from './components/RootLandingRedirect';
4748
import { ProtectedRoute } from './components/ProtectedRoute';
4849
import { studioRoutes } from './components/StudioRoute';
4950
import { SetupRoute } from './components/SetupRoute';
51+
import { UnmatchedRoute } from './components/UnmatchedRoute';
52+
import { nativeShellRouteTarget } from './nativeShellRoute';
5053
import { FormPage } from './components/FormPage';
5154
import { InternalFormRoute } from './components/InternalFormRoute';
5255
import { MetadataHmrReloader } from './components/MetadataHmrReloader';
@@ -148,13 +151,31 @@ const BASENAME = resolveBasename();
148151
* the page. `data-os-native-shell` on the root element names the platform, so
149152
* a stylesheet can tell shell mode apart. Without the bridge this renders
150153
* nothing and installs nothing.
154+
*
155+
* The shell's route is a push route, the notification's `actionUrl`, and is
156+
* never navigated verbatim (objectstack#29750): it is hosted the way the inbox
157+
* hosts that link, under the app the person is in or last had open
158+
* (`nativeShellRouteTarget`). With no such app (a cold start), the route goes
159+
* to the router as given and the catch-all's `UnmatchedRoute` hosts it under
160+
* the default app once the app list is loaded.
151161
*/
152162
function NativeShellRouting() {
153163
const location = useLocation();
154164
const navigate = useNavigate();
165+
const { currentAppName } = useNavigationContext();
166+
// Outside every `MetadataProvider`, so the empty list; see `nativeShellRouteTarget`.
167+
const { apps } = useMetadata();
168+
const hostHint = currentAppName ?? matchPath('/apps/:appName/*', location.pathname)?.params.appName;
169+
const navigateShellRoute = useCallback(
170+
(route: string) => {
171+
const path = nativeShellRouteTarget(route, hostHint, apps);
172+
if (path !== null) navigate(path);
173+
},
174+
[apps, hostHint, navigate],
175+
);
155176
const host = useNativeHostRouting({
156177
route: `${location.pathname}${location.search}${location.hash}`,
157-
navigate,
178+
navigate: navigateShellRoute,
158179
});
159180
const platform = host?.platform;
160181
useEffect(() => {
@@ -486,7 +507,11 @@ export function App() {
486507
* `index` redirect above is deliberately NOT changed — it fires
487508
* under an already-painted organization layout, where covering the
488509
* screen with a splash would be the regression. */}
489-
<Route path="*" element={<RedirectWithSplash to="/" replace />} />
510+
{/* objectstack#29750 — an app-relative path (a push route such as
511+
* `/opportunity/123`, arriving as the first URL or handed over by
512+
* `NativeShellRouting`) is hosted under an app the way the inbox
513+
* hosts it; a stale Console link still redirects to `/`. */}
514+
<Route path="*" element={<UnmatchedRoute />} />
490515
</Routes>
491516
</ConsoleShell>
492517
</UploadProvider>
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* UnmatchedRoute — element for the Console's catch-all `<Route path="*" />`.
5+
*
6+
* A path no route matches used to go straight to `/`. That is still the answer
7+
* for a stale Console link (`/dev/x`, `/home/x`): see
8+
* `isAppRelativeUnmatchedPath`. An APP-RELATIVE path is a record the person was
9+
* sent to, and dropping it on Home loses it (objectstack#29750): a push route
10+
* such as `/opportunity/123` arrives here as the page's first URL when the
11+
* mobile shell re-creates its WebView at a held route, or full-loads it because
12+
* no navigate listener answered; and the Console's own navigate listener hands
13+
* a route over here when it cannot name the host app (a cold start, before any
14+
* app opened).
15+
*
16+
* Such a path is hosted the way the inbox hosts a notification's link:
17+
* `resolveNotificationTarget(path, resolveHostAppSegment(apps, currentAppName))`
18+
* — the app the person is in or last had open, re-checked against the active
19+
* apps, else the first active app. That needs the app list, so the hop runs
20+
* under `ProtectedRoute` (`requireOrganization={false}`, like `/`, because it
21+
* only redirects; the destination's route owns the organization gate) and
22+
* waits for the list. A signed-out visitor goes to the login page first and
23+
* comes back to the same path. An app list that did not load is no answer to
24+
* host under; that case keeps the old redirect to `/`, whose landing resolver
25+
* owns the retry.
26+
*/
27+
import { useLocation } from 'react-router-dom';
28+
import {
29+
LoadingFallback,
30+
RedirectWithSplash,
31+
resolveHostAppSegment,
32+
resolveNotificationTarget,
33+
useMetadata,
34+
useNavigationContext,
35+
} from '@object-ui/app-shell';
36+
import { ProtectedRoute } from './ProtectedRoute';
37+
import { isAppListConclusive } from './RootLandingRedirect';
38+
import { isAppRelativeUnmatchedPath } from '../nativeShellRoute';
39+
40+
export function UnmatchedRoute() {
41+
const location = useLocation();
42+
if (!isAppRelativeUnmatchedPath(location.pathname)) {
43+
return <RedirectWithSplash to="/" replace />;
44+
}
45+
return (
46+
<ProtectedRoute requireOrganization={false}>
47+
<HostAppRelativeRedirect />
48+
</ProtectedRoute>
49+
);
50+
}
51+
52+
function HostAppRelativeRedirect() {
53+
const location = useLocation();
54+
const { apps, loading, getTypeStatus } = useMetadata();
55+
const { currentAppName } = useNavigationContext();
56+
if (loading) return <LoadingFallback />;
57+
if (!isAppListConclusive(getTypeStatus?.('app'))) return <RedirectWithSplash to="/" replace />;
58+
const target = resolveNotificationTarget(
59+
`${location.pathname}${location.search}${location.hash}`,
60+
resolveHostAppSegment(apps, currentAppName),
61+
);
62+
return <RedirectWithSplash to={target?.kind === 'route' ? target.path : '/'} replace />;
63+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* Where a route the native shell hands the Console lands (objectstack#29750).
5+
*
6+
* A push delivery's `route` is the notification's `actionUrl`, the value the
7+
* inbox serves (`packages/spec/src/api/push-delivery.zod.ts`): app-relative
8+
* (`/opportunity/123`) or already a Console route (`/apps/crm/opportunity/123`).
9+
* The contract says the tap is resolved "as the inbox does, never verbatim",
10+
* and the inbox's resolver is `resolveNotificationTarget` with a host app
11+
* segment. Navigated verbatim, `/opportunity/123` matched no route and the
12+
* catch-all dropped the person on Home.
13+
*
14+
* Two sites resolve it, both through that one resolver:
15+
*
16+
* - the native navigate listener (`NativeShellRouting` in `App.tsx`), when it
17+
* can name the host app: {@link nativeShellRouteTarget};
18+
* - the unmatched-route guard (`components/UnmatchedRoute.tsx`), for everything
19+
* else: an app-relative path arriving as the page's first URL (the shell
20+
* re-creates its WebView at a held route, or full-loads it when no listener
21+
* answered), and a route the listener handed over because it could not name
22+
* the app. {@link isAppRelativeUnmatchedPath} decides which unmatched paths
23+
* are hosted.
24+
*
25+
* @module
26+
*/
27+
import {
28+
CONSOLE_ROOT_SEGMENTS,
29+
resolveHostAppSegment,
30+
resolveNotificationTarget,
31+
} from '@object-ui/app-shell';
32+
33+
/** The app records `resolveHostAppSegment` reads, derived from its signature. */
34+
type HostApps = Parameters<typeof resolveHostAppSegment>[0];
35+
36+
/**
37+
* The path the native navigate listener moves the router to, or `null` to stay
38+
* where the person is.
39+
*
40+
* `hostHint` is the app the person is in or last had open: the shell's
41+
* published `currentAppName`, else the `:appName` of the current URL, the same
42+
* hint every inbox door passes. `apps` is whatever app list is in reach; the
43+
* listener renders outside every `MetadataProvider`, so there it is the empty
44+
* list, and `resolveHostAppSegment` then answers the hint itself (its step 3).
45+
*
46+
* - No hint: the route as given. Nothing in reach can name the default app
47+
* (that needs the app list), so the route goes to the router unchanged and
48+
* the unmatched-route guard, which waits for the list, hosts it there. A
49+
* Console route (`/apps/…`, `/home`, …) simply matches its own route.
50+
* - A hint: `resolveNotificationTarget(route, segment)`. A `route` answer is
51+
* the path; `null` (no url) and `external` (a scheme or `//host`) are
52+
* `null`, so nothing moves. Neither is reachable through the listener: the
53+
* shell's event is only taken (and cancelled) for an `isInAppRoute` path,
54+
* which is never blank and never carries a scheme or a second leading `/`.
55+
*/
56+
export function nativeShellRouteTarget(
57+
route: string,
58+
hostHint: string | null | undefined,
59+
apps: HostApps,
60+
): string | null {
61+
if (!hostHint) return route;
62+
const target = resolveNotificationTarget(route, resolveHostAppSegment(apps, hostHint));
63+
return target?.kind === 'route' ? target.path : null;
64+
}
65+
66+
/**
67+
* Is an unmatched pathname app-relative, so the catch-all hosts it under an app
68+
* instead of redirecting to `/`?
69+
*
70+
* Yes unless its first segment names a Console route served outside an app
71+
* (`CONSOLE_ROOT_SEGMENTS`, the empty segment included) or is `apps`, which
72+
* `resolveNotificationTarget` passes through unchanged and so has nothing to
73+
* host. Those keep the catch-all's redirect to `/`: an unknown `/dev/x` or
74+
* `/home/x` is a stale Console link, not a record.
75+
*/
76+
export function isAppRelativeUnmatchedPath(pathname: string): boolean {
77+
if (!pathname.startsWith('/')) return false;
78+
const firstSegment = pathname.slice(1).split('/', 1)[0];
79+
return firstSegment !== 'apps' && !CONSOLE_ROOT_SEGMENTS.has(firstSegment);
80+
}

‎ui/packages/app-shell/src/index.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,15 @@ export {
9494
// (objectui#4109 / PR #4279), which is the "two readers of one prose contract"
9595
// shape #3367 / #3842 record. `./utils/appRoute` is the contract.
9696
export { resolveHostAppSegment, appRouteSegment, filterActiveApps } from './utils/index.js';
97+
// objectstack#29750 — the inbox's notification-link resolver, and the table of
98+
// console routes served outside an app. The console's native-shell navigate
99+
// listener and its unmatched-route guard host an app-relative push route
100+
// through the SAME resolver every inbox door uses, so a push tap and the inbox
101+
// row open the same screen; re-deriving either here would be a second reader
102+
// of one contract.
103+
export { resolveNotificationTarget } from './utils/index.js';
104+
export type { NotificationTarget } from './utils/index.js';
105+
export { CONSOLE_ROOT_SEGMENTS } from './utils/hostInConsolePath.js';
97106
// objectui#5178 — the Approval Center's timeline reads the same `via_override`
98107
// verdict the record page's approval panel does.
99108
export {

0 commit comments

Comments
 (0)