Skip to content

Commit a40710f

Browse files
committed
fix(console): the push listener hosts only under the app its URL names, and the catch-all waits for a settled app list
Measured live: a session-cached app list stops `loading` while its re-read still reads `loading`, so the catch-all redirected to Home; and hosting under `currentAppName` (an app name) made the app route re-address the page several times. The listener now hands a route on whenever the URL names no app. Claude-Session: https://claude.ai/code/session_01QsR2jVL7fzYGjxa3ani6k8 Co-Authored-By: Claude <noreply@anthropic.com>
1 parent a150b5c commit a40710f

4 files changed

Lines changed: 52 additions & 25 deletions

File tree

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import {
3838
DefaultSettingsPage,
3939
DefaultAcceptInvitationPage,
4040
useMetadata,
41-
useNavigationContext,
4241
} from '@object-ui/app-shell';
4342

4443
import { AppContent, ConsolePermissionsRequest, ConsolePermissionsScope } from './AppContent';
@@ -154,18 +153,20 @@ const BASENAME = resolveBasename();
154153
*
155154
* The shell's route is a push route, the notification's `actionUrl`, and is
156155
* 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.
156+
* hosts that link (`nativeShellRouteTarget`). Inside an app it goes under the
157+
* app the URL names. Anywhere else (Home, a cold start) the route goes to the
158+
* router as given, and the catch-all's `UnmatchedRoute` hosts it once the app
159+
* list is loaded: under the app the person last had open while it is still
160+
* active, else the first active app. The shell's published `currentAppName` is
161+
* left to that guard because it is an app NAME, and only the app list turns a
162+
* name into the address its route uses.
161163
*/
162164
function NativeShellRouting() {
163165
const location = useLocation();
164166
const navigate = useNavigate();
165-
const { currentAppName } = useNavigationContext();
166167
// Outside every `MetadataProvider`, so the empty list; see `nativeShellRouteTarget`.
167168
const { apps } = useMetadata();
168-
const hostHint = currentAppName ?? matchPath('/apps/:appName/*', location.pathname)?.params.appName;
169+
const hostHint = matchPath('/apps/:appName/*', location.pathname)?.params.appName;
169170
const navigateShellRoute = useCallback(
170171
(route: string) => {
171172
const path = nativeShellRouteTarget(route, hostHint, apps);

‎ui/apps/console/src/__tests__/App.nativeShellMode-29039.test.tsx‎

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,14 +241,21 @@ describe('a push route from the shell is hosted the way the inbox hosts it', ()
241241
.toBe('/apps/crm/opportunity/123?tab=activity#notes');
242242
});
243243

244-
it('the app the shell last published wins over the URL, as for the inbox bell', async () => {
244+
it('away from an app, the catch-all hosts it under the app the person last had open', async () => {
245+
// `currentAppName` is an app NAME; the catch-all turns it into the app's
246+
// route segment with the app list, which the listener does not have.
245247
installBridge();
246248
shellState.currentAppName = 'sales';
249+
shellState.apps = [{ name: 'crm', active: true }, { name: 'sales', active: true, _packageId: 'com.acme.sales' }];
250+
shellState.appStatus = 'ready';
247251
window.history.pushState({}, '', '/home');
248252
render(<App />);
249253
await screen.findByTestId('home-page');
250-
dispatchNavigate('/opportunity/123');
251-
expect(window.location.pathname).toBe('/apps/sales/opportunity/123');
254+
const event = dispatchNavigate('/opportunity/123');
255+
expect(event.defaultPrevented).toBe(true);
256+
expect(window.location.pathname).toBe('/opportunity/123');
257+
expect((await screen.findByTestId('redirect-with-splash')).getAttribute('data-to'))
258+
.toBe('/apps/com.acme.sales/opportunity/123');
252259
});
253260

254261
it('a Console route under /apps passes through unchanged', async () => {
@@ -312,6 +319,17 @@ describe('the catch-all hosts an app-relative first URL under an app', () => {
312319
expect(screen.queryByTestId('redirect-with-splash')).toBeNull();
313320
});
314321

322+
it('waits while a session-cached app list is still being re-read', async () => {
323+
// Measured live: the provider stops `loading` on the cached list while
324+
// the app type's own status still reads `loading`.
325+
shellState.apps = [{ name: 'crm', active: true }];
326+
shellState.appStatus = 'loading';
327+
window.history.pushState({}, '', '/opportunity/123');
328+
render(<App />);
329+
expect(await screen.findByTestId('loading-fallback')).toBeInTheDocument();
330+
expect(screen.queryByTestId('redirect-with-splash')).toBeNull();
331+
});
332+
315333
it('an app list that failed to load is no answer: the old redirect to / runs', async () => {
316334
shellState.appStatus = 'error';
317335
window.history.pushState({}, '', '/opportunity/123');

‎ui/apps/console/src/components/UnmatchedRoute.tsx‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@
1919
* apps, else the first active app. That needs the app list, so the hop runs
2020
* under `ProtectedRoute` (`requireOrganization={false}`, like `/`, because it
2121
* 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.
22+
* waits until the list has settled (`isAppListConclusive`, the landing
23+
* route's own reading). A signed-out visitor goes to the login page first and
24+
* comes back to the same path. An app list that failed to load is no answer
25+
* to host under; that case keeps the old redirect to `/`, whose landing
26+
* resolver owns the retry.
2627
*/
2728
import { useLocation } from 'react-router-dom';
2829
import {
@@ -53,8 +54,12 @@ function HostAppRelativeRedirect() {
5354
const location = useLocation();
5455
const { apps, loading, getTypeStatus } = useMetadata();
5556
const { currentAppName } = useNavigationContext();
56-
if (loading) return <LoadingFallback />;
57-
if (!isAppListConclusive(getTypeStatus?.('app'))) return <RedirectWithSplash to="/" replace />;
57+
// The list is the answer only once it settled: a session-cached list keeps
58+
// `loading` false while its re-read is still in flight (status `loading`),
59+
// and hosting under it then could name an app the re-read drops.
60+
const status = getTypeStatus?.('app');
61+
if (status === 'error') return <RedirectWithSplash to="/" replace />;
62+
if (loading || !isAppListConclusive(status)) return <LoadingFallback />;
5863
const target = resolveNotificationTarget(
5964
`${location.pathname}${location.search}${location.hash}`,
6065
resolveHostAppSegment(apps, currentAppName),

‎ui/apps/console/src/nativeShellRoute.ts‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,19 @@ type HostApps = Parameters<typeof resolveHostAppSegment>[0];
3737
* The path the native navigate listener moves the router to, or `null` to stay
3838
* where the person is.
3939
*
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).
40+
* `hostHint` is the app the person is in: the `:appName` of the current
41+
* `/apps/:appName/*` URL, already the segment its route is addressed by.
42+
* `apps` is whatever app list is in reach; the listener renders outside every
43+
* `MetadataProvider`, so there it is the empty list, and
44+
* `resolveHostAppSegment` then answers the hint itself (its step 3).
4545
*
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.
46+
* - No hint (Home, a cold start): the route as given. Naming the app then
47+
* takes the app list: the default app, or the shell's `currentAppName`,
48+
* which is an app NAME that only the list turns into its route segment
49+
* (measured: hosted under the name, the app route re-addresses the page
50+
* several times before it settles). So the route goes to the router
51+
* unchanged and the unmatched-route guard, which waits for the list, hosts
52+
* it. A Console route (`/apps/…`, `/home`, …) simply matches its own route.
5053
* - A hint: `resolveNotificationTarget(route, segment)`. A `route` answer is
5154
* the path; `null` (no url) and `external` (a scheme or `//host`) are
5255
* `null`, so nothing moves. Neither is reachable through the listener: the

0 commit comments

Comments
 (0)