Skip to content

The agent that grows with you

fix(desktop): route tile title heals when its plugin route registers late

teknium1c91770b26816
diff --git a/apps/desktop/src/app/chat/route-tile-title.test.tsx b/apps/desktop/src/app/chat/route-tile-title.test.tsx
new file mode 100644
index 00000000000..b1c96898b04
--- /dev/null
+++ b/apps/desktop/src/app/chat/route-tile-title.test.tsx
@@ -0,0 +1,40 @@
+/**
+ * A route tile opened BEFORE its plugin route registers must pick up the
+ * contribution's title once registration lands. `paneMirror` recomputes titles
+ * only when one of its atoms changes; without a routes-area signal the tab
+ * kept the humanized-path fallback forever while the pane content healed.
+ */
+import { afterEach, beforeAll, expect, it } from 'vitest'
+
+import { registry } from '@/contrib/registry'
+import { $routeTiles, closeRouteTile, openRouteTile } from '@/store/route-tiles'
+
+import { watchRouteTiles } from './route-tile'
+
+const paneTitle = (path: string) => registry.getArea('panes').find(c => c.id === `route-tile:${path}`)?.title
+
+beforeAll(() => {
+ watchRouteTiles()
+})
+
+afterEach(() => {
+ for (const tile of $routeTiles.get()) {
+ closeRouteTile(tile.path)
+ }
+})
+
+it('refreshes the tile title when its route registers after the tile opened', () => {
+ openRouteTile('/late-atlas')
+ expect(paneTitle('/late-atlas')).toBe('Late Atlas')
+
+ const dispose = registry.register({
+ area: 'routes',
+ id: 'late-atlas:page',
+ title: 'Atlas of Everything',
+ data: { path: '/late-atlas' },
+ render: () => null
+ })
+
+ expect(paneTitle('/late-atlas')).toBe('Atlas of Everything')
+ dispose()
+})
diff --git a/apps/desktop/src/app/chat/route-tile.tsx b/apps/desktop/src/app/chat/route-tile.tsx
index 7fc508abd40..4fee30c2d2d 100644
--- a/apps/desktop/src/app/chat/route-tile.tsx
+++ b/apps/desktop/src/app/chat/route-tile.tsx
@@ -13,7 +13,7 @@ import { ContribBoundary, ContribRender } from '@/contrib/react/boundary'
import { useContributions } from '@/contrib/react/use-contributions'
import { $routeTiles, closeRouteTile, type RouteTile } from '@/store/route-tiles'
-import { ARTIFACTS_ROUTE, contributedRoutes, MESSAGING_ROUTE, ROUTES_AREA, SKILLS_ROUTE } from '../routes'
+import { $routesVersion, ARTIFACTS_ROUTE, contributedRoutes, MESSAGING_ROUTE, ROUTES_AREA, SKILLS_ROUTE } from '../routes'
import { paneMirror } from './pane-mirror'
@@ -88,6 +88,9 @@ export function RouteTilePane({ path }: { path: string }) {
/** Keep pane contributions mirroring `$routeTiles`. Call once from the root. */
export const watchRouteTiles = paneMirror<RouteTile>({
source: $routeTiles,
+ // A tile restored before its plugin route registers must pick up the
+ // contribution's title once it lands, not keep the humanized-path fallback.
+ also: [$routesVersion],
key: t => t.path,
prefix: 'route-tile',
dir: t => t.dir,
diff --git a/apps/desktop/src/app/routes.ts b/apps/desktop/src/app/routes.ts
index db31f5cb80b..c2563a7523d 100644
--- a/apps/desktop/src/app/routes.ts
+++ b/apps/desktop/src/app/routes.ts
@@ -1,4 +1,4 @@
-import { atom } from 'nanostores'
+import { atom, onMount } from 'nanostores'
import type { ReactNode } from 'react'
import { noteActiveTreeGroup, revealTreePane } from '@/components/pane-shell/tree/store'
@@ -92,6 +92,13 @@ export interface RouteContribution {
path: string
}
+/** Bumps whenever the `routes` area mutates. For non-React consumers that
+ * derive from `contributedRoutes()` outside a render (paneMirror titles):
+ * hand it to `also` so a plugin route registering after its tile opened
+ * re-syncs the tab title. Subscribes to the registry only while listened to. */
+export const $routesVersion = atom(0)
+onMount($routesVersion, () => registry.subscribeArea(ROUTES_AREA, () => $routesVersion.set($routesVersion.get() + 1)))
+
// React consumers must pass their `useContributions(ROUTES_AREA)` snapshot in:
// with React Compiler enabled, an independently-called `contributedRoutes()`
// can stay memoized across a late registration the subscription DID deliver.