Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

fix(web): use direct mobile server hierarchy (#611)

Generef03a872a833
diff --git a/DESIGN.md b/DESIGN.md
index c671c23a0..1f2029ee0 100644
--- a/DESIGN.md
+++ b/DESIGN.md
@@ -117,9 +117,9 @@ For Community server routes, the URL owns selection and the checkpoint owns comp
| Route | Meaning | Mobile `< 640px` | Desktop `≥ 640px` |
| --- | --- | --- | --- |
| `/c/channels/{serverId}` | Server list/landing | Server rail + that server's channel list; no channel detail. | Server rail + channel sidebar + main landing. Replace to the remembered channel, otherwise the first top-level channel; an empty server stays on the root. |
-| `/c/channels/{serverId}/{channelId}` | Exact channel detail | Channel detail only, with Header Back to the semantic parent route. | Server rail + channel sidebar + channel detail in one frame. |
+| `/c/channels/{serverId}/{channelId}` | Exact channel detail | Channel detail only. The leading server icon replaces directly to the server root; a visible parent breadcrumb replaces directly to that parent channel. | Server rail + channel sidebar + channel detail in one frame. |
-Both checkpoints share the same server-scoped data model. A detail route adds channel-scoped content queries; changing checkpoint never changes the route's business meaning or creates a device-specific query contract. Header Back uses replace-style semantic navigation, while browser Back/Forward remains browser-history owned.
+Both checkpoints share the same server-scoped data model. A detail route adds channel-scoped content queries; changing checkpoint never changes the route's business meaning or creates a device-specific query contract. Mobile server hierarchy controls use replace-style navigation to their explicit canonical URLs, while browser Back/Forward remains browser-history owned. DM/Me keeps its separate Back contract.
Rules:
- **Read the breakpoint, don't guess.** Use `useBreakpoint()` (string) or `useIsMobile()` (boolean) for any behavior that must branch by stage. Don't sprinkle raw `window.innerWidth` checks or ad-hoc `matchMedia` calls — they drift away from the shared boundary and re-mount without SSR safety.
diff --git a/scripts/ci/e2e-shards.mjs b/scripts/ci/e2e-shards.mjs
index d137bd25c..1ed17a347 100644
--- a/scripts/ci/e2e-shards.mjs
+++ b/scripts/ci/e2e-shards.mjs
@@ -50,6 +50,7 @@ export const SPEC_SECONDS = {
"37-server-rail-pdd.spec.ts": 10,
"38-community-navigation-checkpoint-matrix.spec.ts": 60,
"39-mobile-composer-send.spec.ts": 45,
+ "40-mobile-server-header-hierarchy.spec.ts": 28,
"40-server-rail-unread.spec.ts": 60,
}
diff --git a/scripts/ci/e2e-shards.test.ts b/scripts/ci/e2e-shards.test.ts
index 58826ce96..2cb558908 100644
--- a/scripts/ci/e2e-shards.test.ts
+++ b/scripts/ci/e2e-shards.test.ts
@@ -70,7 +70,7 @@ describe("planE2eShards", () => {
expect(first).toHaveLength(E2E_SHARD_COUNT)
expect([...assigned].sort()).toEqual(specs)
expect(new Set(assigned).size).toBe(specs.length)
- expect(totals.sort((left, right) => left - right)).toEqual([335, 336, 338, 339, 339])
+ expect(totals.sort((left, right) => left - right)).toEqual([341, 341, 344, 344, 345])
expect(Math.max(...totals) / Math.min(...totals)).toBeLessThanOrEqual(1.15)
})
diff --git a/src/web/src/components/community/channels/channel-header.navigation.test.ts b/src/web/src/components/community/channels/channel-header.navigation.test.ts
new file mode 100644
index 000000000..e2696c3ff
--- /dev/null
+++ b/src/web/src/components/community/channels/channel-header.navigation.test.ts
@@ -0,0 +1,87 @@
+import { createElement } from "react"
+import TestRenderer, { act } from "react-test-renderer"
+import { describe, expect, it, vi } from "vitest"
+import { tid } from "@/lib/community/testids"
+import { ChannelHeader } from "./channel-header"
+
+function render(overrides: Record<string, unknown> = {}) {
+ let renderer!: TestRenderer.ReactTestRenderer
+ act(() => {
+ renderer = TestRenderer.create(createElement(ChannelHeader, {
+ channel: "general",
+ rightPanel: null,
+ onToggle: vi.fn(),
+ tools: { members: false, threads: false, pinned: false },
+ ...overrides,
+ }))
+ })
+ return renderer
+}
+
+describe("ChannelHeader hierarchy navigation", () => {
+ it("uses one mobile-only 44px server control and suppresses legacy Back", () => {
+ const onNavigate = vi.fn()
+ const onBack = vi.fn()
+ const renderer = render({
+ mobileServer: { id: "s1", name: "Studio", icon: null, onNavigate },
+ onBack,
+ })
+
+ const server = renderer.root.findByProps({ "data-testid": tid.channelHeaderServer("s1") })
+ expect(server.props).toMatchObject({
+ type: "button",
+ "aria-label": "Go to server Studio",
+ })
+ expect(server.props.className).toContain("size-11")
+ expect(server.props.className).toContain("sm:hidden")
+ expect(server.findByType("span").props.className).toContain("size-6")
+ act(() => server.props.onClick())
+ expect(onNavigate).toHaveBeenCalledOnce()
+ expect(onBack).not.toHaveBeenCalled()
+ expect(renderer.root.findAllByProps({ "aria-label": "Back" })).toHaveLength(0)
+ })
+
+ it("preserves an uploaded server image inside the 24px mobile visual", () => {
+ const renderer = render({
+ mobileServer: {
+ id: "s1",
+ name: "Studio",
+ icon: "https://example.test/server.png",
+ onNavigate: vi.fn(),
+ },
+ })
+
+ const server = renderer.root.findByProps({ "data-testid": tid.channelHeaderServer("s1") })
+ const image = server.findByType("img")
+ expect(image.props).toMatchObject({
+ src: "https://example.test/server.png",
+ alt: "",
+ className: "size-full object-cover",
+ })
+ expect(server.findByType("span").props.className).toContain("size-6")
+ })
+
+ it("navigates a verified parent directly while the current child stays inert", () => {
+ const onNavigateParent = vi.fn()
+ const renderer = render({
+ channel: "general",
+ mobileServer: { id: "s1", name: "Studio", icon: null, onNavigate: vi.fn() },
+ breadcrumb: {
+ id: "c1",
+ label: "Thread title",
+ onNavigate: onNavigateParent,
+ },
+ })
+
+ const parent = renderer.root.findByProps({ "data-testid": tid.channelHeaderParent("c1") })
+ expect(parent.props.className).toContain("min-w-0")
+ expect(parent.props.className).toContain("max-w-24")
+ expect(parent.props.className).toContain("sm:max-w-none")
+ act(() => parent.props.onClick())
+ expect(onNavigateParent).toHaveBeenCalledOnce()
+ const current = renderer.root.findByProps({ title: "Thread title" })
+ expect(current.type).toBe("span")
+ expect(current.props.className).toContain("min-w-8")
+ expect(current.props.className).toContain("sm:min-w-0")
+ })
+})
diff --git a/src/web/src/components/community/channels/channel-header.skeleton.test.ts b/src/web/src/components/community/channels/channel-header.skeleton.test.ts
index 9c670487e..355322136 100644
--- a/src/web/src/components/community/channels/channel-header.skeleton.test.ts
+++ b/src/web/src/components/community/channels/channel-header.skeleton.test.ts
@@ -1,16 +1,20 @@
import { createElement } from "react"
import { renderToStaticMarkup } from "react-dom/server"
-import { describe, expect, it, vi } from "vitest"
+import { describe, expect, it } from "vitest"
+import { tid } from "@/lib/community/testids"
import { ChannelHeaderSkeleton } from "./channel-header"
describe("ChannelHeaderSkeleton", () => {
- it("renders Back geometry without exposing loading interaction", () => {
- const html = renderToStaticMarkup(
- createElement(ChannelHeaderSkeleton, { onBack: vi.fn() }),
- )
+ it("renders inert mobile server-leading geometry without Back interaction", () => {
+ const html = renderToStaticMarkup(createElement(ChannelHeaderSkeleton))
- expect(html).toContain('data-slot="loading-back-placeholder"')
+ expect(html).toContain(`data-testid="${tid.channelHeaderServerLoading}"`)
+ expect(html).toContain('data-slot="loading-server-leading"')
+ expect(html).toMatch(/class="[^"]*size-11[^"]*sm:hidden[^"]*"/)
+ expect(html).toMatch(/class="[^"]*size-6[^"]*rounded-md[^"]*"/)
+ expect(html).toMatch(/class="[^"]*ml-1 size-7 rounded-md"/)
expect(html).not.toContain("<button")
expect(html).not.toContain('aria-label="Back"')
+ expect(html).not.toContain("loading-back-placeholder")
})
})
diff --git a/src/web/src/components/community/channels/channel-header.tsx b/src/web/src/components/community/channels/channel-header.tsx
index adf3e8436..bb5a7ba57 100644
--- a/src/web/src/components/community/channels/channel-header.tsx
+++ b/src/web/src/components/community/channels/channel-header.tsx
@@ -18,30 +18,29 @@ import { previewSlug } from "@/lib/community/slug-preview"
import { SeededBackdrop } from "@/components/avatar"
import type { RightPanel } from "@/components/community/shell/panel-types"
import { CreateDialogShell } from "../settings/create-dialog-shell"
+import { tid } from "@/lib/community/testids"
// Skeleton header for the loading frame between route change and channel
// metadata arriving. Same h-12 footprint as <ChannelHeader> so the body below
// doesn't shift when the real header lands.
-export function ChannelHeaderSkeleton({
- onBack,
- reserveBackSlot = false,
-}: {
- onBack?: () => void
- reserveBackSlot?: boolean
-}) {
- const showBackSlot = reserveBackSlot || Boolean(onBack)
+export function ChannelHeaderSkeleton() {
return (
<header role="banner" className="flex h-12 shrink-0 items-center gap-1 border-b border-border/40 px-3">
- {showBackSlot && (
- <Skeleton data-slot="loading-back-placeholder" aria-hidden className="size-8 shrink-0 rounded-md" />
- )}
- <Skeleton className="ml-1 size-6 rounded-md" />
+ <div
+ data-testid={tid.channelHeaderServerLoading}
+ data-slot="loading-server-leading"
+ aria-hidden
+ className="grid size-11 shrink-0 place-items-center sm:hidden"
+ >
+ <Skeleton className="size-6 rounded-md" />
+ </div>
+ <Skeleton className="size-6 rounded-md sm:ml-1" />
<Skeleton className="h-4 w-32 rounded" />
<div className="ml-auto flex items-center text-muted-foreground">
<Skeleton className="size-7 rounded-md" />
<span className="mx-1 h-5 w-px bg-border/60" aria-hidden />
<Skeleton className="size-7 rounded-md" />
- <Skeleton className="size-7 rounded-md" />
+ <Skeleton className="ml-1 size-7 rounded-md" />
</div>
</header>
)
@@ -53,23 +52,25 @@ export function ChannelHeaderSkeleton({
export type ChannelNotifLevel = typeof USE_SERVER_DEFAULT | NotifLevel
export function ChannelHeader({
- channel, rightPanel, onToggle, notifLevel, onSetNotifLevel, onBack,
- breadcrumb, forum, server, tools,
+ channel, rightPanel, onToggle, notifLevel, onSetNotifLevel,
+ breadcrumb, forum, server, mobileServer, onBack, tools,
}: {
channel: string
rightPanel: RightPanel
onToggle: (k: Exclude<RightPanel, null>) => void
notifLevel?: ChannelNotifLevel
onSetNotifLevel?: (l: ChannelNotifLevel) => void
- onBack?: () => void
forum?: boolean
breadcrumb?: {
+ id?: string
label: string
onRename?: (name: string) => void | Promise<void>
titleRename?: boolean
- onNavigateBack?: () => void
+ onNavigate?: () => void
}
server?: { id: string; name: string; icon: string | null }
+ mobileServer?: { id: string; name: string; icon: string | null; onNavigate: () => void }
+ onBack?: () => void
tools?: { threads?: boolean; pinned?: boolean; members?: boolean }
}) {
@@ -90,18 +91,24 @@ export function ChannelHeader({
)
return (
<header role="banner" className="flex h-12 shrink-0 items-center gap-1 border-b border-border/40 px-3">
- {onBack && (
+ {onBack && !mobileServer && (
<Button variant="ghost" size="icon-sm" onClick={onBack} className="text-muted-foreground hover:text-foreground" aria-label="Back"><ChevronLeft className="size-5" /></Button>
)}
+ {mobileServer && <MobileServerCrumb id={mobileServer.id} name={mobileServer.name} icon={mobileServer.icon} onNavigate={mobileServer.onNavigate} />}
{server && <ServerCrumb id={server.id} name={server.name} icon={server.icon} size={6} className="ml-1" />}
{breadcrumb ? (
<>
- <button onClick={breadcrumb.onNavigateBack} className={`flex items-center gap-1 text-muted-foreground hover:text-foreground transition-colors ${server ? "" : "ml-1"}`}>
+ <button
+ type="button"
+ data-testid={breadcrumb.id ? tid.channelHeaderParent(breadcrumb.id) : undefined}
+ onClick={breadcrumb.onNavigate}
+ className={`flex min-w-0 max-w-24 items-center gap-1 text-muted-foreground transition-colors hover:text-foreground sm:max-w-none ${mobileServer ? "sm:ml-1" : server ? "" : "ml-1"}`}
+ >
<EntityIcon kind={entityKind} className="size-4 shrink-0" />
<span className="truncate text-base font-medium">{channel}</span>
</button>
<ChannelIcon className="shrink-0 text-base text-muted-foreground/60" />
- <span className="min-w-0 truncate text-base font-medium" title={breadcrumb.label}>
+ <span className="min-w-8 truncate text-base font-medium sm:min-w-0" title={breadcrumb.label}>
{breadcrumb.label}
</span>
{breadcrumb.onRename && (
@@ -110,7 +117,7 @@ export function ChannelHeader({
</>
) : (
<>
- <div className={`grid size-6 shrink-0 place-items-center rounded-md bg-muted text-muted-foreground ${server ? "" : "ml-1"}`}>
+ <div className={`grid size-6 shrink-0 place-items-center rounded-md bg-muted text-muted-foreground ${mobileServer ? "sm:ml-1" : server ? "" : "ml-1"}`}>
<EntityIcon kind={entityKind} className="size-4" />
</div>
<span className="truncate text-base font-semibold">{channel}</span>
@@ -181,13 +188,36 @@ function ChannelOverflowMenu({
// follows leads with its own "/" or forum icon, which serves as the
// separator). Tailwind only picks up complete literal class names at build
// time, so `size` can't be interpolated — it's an explicit ternary.
+function MobileServerCrumb({ id, name, icon, onNavigate }: {
+ id: string
+ name: string
+ icon: string | null
+ onNavigate: () => void
+}) {
+ return (
+ <button
+ type="button"
+ data-testid={tid.channelHeaderServer(id)}
+ onClick={onNavigate}
+ className="grid size-11 shrink-0 place-items-center rounded-md focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-none sm:hidden"
+ aria-label={`Go to server ${name}`}
+ title={name}
+ >
+ <span
+ className={`relative grid size-6 shrink-0 place-items-center overflow-hidden rounded-md ${icon ? "bg-secondary text-[0.6875rem] font-semibold text-foreground" : "font-brand text-sm font-bold text-white [text-shadow:0_1px_2px_rgb(0_0_0/0.35)]"}`}
+ >
+ {icon ? <img src={icon} alt="" className="size-full object-cover" /> : <><SeededBackdrop seed={id} /><span className="relative -translate-x-px [-webkit-text-stroke:0.5px_currentColor]">{avatarInitial(name)}</span></>}
+ </span>
+ </button>
+ )
+}
+
function ServerCrumb({ id, name, icon, size = 5, className = "" }: { id: string; name: string; icon: string | null; size?: 5 | 6 | 7; className?: string }) {
const sizeCls = size === 7 ? "size-7" : size === 6 ? "size-6" : "size-5"
const iconTextCls = size === 7 ? "text-xs" : size === 6 ? "text-[0.6875rem]" : "text-[0.625rem]"
const initialTextCls = size === 7 ? "text-base" : size === 6 ? "text-sm" : "text-xs"
return (
<span
- // The deterministic fallback matches the rail and folder rows.
className={`relative grid shrink-0 place-items-center overflow-hidden rounded-md ${icon ? `font-semibold ${iconTextCls} bg-secondary text-foreground` : `font-brand font-bold ${initialTextCls} text-white [text-shadow:0_1px_2px_rgb(0_0_0/0.35)]`} ${sizeCls} ${className}`}
aria-label={name}
title={name}
diff --git a/src/web/src/components/community/channels/channel-loading-frame.test.ts b/src/web/src/components/community/channels/channel-loading-frame.test.ts
index a9d32ad3c..ff0a85d91 100644
--- a/src/web/src/components/community/channels/channel-loading-frame.test.ts
+++ b/src/web/src/components/community/channels/channel-loading-frame.test.ts
@@ -16,17 +16,13 @@ vi.mock("@/components/community/messages/composer", () => ({
import { ChannelLoadingFrame } from "./channel-loading-frame"
describe("ChannelLoadingFrame", () => {
- it("composes canonical detail zones and converts a legacy Back handler to inert geometry", () => {
- const onBack = vi.fn()
+ it("composes canonical detail zones with server-leading loading geometry", () => {
let renderer!: TestRenderer.ReactTestRenderer
act(() => {
- renderer = TestRenderer.create(createElement(ChannelLoadingFrame, { onBack }))
+ renderer = TestRenderer.create(createElement(ChannelLoadingFrame))
})
- expect(renderer.root.findByType("channel-header-skeleton").props).toMatchObject({
- reserveBackSlot: true,
- })
- expect(renderer.root.findByType("channel-header-skeleton").props.onBack).toBeUndefined()
+ expect(renderer.root.findByType("channel-header-skeleton").props).toEqual({})
expect(renderer.root.findByType("message-list").props).toMatchObject({
channel: "",
messages: [],
@@ -40,15 +36,4 @@ describe("ChannelLoadingFrame", () => {
})
})
- it("reserves loading Back geometry without exposing an interactive handler", () => {
- let renderer!: TestRenderer.ReactTestRenderer
- act(() => {
- renderer = TestRenderer.create(createElement(ChannelLoadingFrame, { reserveBackSlot: true }))
- })
-
- expect(renderer.root.findByType("channel-header-skeleton").props).toMatchObject({
- reserveBackSlot: true,
- })
- expect(renderer.root.findByType("channel-header-skeleton").props.onBack).toBeUndefined()
- })
})
diff --git a/src/web/src/components/community/channels/channel-loading-frame.tsx b/src/web/src/components/community/channels/channel-loading-frame.tsx
index 1ef95f6d7..f67e12d1d 100644
--- a/src/web/src/components/community/channels/channel-loading-frame.tsx
+++ b/src/web/src/components/community/channels/channel-loading-frame.tsx
@@ -4,20 +4,14 @@ import { MessageList } from "@/components/community/messages/message-list"
import { ComposerSkeleton } from "@/components/community/messages/composer"
import { ChannelHeaderSkeleton } from "./channel-header"
-export function ChannelLoadingFrame({
- onBack,
- reserveBackSlot = false,
-}: {
- onBack?: () => void
- reserveBackSlot?: boolean
-}) {
+export function ChannelLoadingFrame() {
return (
<div
aria-busy="true"
aria-label="Loading conversation"
className="flex min-h-0 min-w-0 flex-1 flex-col"
>
- <ChannelHeaderSkeleton reserveBackSlot={reserveBackSlot || Boolean(onBack)} />
+ <ChannelHeaderSkeleton />
<main className="flex min-h-0 min-w-0 flex-1 flex-col">
<MessageList channel="" messages={[]} loading onOpenThread={() => {}} />
<ComposerSkeleton />
diff --git a/src/web/src/components/community/channels/channel-route.text-scroll-target.test.ts b/src/web/src/components/community/channels/channel-route.text-scroll-target.test.ts
index 0045b744d..ffbe7acf6 100644
--- a/src/web/src/components/community/channels/channel-route.text-scroll-target.test.ts
+++ b/src/web/src/components/community/channels/channel-route.text-scroll-target.test.ts
@@ -13,14 +13,16 @@ const {
mockRouter,
mockUiHandlers,
mockBreakpoint,
- mockHeaderBack,
+ mockHeaderServerNavigate,
+ mockHeaderParentNavigate,
mockOpenerGate,
mockSearchParams,
} = vi.hoisted(() => ({
mockRouter: { push: vi.fn(), replace: vi.fn(), back: vi.fn() },
mockUiHandlers: { replacePath: vi.fn(), goBackMobile: vi.fn() },
mockBreakpoint: { value: "desktop" as "desktop" | "mobile" },
- mockHeaderBack: { current: undefined as undefined | (() => void) },
+ mockHeaderServerNavigate: { current: undefined as undefined | (() => void) },
+ mockHeaderParentNavigate: { current: undefined as undefined | (() => void) },
mockOpenerGate: vi.fn(() => null),
mockSearchParams: { value: "msg=m_target&keep=1" },
mockRouteModel: {
@@ -70,8 +72,15 @@ vi.mock("@/hooks/community/thread-opener-read-handoff", () => ({
useThreadOpenerRouteGate: (...args: unknown[]) => mockOpenerGate(...args),
}))
vi.mock("@/components/community/channels/channel-header", () => ({
- ChannelHeader: ({ onBack }: { onBack?: () => void }) => {
- if (onBack) mockHeaderBack.current = onBack
+ ChannelHeader: ({
+ mobileServer,
+ breadcrumb,
+ }: {
+ mobileServer?: { onNavigate: () => void }
+ breadcrumb?: { onNavigate?: () => void }
+ }) => {
+ mockHeaderServerNavigate.current = mobileServer?.onNavigate
+ mockHeaderParentNavigate.current = breadcrumb?.onNavigate
return null
},
ChannelHeaderSkeleton: () => null,
@@ -245,7 +254,8 @@ describe("ChannelRoute message surface ownership", () => {
mockOpenerGate.mockClear()
mockSearchParams.value = "msg=m_target&keep=1"
mockBreakpoint.value = "desktop"
- mockHeaderBack.current = undefined
+ mockHeaderServerNavigate.current = undefined
+ mockHeaderParentNavigate.current = undefined
Object.assign(mockRouteModel, {
server: {
id: "server_1",
@@ -412,7 +422,7 @@ describe("ChannelRoute message surface ownership", () => {
)
})
- it("derives a mobile child Back destination from fetched parent metadata", () => {
+ it("replaces directly to the verified parent from the child crumb", () => {
configureThreadRoute()
mockBreakpoint.value = "mobile"
mockedUseChannelMessageFeed.mockImplementation(() => feed({ anchorInCache: true }))
@@ -422,7 +432,7 @@ describe("ChannelRoute message surface ownership", () => {
React.createElement(ChannelRoute, { serverParam: "server_1", channelId: "channel_1" }),
)
})
- act(() => mockHeaderBack.current?.())
+ act(() => mockHeaderParentNavigate.current?.())
expect(mockUiHandlers.replacePath).toHaveBeenCalledWith(
"/c/channels/server_1/parent_1",
@@ -430,7 +440,7 @@ describe("ChannelRoute message surface ownership", () => {
expect(mockUiHandlers.goBackMobile).not.toHaveBeenCalled()
})
- it("uses the shell mobile Back handler for a top-level channel", () => {
+ it("replaces directly to the canonical server root from a top-level channel", () => {
mockBreakpoint.value = "mobile"
mockedUseChannelMessageFeed.mockImplementation(() => feed())
@@ -439,10 +449,12 @@ describe("ChannelRoute message surface ownership", () => {
React.createElement(ChannelRoute, { serverParam: "server_1", channelId: "channel_1" }),
)
})
- act(() => mockHeaderBack.current?.())
+ act(() => mockHeaderServerNavigate.current?.())
- expect(mockUiHandlers.goBackMobile).toHaveBeenCalledOnce()
- expect(mockUiHandlers.replacePath).not.toHaveBeenCalled()
+ expect(mockUiHandlers.replacePath).toHaveBeenCalledWith(
+ "/c/channels/server_1",
+ )
+ expect(mockUiHandlers.goBackMobile).not.toHaveBeenCalled()
})
it("keeps a child target through warm cache and 5000ms until MessageList consumes it", () => {
diff --git a/src/web/src/components/community/channels/channel-route.tsx b/src/web/src/components/community/channels/channel-route.tsx
index ef181dc15..46aa09a0d 100644
--- a/src/web/src/components/community/channels/channel-route.tsx
+++ b/src/web/src/components/community/channels/channel-route.tsx
@@ -3,7 +3,6 @@
import { useCallback, useEffect, useMemo, useState } from "react"
import { useRouter, useSearchParams } from "next/navigation"
import { toastApiError } from "@/lib/api/client"
-import { useBreakpoint } from "@/hooks/use-mobile"
import { ChannelHeaderSkeleton, type ChannelNotifLevel } from "@/components/community/channels/channel-header"
import { MessageList } from "@/components/community/messages/message-list"
import { ComposerSkeleton } from "@/components/community/messages/composer"
@@ -27,7 +26,7 @@ import { useChannelRouteModel } from "@/hooks/community/use-channel-route-model"
import { useForumOpenerHint } from "@/hooks/community/use-forum-opener-hint"
import { useNotificationSettings } from "@/hooks/community/use-notification-settings"
import { useSetChannelNotif } from "@/hooks/community/mutations"
-import { channelHref, removeCommunityParam } from "@/lib/community/community-route"
+import { channelHref, removeCommunityParam, serverRootHref } from "@/lib/community/community-route"
import {
THREAD_OPENER_HANDOFF_PARAM,
useThreadOpenerRouteGate,
@@ -59,7 +58,6 @@ export function ChannelRoute({ serverParam, channelId }: {
// refresh/back doesn't re-trigger the jump; this frozen copy still drives the
// anchor + scroll for this mount.
const [jumpTargetId] = useState<string | null>(() => searchParams.get("msg"))
- const bp = useBreakpoint()
const currentUser = useCurrentUser()
const uiHandlers = useUiHandlers()
const currentChannelId = useCurrentChannelId()
@@ -127,14 +125,14 @@ export function ChannelRoute({ serverParam, channelId }: {
const channelNotif = notifs.channel
const { mutate: setChannelNotif } = useSetChannelNotif()
- const goBack = useCallback(() => {
+ const navigateServerRoot = useCallback(() => {
+ uiHandlers.replacePath?.(serverRootHref(serverParam))
+ }, [serverParam, uiHandlers])
+ const navigateParent = useCallback(() => {
const parentChannelId = currentChannelMeta?.parentChannelId
- if (isChildChannel && parentChannelId) {
- uiHandlers.replacePath?.(channelHref(serverParam, parentChannelId))
- return
- }
- uiHandlers.goBackMobile?.()
- }, [currentChannelMeta?.parentChannelId, isChildChannel, serverParam, uiHandlers])
+ if (!parentChannelId) return
+ uiHandlers.replacePath?.(channelHref(serverParam, parentChannelId))
+ }, [currentChannelMeta?.parentChannelId, serverParam, uiHandlers])
const setNotificationLevel = useCallback((level: ChannelNotifLevel) => {
setChannelNotif({ channelId, level }, {
onError: (error) => toastApiError(error, "Failed to update notification level"),
@@ -173,7 +171,7 @@ export function ChannelRoute({ serverParam, channelId }: {
if (isForum) {
return (
<>
- <ChannelHeaderSkeleton onBack={bp === "mobile" ? goBack : undefined} />
+ <ChannelHeaderSkeleton />
<main className="flex min-h-0 min-w-0 flex-1 flex-col">
<ForumViewSkeleton />
</main>
@@ -182,7 +180,7 @@ export function ChannelRoute({ serverParam, channelId }: {
}
return (
<>
- <ChannelHeaderSkeleton onBack={bp === "mobile" ? goBack : undefined} />
+ <ChannelHeaderSkeleton />
<main className="flex min-h-0 min-w-0 flex-1 flex-col">
{/*
`key={channelId}` MUST match the hydrated branches' key below —
@@ -220,12 +218,12 @@ export function ChannelRoute({ serverParam, channelId }: {
threadOpenerHandoff={threadOpenerHandoff}
childCreatorId={currentChannelMeta?.creatorId}
canRenameThread={canManageServer(myRole)}
- headerServer={bp === "mobile" && currentServer
- ? { id: currentServer.id, name: currentServer.name, icon: currentServer.icon }
+ headerServer={currentServer
+ ? { id: currentServer.id, name: currentServer.name, icon: currentServer.icon, onNavigate: navigateServerRoot }
: undefined}
+ onNavigateParent={navigateParent}
notificationLevel={(channelNotif[channelId] as ChannelNotifLevel) ?? USE_SERVER_DEFAULT}
onSetNotificationLevel={setNotificationLevel}
- onBack={bp === "mobile" ? goBack : undefined}
composerMembers={composerMembers}
composerMentionCandidates={composerMentionCandidates}
channelRefCandidates={channelRefCandidates}
@@ -248,12 +246,11 @@ export function ChannelRoute({ serverParam, channelId }: {
channelName={channelName}
viewer={currentUser}
viewerRole={myRole}
- headerServer={bp === "mobile" && currentServer
- ? { id: currentServer.id, name: currentServer.name, icon: currentServer.icon }
+ headerServer={currentServer
+ ? { id: currentServer.id, name: currentServer.name, icon: currentServer.icon, onNavigate: navigateServerRoot }
: undefined}
notificationLevel={(channelNotif[channelId] as ChannelNotifLevel) ?? USE_SERVER_DEFAULT}
onSetNotificationLevel={setNotificationLevel}
- onBack={bp === "mobile" ? goBack : undefined}
composerMembers={composerMembers}
composerMentionCandidates={composerMentionCandidates}
memberPanelProps={memberPanelProps}
@@ -273,12 +270,11 @@ export function ChannelRoute({ serverParam, channelId }: {
channelName={channelName}
viewer={currentUser}
anchorMessageId={jumpTargetId}
- headerServer={bp === "mobile" && currentServer
- ? { id: currentServer.id, name: currentServer.name, icon: currentServer.icon }
+ headerServer={currentServer
+ ? { id: currentServer.id, name: currentServer.name, icon: currentServer.icon, onNavigate: navigateServerRoot }
: undefined}
notificationLevel={(channelNotif[channelId] as ChannelNotifLevel) ?? USE_SERVER_DEFAULT}
onSetNotificationLevel={setNotificationLevel}
- onBack={bp === "mobile" ? goBack : undefined}
composerMembers={composerMembers}
composerMentionCandidates={composerMentionCandidates}
channelRefCandidates={channelRefCandidates}
diff --git a/src/web/src/components/community/channels/forum-channel-surface.test.ts b/src/web/src/components/community/channels/forum-channel-surface.test.ts
index 3f04eaa00..8e61e57bf 100644
--- a/src/web/src/components/community/channels/forum-channel-surface.test.ts
+++ b/src/web/src/components/community/channels/forum-channel-surface.test.ts
@@ -63,6 +63,12 @@ function surfaceProps(overrides: Record<string, unknown> = {}) {
channelName: "ideas",
viewer: { id: "viewer_1" },
viewerRole: "member" as const,
+ headerServer: {
+ id: "srv_1",
+ name: "Studio",
+ icon: null,
+ onNavigate: vi.fn(),
+ },
notificationLevel: "Use Server Default" as const,
onSetNotificationLevel: vi.fn(),
composerMembers: [],
@@ -92,6 +98,10 @@ describe("ForumChannelSurface ownership", () => {
})
expect(mocks.activeMessageFeed).not.toHaveBeenCalled()
+ expect(mockedChannelHeader.mock.calls.at(-1)![0]).toEqual(expect.objectContaining({
+ mobileServer: props.headerServer,
+ }))
+ expect(mockedChannelHeader.mock.calls.at(-1)![0]).not.toHaveProperty("onBack")
const forumProps = mockedForumSurface.mock.calls.at(-1)![0]
expect(forumProps).toEqual(expect.objectContaining({
forumChannelId: "forum_1",
diff --git a/src/web/src/components/community/channels/forum-channel-surface.tsx b/src/web/src/components/community/channels/forum-channel-surface.tsx
index 80925dec9..5b42133d1 100644
--- a/src/web/src/components/community/channels/forum-channel-surface.tsx
+++ b/src/web/src/components/community/channels/forum-channel-surface.tsx
@@ -28,7 +28,6 @@ export function ForumChannelSurface({
headerServer,
notificationLevel,
onSetNotificationLevel,
- onBack,
composerMembers,
composerMentionCandidates,
memberPanelProps,
@@ -41,10 +40,9 @@ export function ForumChannelSurface({
channelName: string
viewer: { id: string }
viewerRole: Role | undefined
- headerServer?: { id: string; name: string; icon: string | null }
+ headerServer?: { id: string; name: string; icon: string | null; onNavigate: () => void }
notificationLevel: ChannelNotifLevel
onSetNotificationLevel: (level: ChannelNotifLevel) => void
- onBack?: () => void
composerMembers: Member[]
composerMentionCandidates?: ComposerProps["mentionCandidates"]
memberPanelProps: ChannelMemberPanelProps
@@ -98,8 +96,7 @@ export function ForumChannelSurface({
onToggle={togglePanel}
notifLevel={notificationLevel}
onSetNotifLevel={onSetNotificationLevel}
- onBack={onBack}
- server={headerServer}
+ mobileServer={headerServer}
tools={{ threads: false, pinned: false }}
/>
)}
diff --git a/src/web/src/components/community/channels/text-channel-surface.test.ts b/src/web/src/components/community/channels/text-channel-surface.test.ts
index 5ca1accf2..6f0fdd2a9 100644
--- a/src/web/src/components/community/channels/text-channel-surface.test.ts
+++ b/src/web/src/components/community/channels/text-channel-surface.test.ts
@@ -3,7 +3,9 @@ import TestRenderer, { act } from "react-test-renderer"
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"
import { MessageChannelController } from "../messages/message-channel-controller"
import type { MessageChannelControllerValue } from "../messages/message-channel-controller"
-import type { useChannelMessageFeed } from "@/hooks/community/use-channel-message-feed"
+import { ChannelHeader } from "./channel-header"
+import { TextChannelSurface } from "./text-channel-surface"
+import { useChannelMessageFeed } from "@/hooks/community/use-channel-message-feed"
import { buildAttachmentUploadFormData } from "@/hooks/community/mutations/uploads"
import { useMessageStreamStore } from "@/stores/community/message-stream"
@@ -25,6 +27,29 @@ vi.mock("next/navigation", () => ({
}))
vi.mock("sonner", () => ({ toast: vi.fn() }))
vi.mock("@/lib/api/client", () => ({ apiFetch: vi.fn(), toastApiError: vi.fn() }))
+vi.mock("@/hooks/use-mobile", () => ({ useBreakpoint: () => "desktop" }))
+vi.mock("@/hooks/community/use-channel-message-feed", () => ({
+ useChannelMessageFeed: vi.fn(),
+}))
+vi.mock("@/components/community/channels/channel-header", () => ({
+ ChannelHeader: vi.fn(() => null),
+}))
+vi.mock("@/components/community/channels/channel-shell", () => ({
+ ChannelShell: ({ header, body }: { header: React.ReactNode; body: React.ReactNode }) =>
+ React.createElement(React.Fragment, null, header, body),
+}))
+vi.mock("@/components/community/messages/composer", () => ({
+ Composer: vi.fn(() => null),
+}))
+vi.mock("@/components/community/messages/message-list", () => ({
+ MessageList: vi.fn(() => null),
+}))
+vi.mock("@/components/community/shell/community-panel", () => ({
+ CommunityPanel: vi.fn(() => null),
+}))
+vi.mock("@/components/community/messages/message-context-sheet", () => ({
+ MessageContextSheet: vi.fn(() => null),
+}))
vi.mock("@alook/shared", () => ({
deriveThreadName: () => "thread",
MAX_ATTACHMENT_THUMBNAIL_SIZE_BYTES: 50 * 1024,
@@ -75,6 +100,9 @@ function feed(overrides: Record<string, unknown> = {}) {
} as ReturnType<typeof useChannelMessageFeed>
}
+const mockedChannelHeader = vi.mocked(ChannelHeader)
+const mockedUseChannelMessageFeed = vi.mocked(useChannelMessageFeed)
+
function renderController(
messageFeed: ReturnType<typeof useChannelMessageFeed>,
targetId = "m_target",
@@ -295,3 +323,46 @@ describe("MessageChannelController scroll target ownership", () => {
}
})
})
+
+describe("TextChannelSurface header hierarchy", () => {
+ afterEach(() => {
+ vi.clearAllMocks()
+ })
+
+ it("forwards the direct mobile server segment without a Back fallback", () => {
+ const headerServer = {
+ id: "server_1",
+ name: "Server",
+ icon: null,
+ onNavigate: vi.fn(),
+ }
+ mockedUseChannelMessageFeed.mockReturnValue(feed())
+
+ act(() => {
+ TestRenderer.create(React.createElement(TextChannelSurface, {
+ channelId: "channel_1",
+ serverId: "server_1",
+ serverParam: "server_1",
+ channelName: "general",
+ viewer: { id: "viewer_1", name: "Viewer", avatar: "V" },
+ anchorMessageId: null,
+ headerServer,
+ notificationLevel: "default",
+ onSetNotificationLevel: vi.fn(),
+ composerMembers: [],
+ composerMentionCandidates: undefined,
+ channelRefCandidates: [],
+ memberPanelProps: { members: [] },
+ manageMembersDialog: null,
+ uiHandlers: {},
+ onOpenThread: vi.fn(),
+ onOpenProfile: vi.fn(),
+ resolveUserName: (userId: string) => userId,
+ }))
+ })
+
+ const headerProps = mockedChannelHeader.mock.calls.at(-1)![0]
+ expect(headerProps.mobileServer).toBe(headerServer)
+ expect(headerProps).not.toHaveProperty("onBack")
+ })
+})
diff --git a/src/web/src/components/community/channels/text-channel-surface.tsx b/src/web/src/components/community/channels/text-channel-surface.tsx
index 7179c4378..447f73b88 100644
--- a/src/web/src/components/community/channels/text-channel-surface.tsx
+++ b/src/web/src/components/community/channels/text-channel-surface.tsx
@@ -28,7 +28,6 @@ export function TextChannelSurface({
headerServer,
notificationLevel,
onSetNotificationLevel,
- onBack,
composerMembers,
composerMentionCandidates,
channelRefCandidates,
@@ -45,10 +44,9 @@ export function TextChannelSurface({
channelName: string
viewer: { id: string; name: string; avatar: string }
anchorMessageId: string | null
- headerServer?: { id: string; name: string; icon: string | null }
+ headerServer?: { id: string; name: string; icon: string | null; onNavigate: () => void }
notificationLevel: ChannelNotifLevel
onSetNotificationLevel: (level: ChannelNotifLevel) => void
- onBack?: () => void
composerMembers: ComponentProps<typeof Composer>["members"]
composerMentionCandidates: ComponentProps<typeof Composer>["mentionCandidates"]
channelRefCandidates: ComponentProps<typeof Composer>["channelRefCandidates"]
@@ -103,8 +101,7 @@ export function TextChannelSurface({
onToggle={togglePanel}
notifLevel={notificationLevel}
onSetNotifLevel={onSetNotificationLevel}
- onBack={onBack}
- server={headerServer}
+ mobileServer={headerServer}
/>
)}
body={(
diff --git a/src/web/src/components/community/channels/thread-channel-surface.test.ts b/src/web/src/components/community/channels/thread-channel-surface.test.ts
index fa3422e1f..14e7c08f1 100644
--- a/src/web/src/components/community/channels/thread-channel-surface.test.ts
+++ b/src/web/src/components/community/channels/thread-channel-surface.test.ts
@@ -176,9 +176,15 @@ function surfaceProps(overrides: Record<string, unknown> = {}) {
parentIsForum: false,
childCreatorId: "viewer_1",
canRenameThread: true,
+ headerServer: {
+ id: "server_1",
+ name: "Server",
+ icon: null,
+ onNavigate: vi.fn(),
+ },
+ onNavigateParent: vi.fn(),
notificationLevel: "default" as const,
onSetNotificationLevel: vi.fn(),
- onBack: vi.fn(),
composerMembers: [{ id: "member_1", userId: "member_1", name: "Alice" }],
composerMentionCandidates: undefined,
channelRefCandidates: [{ id: "parent_1", name: "general", serverId: "server_1", serverName: "Server", serverDiscriminator: "0001" }],
@@ -293,23 +299,25 @@ describe("ThreadChannelSurface ownership", () => {
expect(mocks.setReplyTo).toHaveBeenCalledWith(null)
})
- it("uses the same mobile Back handler while loading and after hydration", () => {
- const onBack = vi.fn()
+ it("keeps loading inert and restores direct hierarchy controls on body error", () => {
+ const props = surfaceProps()
mockedUseChannelMessageFeed.mockReturnValue(feed({ isLoading: true }))
let renderer!: TestRenderer.ReactTestRenderer
act(() => {
- renderer = TestRenderer.create(renderSurface({ onBack }))
+ renderer = TestRenderer.create(React.createElement(ThreadChannelSurface, props))
})
- const loadingBack = mockedChannelHeaderSkeleton.mock.calls.at(-1)![0].onBack
- expect(loadingBack).toBe(onBack)
- act(() => loadingBack?.())
+ expect(mockedChannelHeaderSkeleton.mock.calls.at(-1)![0]).not.toHaveProperty("onBack")
+ expect(mockedChannelHeader).not.toHaveBeenCalled()
- mockedUseChannelMessageFeed.mockReturnValue(feed({ isLoading: false }))
- act(() => renderer.update(renderSurface({ onBack })))
- const hydratedBack = mockedChannelHeader.mock.calls.at(-1)![0].onBack
- expect(hydratedBack).toBe(onBack)
- act(() => hydratedBack?.())
- expect(onBack).toHaveBeenCalledTimes(2)
+ mockedUseChannelMessageFeed.mockReturnValue(feed({ isLoading: false, isError: true }))
+ act(() => renderer.update(React.createElement(ThreadChannelSurface, props)))
+ const headerProps = mockedChannelHeader.mock.calls.at(-1)![0]
+ expect(headerProps).not.toHaveProperty("onBack")
+ expect(headerProps.mobileServer).toBe(props.headerServer)
+ expect(headerProps.breadcrumb).toEqual(expect.objectContaining({
+ id: "parent_1",
+ onNavigate: props.onNavigateParent,
+ }))
})
it("preserves regular-thread breadcrumb, rename, panel, and dialog wiring", async () => {
@@ -324,11 +332,14 @@ describe("ThreadChannelSurface ownership", () => {
expect(headerProps).toEqual(expect.objectContaining({
notifLevel: "default",
onSetNotifLevel: props.onSetNotificationLevel,
- onBack: props.onBack,
+ mobileServer: props.headerServer,
}))
+ expect(headerProps).not.toHaveProperty("onBack")
expect(headerProps.breadcrumb).toEqual(expect.objectContaining({
+ id: "parent_1",
label: "Thread name",
titleRename: false,
+ onNavigate: props.onNavigateParent,
onRename: expect.any(Function),
}))
@@ -341,8 +352,8 @@ describe("ThreadChannelSurface ownership", () => {
})
headerProps = mockedChannelHeader.mock.calls.at(-1)![0]
expect(headerProps.breadcrumb?.label).toBe("Renamed thread")
- act(() => headerProps.breadcrumb?.onNavigateBack())
- expect(mocks.router.replace).toHaveBeenCalledWith("/c/channels/server_1/parent_1")
+ act(() => headerProps.breadcrumb?.onNavigate?.())
+ expect(props.onNavigateParent).toHaveBeenCalledOnce()
act(() => headerProps.onToggle("pinned"))
const panelProps = mockedCommunityPanel.mock.calls.at(-1)![0]
diff --git a/src/web/src/components/community/channels/thread-channel-surface.tsx b/src/web/src/components/community/channels/thread-channel-surface.tsx
index 1170d85c5..38461b4e6 100644
--- a/src/web/src/components/community/channels/thread-channel-surface.tsx
+++ b/src/web/src/components/community/channels/thread-channel-surface.tsx
@@ -41,9 +41,9 @@ export function ThreadChannelSurface({
childCreatorId,
canRenameThread,
headerServer,
+ onNavigateParent,
notificationLevel,
onSetNotificationLevel,
- onBack,
composerMembers,
composerMentionCandidates,
channelRefCandidates,
@@ -67,10 +67,10 @@ export function ThreadChannelSurface({
threadOpenerHandoff?: ThreadOpenerReadHandoff | null
childCreatorId?: string | null
canRenameThread: boolean
- headerServer?: { id: string; name: string; icon: string | null }
+ headerServer?: { id: string; name: string; icon: string | null; onNavigate: () => void }
+ onNavigateParent: () => void
notificationLevel: ChannelNotifLevel
onSetNotificationLevel: (level: ChannelNotifLevel) => void
- onBack?: () => void
composerMembers: ComponentProps<typeof Composer>["members"]
composerMentionCandidates: ComponentProps<typeof Composer>["mentionCandidates"]
channelRefCandidates: ComponentProps<typeof Composer>["channelRefCandidates"]
@@ -109,13 +109,6 @@ export function ThreadChannelSurface({
setRightPanel((current) => current === panel ? null : panel)
}, [])
const openPinned = useCallback(() => setRightPanel("pinned"), [])
- const navigateBack = useCallback(() => {
- if (parentChannelId) {
- router.replace(`/c/channels/${serverParam}/${parentChannelId}`)
- return
- }
- onBack?.()
- }, [onBack, parentChannelId, router, serverParam])
const rename = parentIsForum && parentChannelId && parentMessageId && childCreatorId === viewer.id
? async (name: string) => {
try {
@@ -150,7 +143,7 @@ export function ThreadChannelSurface({
if (feed.isLoading) {
return (
<>
- <ChannelHeaderSkeleton onBack={onBack} />
+ <ChannelHeaderSkeleton />
<main className="flex min-h-0 min-w-0 flex-1 flex-col">
<MessageList key={channelId} channel="" messages={[]} loading onOpenThread={ignoreNestedThread} />
<ComposerSkeleton />
@@ -203,15 +196,15 @@ export function ThreadChannelSurface({
onToggle={togglePanel}
notifLevel={notificationLevel}
onSetNotifLevel={onSetNotificationLevel}
- onBack={onBack}
- server={headerServer}
+ mobileServer={headerServer}
tools={{ threads: false }}
- breadcrumb={{
+ breadcrumb={parentChannelId ? {
+ id: parentChannelId,
label: displayName,
titleRename: parentIsForum,
- onNavigateBack: navigateBack,
+ onNavigate: onNavigateParent,
onRename: rename,
- }}
+ } : undefined}
/>
)}
body={(
diff --git a/src/web/src/components/community/shell/community-pending-frame.test.ts b/src/web/src/components/community/shell/community-pending-frame.test.ts
index fe4749856..071c06513 100644
--- a/src/web/src/components/community/shell/community-pending-frame.test.ts
+++ b/src/web/src/components/community/shell/community-pending-frame.test.ts
@@ -54,7 +54,7 @@ describe("CommunityPendingFrame", () => {
expect(friends.root.findByType("friends-skeleton").props.onBack).toBeUndefined()
})
- it("separates the neutral Me root, DM, and channel fallbacks", () => {
+ it("separates neutral Me, DM Back geometry, and server-leading channel geometry", () => {
const root = render("/c/me")
expect(root.root.findByProps({ "aria-label": "Loading your space" }).props["aria-busy"]).toBe("true")
@@ -62,7 +62,9 @@ describe("CommunityPendingFrame", () => {
expect(dm.root.findByType("dm-skeleton").props.reserveBackSlot).toBe(true)
const channel = render("/c/channels/s1/c1")
- expect(channel.root.findByType("channel-skeleton").props.reserveBackSlot).toBe(true)
- expect(channel.root.findByType("channel-skeleton").props.onBack).toBeUndefined()
+ expect(channel.root.findByType("channel-skeleton").props).toEqual({})
+
+ const serverRoot = render("/c/channels/s1")
+ expect(serverRoot.root.findByType("channel-skeleton").props).toEqual({})
})
})
diff --git a/src/web/src/components/community/shell/community-pending-frame.tsx b/src/web/src/components/community/shell/community-pending-frame.tsx
index dbf5d0be0..f5a91d545 100644
--- a/src/web/src/components/community/shell/community-pending-frame.tsx
+++ b/src/web/src/components/community/shell/community-pending-frame.tsx
@@ -42,5 +42,5 @@ export function CommunityPendingFrame({
if (/^\/c\/me\/[^/]+$/.test(pathname)) {
return <DmLoadingFrame reserveBackSlot={reserveBackSlot} />
}
- return <ChannelLoadingFrame reserveBackSlot={reserveBackSlot} />
+ return <ChannelLoadingFrame />
}
diff --git a/src/web/src/lib/community/testids.ts b/src/web/src/lib/community/testids.ts
index 5865a1b7a..9ff9ed922 100644
--- a/src/web/src/lib/community/testids.ts
+++ b/src/web/src/lib/community/testids.ts
@@ -25,6 +25,9 @@ export const tid = {
serverRailMoveConfirm: "community-server-rail-move-confirm",
channelSidebarScroll: "community-channel-sidebar-scroll",
channelSidebarPending: (serverId: string) => `community-channel-sidebar-pending-${serverId}`,
+ channelHeaderServer: (serverId: string) => `community-channel-header-server-${serverId}`,
+ channelHeaderParent: (channelId: string) => `community-channel-header-parent-${channelId}`,
+ channelHeaderServerLoading: "community-channel-header-server-loading",
dmSidebarPending: "community-dm-sidebar-pending",
createServerSubmit: "community-create-server-submit",
createServerName: "community-create-server-name",
diff --git a/src/web/src/test/e2e-ui/08-mobile.spec.ts b/src/web/src/test/e2e-ui/08-mobile.spec.ts
index f1ed08996..19fabc2d9 100644
--- a/src/web/src/test/e2e-ui/08-mobile.spec.ts
+++ b/src/web/src/test/e2e-ui/08-mobile.spec.ts
@@ -11,7 +11,8 @@ import {
} from "./_fixtures/seed"
// Journey 8 — adaptive list/detail routing. At <640px semantic roots render
-// lists and leaf paths render detail. Header Back replaces with the parent.
+// lists and leaf paths render detail. Server and verified-parent header crumbs
+// replace directly to their canonical hierarchy targets; DM keeps Header Back.
test.use({ viewport: { width: 390, height: 844 } })
const shellGroup = (page: Page) => page.locator('[data-slot="resizable-panel-group"]')
@@ -112,17 +113,28 @@ test.describe.serial("mobile layout", () => {
}
})
- test("a direct channel opens detail and Header Back replaces it with the server root", async ({ asUser }) => {
+ test("a direct channel opens detail and its server crumb replaces to the server root", async ({ asUser }) => {
const { page } = await asUser("alice")
await page.goto(`/c/channels/${serverId}/${channelId}`)
await page.waitForURL(new RegExp(channelId), { timeout: 20_000 , waitUntil: "commit" })
await expect(page.getByTestId(tid.composerInput)).toBeVisible()
- const back = page.getByRole("button", { name: "Back" })
- await expect(back).toBeVisible()
+ const serverCrumb = page.getByTestId(tid.channelHeaderServer(serverId))
+ await expect(serverCrumb).toBeVisible()
+ await expect(page.getByRole("button", { name: "Back" })).toHaveCount(0)
+ const [controlBox, visualBox] = await Promise.all([
+ serverCrumb.boundingBox(),
+ serverCrumb.locator(":scope > span").boundingBox(),
+ ])
+ expect(controlBox).not.toBeNull()
+ expect(visualBox).not.toBeNull()
+ expect(controlBox!.width).toBe(44)
+ expect(controlBox!.height).toBe(44)
+ expect(visualBox!.width).toBe(24)
+ expect(visualBox!.height).toBe(24)
const historyLength = await page.evaluate(() => history.length)
- await back.click()
+ await serverCrumb.click()
await expect.poll(() => new URL(page.url()).pathname).toBe(`/c/channels/${serverId}`)
expect(new URL(page.url()).searchParams.has("pane")).toBe(false)
await expect(page.getByTestId(tid.serverIcon(serverId))).toBeVisible()
@@ -196,19 +208,29 @@ test.describe.serial("mobile layout", () => {
await expect(page.getByRole("dialog").getByText("mobile child seq target")).toBeVisible()
})
- test("a flat child derives Header Back from parent metadata", async ({ asUser }) => {
+ test("a flat child exposes direct parent and server hierarchy controls", async ({ asUser }) => {
const { page } = await asUser("alice")
await page.goto(`/c/channels/${serverId}/${childChannelId}`)
- await expect(
- page.getByRole("banner").getByText("mobile-child", { exact: true }),
- ).toBeVisible()
+ const current = page.getByRole("banner").getByText("mobile-child", { exact: true })
+ await expect(current).toBeVisible()
+ expect(await current.evaluate((element) => element.tagName)).toBe("SPAN")
+ await expect(page.getByRole("button", { name: "Back" })).toHaveCount(0)
const historyLength = await page.evaluate(() => history.length)
- await page.getByRole("button", { name: "Back" }).click()
+ await page.getByTestId(tid.channelHeaderParent(channelId)).click()
await expect.poll(() => new URL(page.url()).pathname).toBe(
`/c/channels/${serverId}/${channelId}`,
)
expect(await page.evaluate(() => history.length)).toBe(historyLength)
+
+ await page.goto(`/c/channels/${serverId}/${childChannelId}`)
+ await expect(current).toBeVisible()
+ const serverHistoryLength = await page.evaluate(() => history.length)
+ await page.getByTestId(tid.channelHeaderServer(serverId)).click()
+ await expect.poll(() => new URL(page.url()).pathname).toBe(
+ `/c/channels/${serverId}`,
+ )
+ expect(await page.evaluate(() => history.length)).toBe(serverHistoryLength)
})
test("Marked opens a child message on its canonical route without losing context", async ({ asUser }) => {
@@ -330,7 +352,7 @@ test.describe.serial("mobile layout", () => {
const { page } = await asUser("alice")
await page.goto(`/c/channels/${serverId}/${channelId}`)
await expect(page.getByTestId(tid.composerInput)).toBeVisible()
- await page.getByRole("button", { name: "Back" }).click()
+ await page.getByTestId(tid.channelHeaderServer(serverId)).click()
await expect.poll(() => new URL(page.url()).pathname).toBe(`/c/channels/${serverId}`)
await expect(page.getByTestId(tid.channelRow(channelId))).toBeVisible()
diff --git a/src/web/src/test/e2e-ui/36-server-switch-pending-checkpoint.spec.ts b/src/web/src/test/e2e-ui/36-server-switch-pending-checkpoint.spec.ts
index aa9757319..34426f48b 100644
--- a/src/web/src/test/e2e-ui/36-server-switch-pending-checkpoint.spec.ts
+++ b/src/web/src/test/e2e-ui/36-server-switch-pending-checkpoint.spec.ts
@@ -177,7 +177,7 @@ test("server switching exposes one target-scoped cold checkpoint and skips it wh
await expectActiveServer(page, serverA, serverC)
await page.setViewportSize({ width: 390, height: 844 })
- await page.getByRole("button", { name: "Back" }).click()
+ await page.getByTestId(tid.channelHeaderServer(serverA)).click()
await expect.poll(() => new URL(page.url()).pathname === `/c/channels/${serverA}`)
.toBe(true)
await expect(page.getByTestId(tid.serverIcon(serverD))).toBeVisible()
diff --git a/src/web/src/test/e2e-ui/37-server-rail-pdd.spec.ts b/src/web/src/test/e2e-ui/37-server-rail-pdd.spec.ts
index 679987ae8..d62ced4bb 100644
--- a/src/web/src/test/e2e-ui/37-server-rail-pdd.spec.ts
+++ b/src/web/src/test/e2e-ui/37-server-rail-pdd.spec.ts
@@ -118,7 +118,7 @@ test("server rail commits one PDD drop and exposes mobile Move parity", async ({
await expect.poll(() => railRequests[0]?.status).toBe(200)
await page.setViewportSize({ width: 390, height: 844 })
- await page.getByRole("button", { name: "Back" }).click()
+ await page.getByTestId(tid.channelHeaderServer(first)).click()
await expect.poll(() => new URL(page.url()).pathname).toBe(`/c/channels/${first}`)
const rail = page.getByTestId(tid.serverRailScroll)
await rail.evaluate((element) => { element.scrollTop = element.scrollHeight })
diff --git a/src/web/src/test/e2e-ui/38-community-navigation-checkpoint-matrix.spec.ts b/src/web/src/test/e2e-ui/38-community-navigation-checkpoint-matrix.spec.ts
index a1002bbf1..11441770e 100644
--- a/src/web/src/test/e2e-ui/38-community-navigation-checkpoint-matrix.spec.ts
+++ b/src/web/src/test/e2e-ui/38-community-navigation-checkpoint-matrix.spec.ts
@@ -64,7 +64,7 @@ test("community checkpoint waits for layout-owned frame commits", async ({ asUse
await page.setViewportSize({ width: 390, height: 844 })
const rootGate = await holdRoute(page, `/c/channels/${serverId}`)
- await page.getByRole("button", { name: "Back" }).click({ noWaitAfter: true })
+ await page.getByTestId(tid.channelHeaderServer(serverId)).click({ noWaitAfter: true })
await expect.poll(rootGate.held).toBeGreaterThan(0)
await page.setViewportSize({ width: 1280, height: 900 })
await expect(page.getByLabel("Loading conversation")).toBeVisible()
diff --git a/src/web/src/test/e2e-ui/40-mobile-server-header-hierarchy.spec.ts b/src/web/src/test/e2e-ui/40-mobile-server-header-hierarchy.spec.ts
new file mode 100644
index 000000000..9e8484660
--- /dev/null
+++ b/src/web/src/test/e2e-ui/40-mobile-server-header-hierarchy.spec.ts
@@ -0,0 +1,133 @@
+import type { Page } from "@playwright/test"
+import { test, expect } from "./_fixtures/community-fixture"
+import {
+ seedChannel,
+ seedForumThread,
+ seedMessage,
+ seedServer,
+ seedThread,
+} from "./_fixtures/seed"
+import { tid } from "./_fixtures/testids"
+
+test.use({ viewport: { width: 390, height: 844 } })
+
+async function expectServerControl(page: Page, serverId: string) {
+ const control = page.getByTestId(tid.channelHeaderServer(serverId))
+ await expect(control).toBeVisible()
+ await expect(page.getByRole("button", { name: "Back" })).toHaveCount(0)
+ const [controlBox, visualBox] = await Promise.all([
+ control.boundingBox(),
+ control.locator(":scope > span").boundingBox(),
+ ])
+ expect(controlBox).toMatchObject({ width: 44, height: 44 })
+ expect(visualBox).toMatchObject({ width: 24, height: 24 })
+ return control
+}
+
+test.describe.serial("mobile server header direct hierarchy", () => {
+ let serverId: string
+ let textId: string
+ let forumId: string
+ let threadId: string
+ let postId: string
+
+ test.beforeAll(async () => {
+ const stamp = Date.now()
+ serverId = await seedServer("alice", `header-hierarchy-${stamp}`)
+ textId = await seedChannel("alice", serverId, `text-${stamp}`)
+ forumId = await seedChannel("alice", serverId, `forum-${stamp}`, "forum")
+ const openerId = await seedMessage("alice", textId, `thread opener ${stamp}`)
+ threadId = await seedThread("alice", openerId, `thread-${stamp}`)
+ postId = await seedForumThread("alice", forumId, `post-${stamp}`, "post body")
+ })
+
+ test("top-level text and forum replace directly to the canonical server root", async ({ asUser }) => {
+ const { page } = await asUser("alice")
+ for (const channelId of [textId, forumId]) {
+ await page.goto(`/c/channels/${serverId}/${channelId}`, { waitUntil: "commit" })
+ const control = await expectServerControl(page, serverId)
+ const historyLength = await page.evaluate(() => history.length)
+ await control.click()
+ await expect.poll(() => new URL(page.url()).pathname).toBe(`/c/channels/${serverId}`)
+ expect(await page.evaluate(() => history.length)).toBe(historyLength)
+ }
+ })
+
+ test("thread and forum post expose direct parent, direct root, and inert current labels", async ({ asUser }) => {
+ const { page } = await asUser("alice")
+ for (const child of [
+ { id: threadId, parentId: textId },
+ { id: postId, parentId: forumId },
+ ]) {
+ await page.goto(`/c/channels/${serverId}/${child.id}`, { waitUntil: "commit" })
+ await expectServerControl(page, serverId)
+ const parent = page.getByTestId(tid.channelHeaderParent(child.parentId))
+ await expect(parent).toBeVisible()
+ const current = page.getByRole("banner").locator("span[title]").first()
+ await expect(current).toBeVisible()
+ expect(await current.evaluate((element) => element.tagName)).toBe("SPAN")
+
+ const parentHistoryLength = await page.evaluate(() => history.length)
+ await parent.click()
+ await expect.poll(() => new URL(page.url()).pathname).toBe(
+ `/c/channels/${serverId}/${child.parentId}`,
+ )
+ expect(await page.evaluate(() => history.length)).toBe(parentHistoryLength)
+
+ await page.goto(`/c/channels/${serverId}/${child.id}`, { waitUntil: "commit" })
+ const rootHistoryLength = await page.evaluate(() => history.length)
+ await page.getByTestId(tid.channelHeaderServer(serverId)).click()
+ await expect.poll(() => new URL(page.url()).pathname).toBe(`/c/channels/${serverId}`)
+ expect(await page.evaluate(() => history.length)).toBe(rootHistoryLength)
+ }
+ })
+
+ test("639↔640 preserves the header and composer owners without resize requests", async ({ asUser }) => {
+ const { page } = await asUser("alice")
+ await page.setViewportSize({ width: 639, height: 844 })
+ await page.goto(`/c/channels/${serverId}/${threadId}`, { waitUntil: "commit" })
+ await expect(page.getByTestId(tid.composerInput)).toBeVisible({ timeout: 20_000 })
+ await expectServerControl(page, serverId)
+ await page.waitForTimeout(200)
+
+ await page.evaluate(({ composerTestId, serverTestId }) => {
+ const serverControl = document.querySelector(`[data-testid="${serverTestId}"]`)
+ Reflect.set(window, "__headerHierarchyBanner", serverControl?.closest("header[role=banner]"))
+ Reflect.set(window, "__headerHierarchyComposer", document.querySelector(`[data-testid="${composerTestId}"]`))
+ }, {
+ composerTestId: tid.channelComposerShell,
+ serverTestId: tid.channelHeaderServer(serverId),
+ })
+ let communityRequests = 0
+ let newSockets = 0
+ page.on("request", (request) => {
+ if (new URL(request.url()).pathname.startsWith("/api/community/")) communityRequests += 1
+ })
+ page.on("websocket", () => { newSockets += 1 })
+ const pathname = new URL(page.url()).pathname
+
+ await page.setViewportSize({ width: 640, height: 844 })
+ await expect(page.getByTestId(tid.channelHeaderServer(serverId))).toBeHidden()
+ await expect(page.getByTestId(tid.channelComposerShell)).toBeVisible()
+ expect(await page.evaluate(({ composerTestId, serverTestId }) => ({
+ banner: Reflect.get(window, "__headerHierarchyBanner") === document.querySelector(`[data-testid="${serverTestId}"]`)?.closest("header[role=banner]"),
+ composer: Reflect.get(window, "__headerHierarchyComposer") === document.querySelector(`[data-testid="${composerTestId}"]`),
+ }), {
+ composerTestId: tid.channelComposerShell,
+ serverTestId: tid.channelHeaderServer(serverId),
+ })).toEqual({ banner: true, composer: true })
+
+ await page.setViewportSize({ width: 639, height: 844 })
+ await expect(page.getByTestId(tid.channelHeaderServer(serverId))).toBeVisible()
+ expect(await page.evaluate(({ composerTestId, serverTestId }) => ({
+ banner: Reflect.get(window, "__headerHierarchyBanner") === document.querySelector(`[data-testid="${serverTestId}"]`)?.closest("header[role=banner]"),
+ composer: Reflect.get(window, "__headerHierarchyComposer") === document.querySelector(`[data-testid="${composerTestId}"]`),
+ }), {
+ composerTestId: tid.channelComposerShell,
+ serverTestId: tid.channelHeaderServer(serverId),
+ })).toEqual({ banner: true, composer: true })
+ expect(new URL(page.url()).pathname).toBe(pathname)
+ expect(communityRequests).toBe(0)
+ expect(newSockets).toBe(0)
+ })
+})
diff --git a/src/web/src/test/e2e-ui/40-server-rail-unread.spec.ts b/src/web/src/test/e2e-ui/40-server-rail-unread.spec.ts
index ab67860e8..73cedaacb 100644
--- a/src/web/src/test/e2e-ui/40-server-rail-unread.spec.ts
+++ b/src/web/src/test/e2e-ui/40-server-rail-unread.spec.ts
@@ -95,7 +95,8 @@ test("server unread owns exact rail geometry, folder aggregation, read clear, an
await expectIndicatorHeight(folderIndicator, 0)
await page.setViewportSize({ width: 390, height: 844 })
- await page.getByRole("button", { name: "Back" }).click()
+ await expect(page.getByRole("button", { name: "Back" })).toHaveCount(0)
+ await page.getByTestId(tid.channelHeaderServer(foregroundServer)).click()
await expect.poll(() => new URL(page.url()).pathname).toBe(`/c/channels/${foregroundServer}`)
if (await backgroundIcon.count() === 0) {
await folder.click()