Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

feat(web): add route-owned community loading frames (#615)

Gener34f6dc2c8e53
diff --git a/scripts/ci/e2e-shards.mjs b/scripts/ci/e2e-shards.mjs
index 1ed17a347..1d2cac942 100644
--- a/scripts/ci/e2e-shards.mjs
+++ b/scripts/ci/e2e-shards.mjs
@@ -52,6 +52,7 @@ export const SPEC_SECONDS = {
"39-mobile-composer-send.spec.ts": 45,
"40-mobile-server-header-hierarchy.spec.ts": 28,
"40-server-rail-unread.spec.ts": 60,
+ "41-community-initial-load-module-skeletons.spec.ts": 30,
}
function walk(directory) {
diff --git a/scripts/ci/e2e-shards.test.ts b/scripts/ci/e2e-shards.test.ts
index 2cb558908..97461529e 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([341, 341, 344, 344, 345])
+ expect(totals.sort((left, right) => left - right)).toEqual([347, 348, 349, 349, 352])
expect(Math.max(...totals) / Math.min(...totals)).toBeLessThanOrEqual(1.15)
})
diff --git a/src/web/src/app/c/layout.test.ts b/src/web/src/app/c/layout.test.ts
index 7a521144b..02cea2b24 100644
--- a/src/web/src/app/c/layout.test.ts
+++ b/src/web/src/app/c/layout.test.ts
@@ -19,7 +19,7 @@ vi.mock("./community-shell", () => ({
CommunityShell: (props: Record<string, unknown>) => createElement("community-shell", props),
}))
vi.mock("@/components/community/shell/community-session-pending-frame", () => ({
- CommunitySessionPendingFrame: () => createElement("session-pending"),
+ CommunitySessionPendingFrame: (props: Record<string, unknown>) => createElement("session-pending", props),
}))
vi.mock("@/components/signup-tracker", () => ({
SignupTracker: (props: Record<string, unknown>) => createElement("signup-tracker", props),
@@ -44,7 +44,7 @@ describe("CommunityLayout session boundary", () => {
it("keeps a stable frame while identity is pending", () => {
const renderer = render()
- expect(renderer.root.findAllByType("session-pending")).toHaveLength(1)
+ expect(renderer.root.findByType("session-pending").props.pathname).toBe("/c/me")
expect(renderer.root.findAllByType("community-shell")).toHaveLength(0)
})
@@ -52,7 +52,7 @@ describe("CommunityLayout session boundary", () => {
mocks.session = { data: null, isPending: false }
const renderer = render()
expect(mocks.replace).toHaveBeenCalledWith("/sign-in")
- expect(renderer.root.findAllByType("session-pending")).toHaveLength(1)
+ expect(renderer.root.findByType("session-pending").props.pathname).toBe("/c/me")
})
it("constructs the shell only after identity is available", () => {
@@ -74,6 +74,15 @@ describe("CommunityLayout session boundary", () => {
expect(mocks.replace).not.toHaveBeenCalled()
})
+ it("does not broaden the public bypass to malformed invite descendants", () => {
+ mocks.pathname = "/c/invite/token/extra"
+ const renderer = render()
+ expect(renderer.root.findByType("session-pending").props.pathname).toBe(
+ "/c/invite/token/extra",
+ )
+ expect(renderer.root.findAllByType("child")).toHaveLength(0)
+ })
+
it("wires the Me verifier to canonical fetch-in-flight state", () => {
const source = readFileSync(new URL("./me/layout.tsx", import.meta.url), "utf8")
expect(source).toMatch(/isPending:\s*dmsPending/)
diff --git a/src/web/src/app/c/layout.tsx b/src/web/src/app/c/layout.tsx
index 39bd2d5a1..4f687e3cc 100644
--- a/src/web/src/app/c/layout.tsx
+++ b/src/web/src/app/c/layout.tsx
@@ -7,15 +7,16 @@ import { CommunityShell } from "./community-shell"
import { avatarInitial } from "@/lib/community/avatar"
import { SignupTracker } from "@/components/signup-tracker"
import { CommunitySessionPendingFrame } from "@/components/community/shell/community-session-pending-frame"
+import { resolveCommunityModulePlan } from "@/lib/community/community-route"
// The invite landing page is preview-first: a logged-out visitor must be able
// to see it (and only hit the login wall on Join). It's a standalone
// full-screen page that doesn't use CommunityShell (which requires a
// logged-in user), so it's exempt from this layout's session gate AND the
-// shell — its own middleware exemption keeps the server side public. Mirrors
-// the `PUBLIC_PREFIXES` guard in `middleware.ts`; both gates must agree.
+// shell — its own middleware exemption keeps the server side public. Keep the
+// client bypass exact so malformed invite descendants do not inherit it.
function isPublicCommunityPath(pathname: string): boolean {
- return pathname.startsWith("/c/invite/")
+ return resolveCommunityModulePlan(pathname).route === "public-invite"
}
export default function CommunityLayout({
@@ -38,7 +39,7 @@ export default function CommunityLayout({
// gate, no CommunityShell (a logged-out visitor has no currentUser).
if (isPublic) return <><SignupTracker />{children}</>
- if (isPending || !session) return <CommunitySessionPendingFrame />
+ if (isPending || !session) return <CommunitySessionPendingFrame pathname={pathname} />
const currentUser = {
id: session.user.id,
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 071c06513..bcac55318 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
@@ -65,6 +65,15 @@ describe("CommunityPendingFrame", () => {
expect(channel.root.findByType("channel-skeleton").props).toEqual({})
const serverRoot = render("/c/channels/s1")
- expect(serverRoot.root.findByType("channel-skeleton").props).toEqual({})
+ expect(serverRoot.root.findByProps({ "aria-label": "Loading server" }).props["aria-busy"])
+ .toBe("true")
+ })
+
+ it("uses a neutral route-resolution frame for malformed paths", () => {
+ const renderer = render(["/c/channels/s1/c1", "extra"].join("/"))
+ expect(renderer.root.findByProps({ "aria-label": "Resolving community route" }))
+ .toBeDefined()
+ expect(renderer.root.findAllByType("channel-skeleton")).toHaveLength(0)
+ expect(renderer.root.findAllByType("dm-skeleton")).toHaveLength(0)
})
})
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 f5a91d545..8c10985d2 100644
--- a/src/web/src/components/community/shell/community-pending-frame.tsx
+++ b/src/web/src/components/community/shell/community-pending-frame.tsx
@@ -1,11 +1,17 @@
"use client"
+import type { ReactNode } from "react"
import { BotListSkeleton } from "@/components/community/bots/bot-list-view"
import { ChannelLoadingFrame } from "@/components/community/channels/channel-loading-frame"
import { DmLoadingFrame } from "@/components/community/channels/dm-loading-frame"
import { MachineListSkeleton } from "@/components/community/machines/machine-list"
import { FriendsPage } from "@/components/community/social/friends-page"
import { Skeleton } from "@/components/ui/skeleton"
+import {
+ resolveCommunityModulePlan,
+ type CommunityModulePlan,
+} from "@/lib/community/community-route"
+import { tid } from "@/lib/community/testids"
function MeRootPendingFrame() {
return (
@@ -17,30 +23,92 @@ function MeRootPendingFrame() {
)
}
+function ServerLandingPendingFrame() {
+ return (
+ <main aria-busy="true" aria-label="Loading server" className="flex min-h-0 flex-1 flex-col">
+ <header className="flex h-12 shrink-0 items-center gap-2 border-b border-border/40 px-3">
+ <Skeleton className="size-6 rounded-md" />
+ <Skeleton className="h-4 w-32 rounded" />
+ </header>
+ <div className="flex min-h-0 flex-1 flex-col items-center justify-center gap-3 p-4">
+ <Skeleton className="size-12 rounded-xl" />
+ <Skeleton className="h-4 w-36 rounded" />
+ <Skeleton className="h-3 w-52 max-w-full rounded" />
+ </div>
+ </main>
+ )
+}
+
+function RouteResolutionPendingFrame() {
+ return (
+ <main
+ aria-busy="true"
+ aria-label="Resolving community route"
+ className="flex min-h-0 flex-1 flex-col items-center justify-center gap-3 bg-background p-4"
+ >
+ <Skeleton className="size-10 rounded-xl" />
+ <Skeleton className="h-4 w-40 rounded" />
+ </main>
+ )
+}
+
export function CommunityPendingFrame({
href,
reserveBackSlot = false,
+ plan: suppliedPlan,
}: {
href: string
reserveBackSlot?: boolean
+ plan?: CommunityModulePlan
}) {
- const pathname = href.split(/[?#]/, 1)[0]
- if (pathname === "/c/me") return <MeRootPendingFrame />
- if (pathname === "/c/me/machines") return <MachineListSkeleton reserveBackSlot={reserveBackSlot} />
- if (pathname === "/c/me/bots") return <BotListSkeleton reserveBackSlot={reserveBackSlot} />
- if (pathname === "/c/me/friends") {
- return (
- <FriendsPage
- friends={[]}
- pending={[]}
- blocked={[]}
- loading
- reserveBackSlot={reserveBackSlot}
- />
- )
- }
- if (/^\/c\/me\/[^/]+$/.test(pathname)) {
- return <DmLoadingFrame reserveBackSlot={reserveBackSlot} />
+ const plan = suppliedPlan ?? resolveCommunityModulePlan(href)
+ const reserveMeBackSlot = reserveBackSlot || (
+ plan.surface === "detail" && plan.sidebar.kind === "me"
+ )
+ let content: ReactNode
+ switch (plan.main.kind) {
+ case "me-root":
+ content = <MeRootPendingFrame />
+ break
+ case "machines":
+ content = <MachineListSkeleton reserveBackSlot={reserveMeBackSlot} />
+ break
+ case "bots":
+ content = <BotListSkeleton reserveBackSlot={reserveMeBackSlot} />
+ break
+ case "friends":
+ content = (
+ <FriendsPage
+ friends={[]}
+ pending={[]}
+ blocked={[]}
+ loading
+ reserveBackSlot={reserveMeBackSlot}
+ />
+ )
+ break
+ case "dm":
+ content = <DmLoadingFrame reserveBackSlot={reserveMeBackSlot} />
+ break
+ case "server-landing":
+ content = <ServerLandingPendingFrame />
+ break
+ case "server-conversation":
+ content = <ChannelLoadingFrame />
+ break
+ case "route-resolution":
+ content = <RouteResolutionPendingFrame />
+ break
+ case "none":
+ return null
}
- return <ChannelLoadingFrame />
+ return (
+ <div
+ data-testid={tid.pendingMain(plan.main.kind)}
+ data-community-main-kind={plan.main.kind}
+ className="flex min-h-0 min-w-0 flex-1 flex-col"
+ >
+ {content}
+ </div>
+ )
}
diff --git a/src/web/src/components/community/shell/community-session-pending-frame.test.ts b/src/web/src/components/community/shell/community-session-pending-frame.test.ts
index 85199a9c4..9b2913ca9 100644
--- a/src/web/src/components/community/shell/community-session-pending-frame.test.ts
+++ b/src/web/src/components/community/shell/community-session-pending-frame.test.ts
@@ -6,19 +6,72 @@ import { describe, expect, it, vi } from "vitest"
vi.mock("@/components/ui/skeleton", () => ({
Skeleton: (props: Record<string, unknown>) => createElement("skeleton", props),
}))
+vi.mock("@/components/ui/app-surface", () => ({
+ AppBackground: (props: Record<string, unknown>) => createElement("app-background", props),
+ AppSurface: (props: Record<string, unknown>) => createElement("app-surface", props),
+}))
+vi.mock("@/components/community/channels/channel-sidebar", () => ({
+ ChannelSidebarSkeleton: (props: Record<string, unknown>) => createElement("server-sidebar", props),
+}))
+vi.mock("@/components/community/channels/dm-sidebar", () => ({
+ DmSidebarSkeleton: (props: Record<string, unknown>) => createElement("me-sidebar", props),
+}))
+vi.mock("./server-rail", () => ({
+ ServerRailSkeleton: (props: Record<string, unknown>) => createElement("rail-skeleton", props),
+}))
+vi.mock("./user-bar", () => ({
+ UserBarSkeleton: (props: Record<string, unknown>) => createElement("user-bar-skeleton", props),
+}))
+vi.mock("./community-pending-frame", () => ({
+ CommunityPendingFrame: (props: Record<string, unknown>) => createElement("pending-main", props),
+}))
import { CommunitySessionPendingFrame } from "./community-session-pending-frame"
describe("CommunitySessionPendingFrame", () => {
- it("renders a stable inert viewport without community controls", () => {
+ function render(pathname: string) {
let renderer!: TestRenderer.ReactTestRenderer
act(() => {
- renderer = TestRenderer.create(createElement(CommunitySessionPendingFrame))
+ renderer = TestRenderer.create(createElement(CommunitySessionPendingFrame, { pathname }))
})
+ return renderer
+ }
+
+ it.each([
+ ["/c/me", "me-root", "me-sidebar", "me-root"],
+ ["/c/me/dm_1", "dm-detail", "me-sidebar", "dm"],
+ ["/c/channels/s1", "server-root", "server-sidebar", "server-landing"],
+ ["/c/channels/s1/c1", "server-detail", "server-sidebar", "server-conversation"],
+ ])("renders only route-owned modules for %s", (pathname, route, sidebar, main) => {
+ const renderer = render(pathname)
const frame = renderer.root.findByProps({ "aria-label": "Loading community" })
expect(frame.props["aria-busy"]).toBe("true")
- expect(renderer.root.findAllByType("skeleton").length).toBeGreaterThan(5)
+ expect(frame.props["data-community-route-kind"]).toBe(route)
+ expect(renderer.root.findAllByType("rail-skeleton")).toHaveLength(1)
+ expect(renderer.root.findAllByType(sidebar)).toHaveLength(1)
+ expect(renderer.root.findByType("pending-main").props.plan.main.kind).toBe(main)
+ expect(renderer.root.findAllByType("pending-main")).toHaveLength(1)
+ expect(renderer.root.findAllByType("user-bar-skeleton")).toHaveLength(1)
+ expect(renderer.root.findAllByType("skeleton").length).toBeGreaterThanOrEqual(2)
expect(renderer.root.findAllByType("button")).toEqual([])
expect(renderer.root.findAllByType("a")).toEqual([])
})
+
+ it("keeps invalid routes neutral instead of guessing account or server ownership", () => {
+ const renderer = render(["/c/channels/s1/c1", "extra"].join("/"))
+ expect(renderer.root.findAllByType("rail-skeleton")).toHaveLength(0)
+ expect(renderer.root.findAllByType("me-sidebar")).toHaveLength(0)
+ expect(renderer.root.findAllByType("server-sidebar")).toHaveLength(0)
+ expect(renderer.root.findAllByType("user-bar-skeleton")).toHaveLength(0)
+ expect(renderer.root.findByType("pending-main").props.plan.main.kind).toBe("route-resolution")
+ })
+
+ it("renders no authenticated shell modules for the public invite bypass", () => {
+ const renderer = render("/c/invite/token")
+ expect(renderer.root.findAllByType("rail-skeleton")).toHaveLength(0)
+ expect(renderer.root.findAllByType("me-sidebar")).toHaveLength(0)
+ expect(renderer.root.findAllByType("server-sidebar")).toHaveLength(0)
+ expect(renderer.root.findAllByType("pending-main")).toHaveLength(0)
+ expect(renderer.root.findAllByType("user-bar-skeleton")).toHaveLength(0)
+ })
})
diff --git a/src/web/src/components/community/shell/community-session-pending-frame.tsx b/src/web/src/components/community/shell/community-session-pending-frame.tsx
index bdd91088b..23ee422ee 100644
--- a/src/web/src/components/community/shell/community-session-pending-frame.tsx
+++ b/src/web/src/components/community/shell/community-session-pending-frame.tsx
@@ -1,37 +1,122 @@
+import type { CSSProperties } from "react"
+import { ChannelSidebarSkeleton } from "@/components/community/channels/channel-sidebar"
+import { DmSidebarSkeleton } from "@/components/community/channels/dm-sidebar"
+import { AppBackground, AppSurface } from "@/components/ui/app-surface"
import { Skeleton } from "@/components/ui/skeleton"
+import { resolveCommunityModulePlan } from "@/lib/community/community-route"
+import { tid } from "@/lib/community/testids"
+import { cn } from "@/lib/utils"
+import { CommunityPendingFrame } from "./community-pending-frame"
+import {
+ COMMUNITY_RAIL_WIDTH,
+ desktopUserBarOverlayWidth,
+} from "./shell-frame-geometry"
+import { ServerRailSkeleton } from "./server-rail"
+import { UserBarSkeleton } from "./user-bar"
+
+const SESSION_SIDEBAR_WIDTH = 240
+const SESSION_USER_BAR_WIDTH = desktopUserBarOverlayWidth(SESSION_SIDEBAR_WIDTH)
+
+function SessionRail() {
+ return (
+ <nav
+ aria-hidden
+ className="flex h-full w-14 shrink-0 flex-col items-center gap-2 pb-2 pt-1"
+ >
+ <Skeleton className="size-10 shrink-0 rounded-xl" />
+ <div className="h-px w-8 shrink-0 bg-border/60" />
+ <div className="min-h-0 w-full flex-1 overflow-hidden px-2">
+ <ServerRailSkeleton />
+ </div>
+ <Skeleton className="mt-auto size-10 shrink-0 rounded-[20px]" />
+ </nav>
+ )
+}
/** Stable, inert viewport shown before authenticated community providers exist. */
-export function CommunitySessionPendingFrame() {
+export function CommunitySessionPendingFrame({ pathname }: { pathname: string }) {
+ const plan = resolveCommunityModulePlan(pathname)
+ const showCommunityShell = plan.rail === "community"
+ const showSidebar = plan.sidebar.kind !== "none"
+ const showMain = plan.main.kind !== "none"
+ const isList = plan.surface === "list"
+ const isDetail = plan.surface === "detail"
+
return (
- <main
+ <div
+ data-testid={tid.initialFrame}
+ data-community-route-kind={plan.route}
aria-busy="true"
aria-label="Loading community"
- className="flex h-dvh min-h-0 overflow-hidden bg-muted/40 p-2 pl-0"
+ className="fixed inset-0 flex overflow-hidden font-sans text-sm text-foreground"
>
- <div aria-hidden className="flex w-14 shrink-0 flex-col items-center gap-3 py-2">
- <Skeleton className="size-10 rounded-xl" />
- <Skeleton className="size-10 rounded-full" />
- <Skeleton className="size-10 rounded-full" />
- </div>
- <div aria-hidden className="flex min-w-0 flex-1 overflow-hidden rounded-tl-xl border-l border-t border-border/40 bg-background">
- <div className="hidden w-60 shrink-0 flex-col gap-3 border-r border-border/40 bg-sidebar p-3 sm:flex">
- <Skeleton className="h-6 w-28" />
- <Skeleton className="h-9 w-full" />
- <Skeleton className="h-9 w-4/5" />
- <Skeleton className="mt-auto h-11 w-full" />
+ <AppBackground />
+ {showCommunityShell && (
+ <div className={cn("flex min-h-0", isDetail && "max-sm:hidden")}>
+ <SessionRail />
</div>
- <div className="flex min-w-0 flex-1 flex-col">
- <div className="flex h-12 items-center gap-2 border-b border-border/40 px-3">
- <Skeleton className="size-6 rounded-full" />
- <Skeleton className="h-4 w-36" />
+ )}
+ <div
+ className={cn(
+ "relative flex min-h-0 min-w-0 flex-1 flex-col",
+ showCommunityShell && isList && "pt-2",
+ showCommunityShell && isDetail && "pt-0 sm:pt-2",
+ )}
+ >
+ <AppSurface
+ className={cn(
+ "rounded-bl-none rounded-br-none rounded-tl-xl rounded-tr-none border-l border-t border-border/40 shadow-none ring-0",
+ isDetail && "max-sm:rounded-none max-sm:border-0 max-sm:bg-background",
+ !showCommunityShell && "rounded-none border-0 bg-background",
+ )}
+ >
+ <div className="flex min-h-0 min-w-0 flex-1">
+ {showSidebar && (
+ <div
+ data-community-sidebar-kind={plan.sidebar.kind}
+ className={cn(
+ "min-h-0 shrink-0 flex-col border-r border-border/40 bg-sidebar pb-15 sm:flex",
+ isList ? "flex w-full sm:w-60" : "hidden w-60 sm:flex",
+ )}
+ >
+ {plan.sidebar.kind === "server"
+ ? <ChannelSidebarSkeleton targetServerId={plan.sidebar.serverId} />
+ : <DmSidebarSkeleton />}
+ </div>
+ )}
+ {showMain && (
+ <div
+ className={cn(
+ "min-h-0 min-w-0 flex-1 flex-col bg-background sm:flex",
+ isList ? "hidden" : "flex",
+ )}
+ >
+ <CommunityPendingFrame
+ href={pathname}
+ plan={plan}
+ reserveBackSlot={isDetail}
+ />
+ </div>
+ )}
</div>
- <div className="flex flex-1 flex-col gap-4 p-4">
- <Skeleton className="h-16 w-2/3 max-w-md" />
- <Skeleton className="h-16 w-3/4 max-w-lg" />
- <Skeleton className="h-16 w-1/2 max-w-sm" />
+ </AppSurface>
+
+ {showCommunityShell && (
+ <div
+ data-slot="community-user-bar-overlay"
+ className={cn(
+ "absolute bottom-0 left-0 z-10 w-[calc(100%+3.5rem)] sm:w-(--community-session-user-bar-width)",
+ isDetail && "max-sm:hidden",
+ )}
+ style={{
+ "--community-session-user-bar-width": `${SESSION_USER_BAR_WIDTH}px`,
+ marginLeft: -COMMUNITY_RAIL_WIDTH,
+ } as CSSProperties}
+ >
+ <UserBarSkeleton />
</div>
- </div>
+ )}
</div>
- </main>
+ </div>
)
}
diff --git a/src/web/src/components/community/shell/server-rail.pending.test.ts b/src/web/src/components/community/shell/server-rail.pending.test.ts
index a03dec17f..58f7a33c1 100644
--- a/src/web/src/components/community/shell/server-rail.pending.test.ts
+++ b/src/web/src/components/community/shell/server-rail.pending.test.ts
@@ -1,7 +1,7 @@
import { createElement, type ReactNode } from "react"
import TestRenderer, { act } from "react-test-renderer"
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"
-import { ServerRail } from "./server-rail"
+import { ServerRail, ServerRailSkeleton } from "./server-rail"
import { tid } from "@/lib/community/testids"
import type { RailInstruction } from "@/lib/community/server-rail-model"
@@ -35,7 +35,9 @@ vi.mock("./rail-icon", () => ({ RailIcon: () => null }))
vi.mock("./animated-alook-logo", () => ({ AnimatedAlookLogo: () => null }))
vi.mock("./server-rail-move-menu", () => ({ ServerRailMoveMenu: () => null }))
vi.mock("../settings/create-server-dialog", () => ({ CreateServerDialog: () => null }))
-vi.mock("@/components/ui/skeleton", () => ({ Skeleton: () => null }))
+vi.mock("@/components/ui/skeleton", () => ({
+ Skeleton: (props: Record<string, unknown>) => createElement("skeleton", props),
+}))
vi.mock("@/components/ui/tooltip", () => ({
Tooltip: ({ children }: { children: ReactNode }) => children,
TooltipTrigger: ({ children }: { children: ReactNode }) => children,
@@ -119,6 +121,17 @@ describe("ServerRail one-in-flight structural guard", () => {
})
afterEach(() => vi.unstubAllGlobals())
+ it("exports an inert data-free rail placeholder", async () => {
+ let renderer!: TestRenderer.ReactTestRenderer
+ await act(async () => {
+ renderer = TestRenderer.create(createElement(ServerRailSkeleton))
+ })
+ expect(renderer.root.findByProps({ "data-testid": tid.initialRailPending }))
+ .toBeDefined()
+ expect(renderer.root.findAllByType("skeleton")).toHaveLength(4)
+ expect(renderer.root.findAllByType("button")).toHaveLength(0)
+ })
+
it("aggregates unread only while collapsed and preserves it on the expanded child", async () => {
let renderer!: TestRenderer.ReactTestRenderer
const unreadServers = servers.map((server) => ({
diff --git a/src/web/src/components/community/shell/server-rail.tsx b/src/web/src/components/community/shell/server-rail.tsx
index f8172796c..3b1b52025 100644
--- a/src/web/src/components/community/shell/server-rail.tsx
+++ b/src/web/src/components/community/shell/server-rail.tsx
@@ -468,9 +468,13 @@ export const ServerRail = memo(function ServerRail({
)
})
-function ServerRailSkeleton() {
+export function ServerRailSkeleton() {
return (
- <div className="flex w-full flex-col items-center gap-2">
+ <div
+ data-testid={tid.initialRailPending}
+ aria-hidden
+ className="flex w-full flex-col items-center gap-2"
+ >
{Array.from({ length: 4 }).map((_, index) => (
<Skeleton key={index} className="size-10 rounded-[20px]" />
))}
diff --git a/src/web/src/components/community/shell/shell-frame-view.test.ts b/src/web/src/components/community/shell/shell-frame-view.test.ts
index 562114044..06559803c 100644
--- a/src/web/src/components/community/shell/shell-frame-view.test.ts
+++ b/src/web/src/components/community/shell/shell-frame-view.test.ts
@@ -117,7 +117,11 @@ describe("ShellFrameView", () => {
inbox,
}, createElement("main-content")))
})
- expect(renderer.root.findAllByType("channel-loading-frame")).toHaveLength(2)
+ expect(renderer.root.findAllByType("channel-loading-frame")).toHaveLength(1)
+ expect(renderer.root.findByType("channel-loading-frame").props).toMatchObject({
+ href: "/c/me/dm_1",
+ reserveBackSlot: true,
+ })
const initialRailWrapper = renderer.root.find((node) =>
node.type === "div"
&& typeof node.props.className === "string"
diff --git a/src/web/src/components/community/shell/shell-frame-view.tsx b/src/web/src/components/community/shell/shell-frame-view.tsx
index 7eec96a69..9d574f7bf 100644
--- a/src/web/src/components/community/shell/shell-frame-view.tsx
+++ b/src/web/src/components/community/shell/shell-frame-view.tsx
@@ -150,21 +150,10 @@ export function ShellFrameView({
)}
>
{checkpoint.main.kind === "target-skeleton" || isInitial ? (
- isInitialDetail ? (
- <>
- <div className="flex min-h-0 flex-1 sm:hidden">
- <CommunityPendingFrame href={checkpoint.targetHref} reserveBackSlot />
- </div>
- <div className="hidden min-h-0 flex-1 sm:flex">
- <CommunityPendingFrame href={checkpoint.targetHref} />
- </div>
- </>
- ) : (
- <CommunityPendingFrame
- href={checkpoint.targetHref}
- reserveBackSlot={isMobileDetail}
- />
- )
+ <CommunityPendingFrame
+ href={checkpoint.targetHref}
+ reserveBackSlot={surface === "detail"}
+ />
) : children}
</ResizablePanel>
</ResizablePanelGroup>
diff --git a/src/web/src/components/community/shell/user-bar.test.ts b/src/web/src/components/community/shell/user-bar.test.ts
index cc5127561..b03f94a82 100644
--- a/src/web/src/components/community/shell/user-bar.test.ts
+++ b/src/web/src/components/community/shell/user-bar.test.ts
@@ -1,7 +1,8 @@
import { createElement } from "react"
import { renderToStaticMarkup } from "react-dom/server"
import { describe, expect, it } from "vitest"
-import { UserBar } from "./user-bar"
+import { UserBar, UserBarSkeleton } from "./user-bar"
+import { tid } from "@/lib/community/testids"
describe("UserBar", () => {
it("keeps the name shrinkable and truncated while the action group stays fixed", () => {
@@ -20,4 +21,13 @@ describe("UserBar", () => {
expect(html).toContain('class="truncate text-sm font-medium leading-tight"')
expect(html).toContain('class="flex shrink-0 items-center gap-1"')
})
+
+ it("provides an inert account-neutral placeholder with the same outer geometry", () => {
+ const html = renderToStaticMarkup(createElement(UserBarSkeleton))
+ expect(html).toContain(`data-testid="${tid.initialUserBarPending}"`)
+ expect(html).toContain("aria-hidden=\"true\"")
+ expect(html).toContain('class="w-full min-w-0 max-w-full shrink-0 overflow-hidden px-3 pb-3 pt-0"')
+ expect(html).not.toContain("<button")
+ expect(html).not.toContain("<a")
+ })
})
diff --git a/src/web/src/components/community/shell/user-bar.tsx b/src/web/src/components/community/shell/user-bar.tsx
index 590928dd7..9d0e08076 100644
--- a/src/web/src/components/community/shell/user-bar.tsx
+++ b/src/web/src/components/community/shell/user-bar.tsx
@@ -4,6 +4,7 @@ import type React from "react"
import { Inbox, Settings } from "lucide-react"
import { Popover, PopoverTrigger, PopoverContent } from "@/components/ui/popover"
import { Avatar } from "../avatar"
+import { Skeleton } from "@/components/ui/skeleton"
import type { OpenProfile } from "@/components/community/social/profile-types"
import { resolveProfilePresence } from "@/lib/community/presence"
import { tid } from "@/lib/community/testids"
@@ -30,6 +31,23 @@ export function UserBar({ user, onOpenProfile, onEditProfile, inbox, hasUnread,
)
}
+export function UserBarSkeleton() {
+ return (
+ <div
+ data-testid={tid.initialUserBarPending}
+ aria-hidden
+ className="w-full min-w-0 max-w-full shrink-0 overflow-hidden px-3 pb-3 pt-0"
+ >
+ <div className="flex h-12 items-center gap-3 rounded-xl bg-muted px-4 ring-1 ring-border/40">
+ <Skeleton className="size-7 shrink-0 rounded-full" />
+ <Skeleton className="h-3.5 min-w-0 flex-1 rounded" />
+ <Skeleton className="size-7 shrink-0 rounded-lg" />
+ <Skeleton className="size-7 shrink-0 rounded-lg" />
+ </div>
+ </div>
+ )
+}
+
function Inner({ user, onOpenProfile, onEditProfile, inbox, hasUnread, inboxOpen, onInboxOpenChange }: {
user: { id: string; name: string; avatar: string }
onOpenProfile?: OpenProfile
diff --git a/src/web/src/lib/community/community-route.test.ts b/src/web/src/lib/community/community-route.test.ts
index cca1e6c71..3c810da86 100644
--- a/src/web/src/lib/community/community-route.test.ts
+++ b/src/web/src/lib/community/community-route.test.ts
@@ -7,13 +7,70 @@ import {
normalizeCommunityHref,
communityServerId,
removeCommunityParam,
+ resolveCommunityModulePlan,
resolveCommunityCheckpointPlan,
resolveCommunityRoute,
serverModalMarkerCleanupHref,
serverRootHref,
} from "./community-route"
+const removedNestedChannelPath = (...segments: string[]) => (
+ ["", "c", "channels", ...segments].join("/")
+)
+
describe("community route", () => {
+ it.each([
+ ["/c", "community-root-redirect", "detail", "me", "machines"],
+ ["/c/me", "me-root", "list", "me", "me-root"],
+ ["/c/me/friends", "me-friends", "detail", "me", "friends"],
+ ["/c/me/machines", "me-machines", "detail", "me", "machines"],
+ ["/c/me/bots", "me-bots", "detail", "me", "bots"],
+ ["/c/me/dm_1", "dm-detail", "detail", "me", "dm"],
+ ["/c/channels/s1", "server-root", "list", "server", "server-landing"],
+ ["/c/channels/s1/c1", "server-detail", "detail", "server", "server-conversation"],
+ ["/c/channels/s1/settings", "server-settings-redirect", "list", "server", "server-landing"],
+ ["/c/invite/token", "public-invite", "neutral", "none", "none"],
+ ])("plans route-owned modules for %s", (href, route, surface, sidebar, main) => {
+ const plan = resolveCommunityModulePlan(href)
+ expect(plan).toMatchObject({
+ route,
+ surface,
+ sidebar: { kind: sidebar },
+ main: { kind: main },
+ })
+ })
+
+ it.each([
+ "/",
+ "/c/channels",
+ removedNestedChannelPath("s1", "c1", "extra"),
+ "/c/me/dm_1/extra",
+ "/c//me",
+ "/c/me/%E0%A4%A",
+ "/c/me/dm%2Fescape",
+ "/outside/c/me",
+ ])("keeps malformed or unknown route %s neutral", (href) => {
+ expect(resolveCommunityModulePlan(href)).toEqual({
+ route: "unknown",
+ surface: "neutral",
+ rail: "none",
+ sidebar: { kind: "none" },
+ main: { kind: "route-resolution" },
+ })
+ })
+
+ it("ignores query and hash when selecting modules", () => {
+ expect(resolveCommunityModulePlan("/c/channels/s1/c1?settings=1#message"))
+ .toEqual(resolveCommunityModulePlan("/c/channels/s1/c1"))
+ })
+
+ it("publishes explicit canonical destinations only for redirect routes", () => {
+ expect(resolveCommunityModulePlan("/c").canonicalHref).toBe("/c/me/machines")
+ expect(resolveCommunityModulePlan("/c/channels/s1/settings").canonicalHref)
+ .toBe("/c/channels/s1")
+ expect(resolveCommunityModulePlan("/c/me/machines").canonicalHref).toBeUndefined()
+ })
+
it.each([
["/c/me", "list", null],
["/c/me/friends", "detail", "/c/me"],
@@ -21,6 +78,7 @@ describe("community route", () => {
["/c/me/dm_1", "detail", "/c/me"],
["/c/channels/server_1", "list", null],
["/c/channels/server_1/channel_1", "detail", "/c/channels/server_1"],
+ ["/outside", "detail", null],
])("classifies %s", (pathname, surface, parentPath) => {
expect(resolveCommunityRoute(pathname)).toEqual({ surface, parentPath })
})
@@ -34,6 +92,8 @@ describe("community route", () => {
it.each([
["/c/channels/server_1", "server_1"],
["/c/channels/server_1/channel_1?keep=1#message", "server_1"],
+ [removedNestedChannelPath("server_1", "channel_1", "extra"), null],
+ ["/c/channels/server%2Fescape/channel_1", null],
["/c/me", null],
["/not-community/channels/server_1", null],
])("extracts the community server identity from %s", (href, serverId) => {
diff --git a/src/web/src/lib/community/community-route.ts b/src/web/src/lib/community/community-route.ts
index e89daf13a..7f41cbf4d 100644
--- a/src/web/src/lib/community/community-route.ts
+++ b/src/web/src/lib/community/community-route.ts
@@ -1,5 +1,41 @@
export type CommunitySurface = "list" | "detail"
+type CommunityModuleRoute =
+ | "community-root-redirect"
+ | "me-root"
+ | "me-friends"
+ | "me-machines"
+ | "me-bots"
+ | "dm-detail"
+ | "server-root"
+ | "server-detail"
+ | "server-settings-redirect"
+ | "public-invite"
+ | "unknown"
+
+type CommunityModuleMain =
+ | { kind: "me-root" }
+ | { kind: "friends" }
+ | { kind: "machines" }
+ | { kind: "bots" }
+ | { kind: "dm"; dmId: string }
+ | { kind: "server-landing"; serverId: string }
+ | { kind: "server-conversation"; serverId: string; leafId: string }
+ | { kind: "route-resolution" }
+ | { kind: "none" }
+
+export type CommunityModulePlan = {
+ route: CommunityModuleRoute
+ canonicalHref?: string
+ surface: CommunitySurface | "neutral"
+ rail: "community" | "none"
+ sidebar:
+ | { kind: "me" }
+ | { kind: "server"; serverId: string }
+ | { kind: "none" }
+ main: CommunityModuleMain
+}
+
export type CommunityRoute = {
surface: CommunitySurface
parentPath: string | null
@@ -38,11 +74,145 @@ export type CommunityCheckpointPlan = {
}
export function communityServerId(href: string): string | null {
- const pathname = href.split(/[?#]/, 1)[0]
- const segments = pathname?.split("/").filter(Boolean) ?? []
- return segments[0] === "c" && segments[1] === "channels" && segments[2]
- ? segments[2]
- : null
+ const sidebar = resolveCommunityModulePlan(href).sidebar
+ return sidebar.kind === "server" ? sidebar.serverId : null
+}
+
+function unknownCommunityModulePlan(): CommunityModulePlan {
+ return {
+ route: "unknown",
+ surface: "neutral",
+ rail: "none",
+ sidebar: { kind: "none" },
+ main: { kind: "route-resolution" },
+ }
+}
+
+function structuralPathname(href: string): string {
+ return href.split(/[?#]/, 1)[0] || "/"
+}
+
+function decodedPathSegments(pathname: string): string[] | null {
+ if (!pathname.startsWith("/")) return null
+ const raw = pathname.slice(1).split("/")
+ if (raw.at(-1) === "") raw.pop()
+ if (raw.some((segment) => segment.length === 0)) return null
+ try {
+ const decoded = raw.map((segment) => decodeURIComponent(segment))
+ if (decoded.some((segment) => !segment || /[/?#\\]/.test(segment))) return null
+ return decoded
+ } catch {
+ return null
+ }
+}
+
+export function resolveCommunityModulePlan(href: string): CommunityModulePlan {
+ const segments = decodedPathSegments(structuralPathname(href))
+ if (!segments || segments[0] !== "c") return unknownCommunityModulePlan()
+
+ if (segments.length === 1) {
+ return {
+ route: "community-root-redirect",
+ canonicalHref: "/c/me/machines",
+ surface: "detail",
+ rail: "community",
+ sidebar: { kind: "me" },
+ main: { kind: "machines" },
+ }
+ }
+
+ if (segments[1] === "invite" && segments.length === 3) {
+ return {
+ route: "public-invite",
+ surface: "neutral",
+ rail: "none",
+ sidebar: { kind: "none" },
+ main: { kind: "none" },
+ }
+ }
+
+ if (segments[1] === "me") {
+ if (segments.length === 2) {
+ return {
+ route: "me-root",
+ surface: "list",
+ rail: "community",
+ sidebar: { kind: "me" },
+ main: { kind: "me-root" },
+ }
+ }
+ if (segments.length !== 3) return unknownCommunityModulePlan()
+ const leaf = segments[2]!
+ if (leaf === "friends") {
+ return {
+ route: "me-friends",
+ surface: "detail",
+ rail: "community",
+ sidebar: { kind: "me" },
+ main: { kind: "friends" },
+ }
+ }
+ if (leaf === "machines") {
+ return {
+ route: "me-machines",
+ surface: "detail",
+ rail: "community",
+ sidebar: { kind: "me" },
+ main: { kind: "machines" },
+ }
+ }
+ if (leaf === "bots") {
+ return {
+ route: "me-bots",
+ surface: "detail",
+ rail: "community",
+ sidebar: { kind: "me" },
+ main: { kind: "bots" },
+ }
+ }
+ return {
+ route: "dm-detail",
+ surface: "detail",
+ rail: "community",
+ sidebar: { kind: "me" },
+ main: { kind: "dm", dmId: leaf },
+ }
+ }
+
+ if (segments[1] === "channels") {
+ if (segments.length < 3 || segments.length > 4) return unknownCommunityModulePlan()
+ const serverId = segments[2]!
+ const sidebar = { kind: "server" as const, serverId }
+ if (segments.length === 3) {
+ return {
+ route: "server-root",
+ surface: "list",
+ rail: "community",
+ sidebar,
+ main: { kind: "server-landing", serverId },
+ }
+ }
+ const leafId = segments[3]!
+ if (leafId === "settings") {
+ return {
+ route: "server-settings-redirect",
+ canonicalHref: `/c/channels/${encodeURIComponent(serverId)}`,
+ surface: "list",
+ rail: "community",
+ sidebar,
+ main: { kind: "server-landing", serverId },
+ }
+ }
+ return {
+ route: "server-detail",
+ surface: "detail",
+ rail: "community",
+ sidebar,
+ main: { kind: "server-conversation", serverId, leafId },
+ }
+ }
+
+ return unknownCommunityModulePlan()
}
export function normalizeCommunityHref(href: string): CommunityHref {
@@ -55,10 +225,10 @@ export function normalizeCommunityHref(href: string): CommunityHref {
)
searchParams.sort()
const search = searchParams.toString()
- const segments = pathname.split("/").filter(Boolean)
- const scope: CommunityScope = segments[0] === "c" && segments[1] === "channels" && segments[2]
- ? { kind: "server", serverId: segments[2] }
- : segments[0] === "c" && segments[1] === "me"
+ const modulePlan = resolveCommunityModulePlan(pathname)
+ const scope: CommunityScope = modulePlan.sidebar.kind === "server"
+ ? { kind: "server", serverId: modulePlan.sidebar.serverId }
+ : modulePlan.sidebar.kind === "me"
? { kind: "me" }
: { kind: "unknown" }
return {
@@ -66,7 +236,7 @@ export function normalizeCommunityHref(href: string): CommunityHref {
pathname,
search,
scope,
- surface: resolveCommunityRoute(pathname).surface,
+ surface: modulePlan.surface === "list" ? "list" : "detail",
leafKey: pathname,
}
}
@@ -178,22 +348,18 @@ function committedPlan(
}
export function resolveCommunityRoute(pathname: string): CommunityRoute {
- const segments = pathname.split("/").filter(Boolean)
- if (segments[0] !== "c") return { surface: "detail", parentPath: null }
-
- if (segments[1] === "me") {
- return segments.length === 2
- ? { surface: "list", parentPath: null }
- : { surface: "detail", parentPath: "/c/me" }
+ const plan = resolveCommunityModulePlan(pathname)
+ if (plan.route === "dm-detail" || plan.route.startsWith("me-")) {
+ return plan.surface === "detail"
+ ? { surface: "detail", parentPath: "/c/me" }
+ : { surface: "list", parentPath: null }
}
-
- if (segments[1] === "channels" && segments[2]) {
- const serverRoot = `/c/channels/${segments[2]}`
- if (segments.length === 3) return { surface: "list", parentPath: null }
- return { surface: "detail", parentPath: serverRoot }
+ if (plan.sidebar.kind === "server") {
+ return plan.surface === "detail"
+ ? { surface: "detail", parentPath: serverRootHref(plan.sidebar.serverId) }
+ : { surface: "list", parentPath: null }
}
-
- return { surface: "detail", parentPath: null }
+ return { surface: plan.surface === "list" ? "list" : "detail", parentPath: null }
}
export function serverRootHref(serverId: string): string {
diff --git a/src/web/src/lib/community/testids.ts b/src/web/src/lib/community/testids.ts
index c16f9e9f8..6310de61f 100644
--- a/src/web/src/lib/community/testids.ts
+++ b/src/web/src/lib/community/testids.ts
@@ -13,6 +13,10 @@ export const tid = {
messageScroller: "community-message-scroller",
wsReconnectOverlay: "community-ws-reconnect-overlay",
wsRetry: "community-ws-retry",
+ initialFrame: "community-initial-frame",
+ initialRailPending: "community-initial-rail-pending",
+ initialUserBarPending: "community-initial-user-bar-pending",
+ pendingMain: (kind: string) => `community-pending-main-${kind}`,
serverAdd: "community-server-add",
serverRailScroll: "community-server-rail-scroll",
serverRailFolder: (id: string) => `community-server-folder-${id}`,
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 34426f48b..76fa3859b 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
@@ -137,7 +137,7 @@ test("server switching exposes one target-scoped cold checkpoint and skips it wh
await serverBIcon.click({ noWaitAfter: true })
await expect.poll(warmB.heldNavigation).toBeGreaterThan(0)
await expect(page.getByTestId(tid.channelSidebarPending(serverB))).toHaveCount(0)
- await expect(page.getByLabel("Loading conversation")).toHaveCount(0)
+ await expect(page.getByTestId(tid.pendingMain("server-landing"))).toHaveCount(0)
await expect(page.getByRole("heading", { name: channelAName })).toBeVisible()
await expectActiveServer(page, serverA, serverB)
await warmB.release()
@@ -158,7 +158,7 @@ test("server switching exposes one target-scoped cold checkpoint and skips it wh
await clickServer(page, serverC)
await expect.poll(coldC.heldNavigation).toBeGreaterThan(0)
await expect(page.getByTestId(tid.channelSidebarPending(serverC))).toBeVisible()
- await expect(page.getByLabel("Loading conversation")).toBeVisible()
+ await expect(page.getByTestId(tid.pendingMain("server-landing"))).toBeVisible()
await expect(page.getByRole("button", { name: channelAName })).toHaveCount(0)
await expectActiveServer(page, serverC, serverA)
expect(mutations).toEqual([])
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 11441770e..4c326576d 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
@@ -67,10 +67,10 @@ test("community checkpoint waits for layout-owned frame commits", async ({ asUse
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()
+ await expect(page.getByTestId(tid.pendingMain("server-landing"))).toBeVisible()
await expect(page.getByRole("heading", { name: channelBName })).toHaveCount(0)
await page.waitForTimeout(150)
- await expect(page.getByLabel("Loading conversation")).toBeVisible()
+ await expect(page.getByTestId(tid.pendingMain("server-landing"))).toBeVisible()
await rootGate.release()
await expect(page.getByRole("heading", { name: channelBName })).toBeVisible({ timeout: 30_000 })
diff --git a/src/web/src/test/e2e-ui/41-community-initial-load-module-skeletons.spec.ts b/src/web/src/test/e2e-ui/41-community-initial-load-module-skeletons.spec.ts
new file mode 100644
index 000000000..a89278dc6
--- /dev/null
+++ b/src/web/src/test/e2e-ui/41-community-initial-load-module-skeletons.spec.ts
@@ -0,0 +1,285 @@
+import type { BrowserContext, Page, Route } from "@playwright/test"
+import { test, expect, userId } from "./_fixtures/community-fixture"
+import { seedChannel, seedDm, seedDmMessage, seedMessage, seedServer } from "./_fixtures/seed"
+import { tid } from "./_fixtures/testids"
+
+type Surface = "list" | "detail" | "neutral"
+type Sidebar = "me" | "server" | "none"
+
+type ExpectedFrame = {
+ route: string
+ surface: Surface
+ sidebar: Sidebar
+ main: string
+ serverId?: string
+}
+
+async function holdSession(page: Page) {
+ let releaseGate!: () => void
+ let disposition: "continue" | "abort" = "continue"
+ const gate = new Promise<void>((resolve) => { releaseGate = resolve })
+ let hits = 0
+ const pattern = "**/api/auth/get-session**"
+ const handler = async (route: Route) => {
+ hits += 1
+ await gate
+ if (disposition === "abort") await route.abort("aborted")
+ else await route.continue()
+ }
+ await page.route(pattern, handler)
+ return {
+ hits: () => hits,
+ release: () => { releaseGate() },
+ abort: () => {
+ disposition = "abort"
+ releaseGate()
+ },
+ }
+}
+
+function captureCommunityTraffic(page: Page) {
+ const requests: Array<{ method: string; pathname: string; search: string }> = []
+ const responses: Array<{ method: string; pathname: string; search: string; status: number }> = []
+ const failures: Array<{ method: string; pathname: string; search: string; error: string }> = []
+ let sockets = 0
+ page.on("request", (request) => {
+ const { pathname, search } = new URL(request.url())
+ if (pathname.startsWith("/api/community/")) {
+ requests.push({ method: request.method(), pathname, search })
+ }
+ })
+ page.on("response", (response) => {
+ const { pathname, search } = new URL(response.url())
+ if (pathname.startsWith("/api/community/")) {
+ responses.push({
+ method: response.request().method(),
+ pathname,
+ search,
+ status: response.status(),
+ })
+ }
+ })
+ page.on("requestfailed", (request) => {
+ const { pathname, search } = new URL(request.url())
+ if (pathname.startsWith("/api/community/")) {
+ failures.push({
+ method: request.method(),
+ pathname,
+ search,
+ error: request.failure()?.errorText ?? "unknown",
+ })
+ }
+ })
+ page.on("websocket", (socket) => {
+ if (new URL(socket.url()).pathname.endsWith("/user")) sockets += 1
+ })
+ return { requests, responses, failures, sockets: () => sockets }
+}
+
+async function expectVisibility(locator: ReturnType<Page["getByTestId"]>, visible: boolean) {
+ if (visible) await expect(locator).toBeVisible()
+ else await expect(locator).toBeHidden()
+}
+
+async function expectOwnedFrame(
+ page: Page,
+ expected: ExpectedFrame,
+ distinctiveStrings: string[],
+) {
+ const frame = page.getByTestId(tid.initialFrame)
+ await expect(frame).toBeVisible()
+ await expect(frame).toHaveAttribute("data-community-route-kind", expected.route)
+ const mobile = (page.viewportSize()?.width ?? 640) < 640
+ const shellVisible = expected.sidebar !== "none"
+ const detailMobile = mobile && expected.surface === "detail"
+ const listMobile = mobile && expected.surface === "list"
+
+ const rail = page.getByTestId(tid.initialRailPending)
+ const userBar = page.getByTestId(tid.initialUserBarPending)
+ if (shellVisible) {
+ await expect(rail).toHaveCount(1)
+ await expect(userBar).toHaveCount(1)
+ await expectVisibility(rail, !detailMobile)
+ await expectVisibility(userBar, !detailMobile)
+ } else {
+ await expect(rail).toHaveCount(0)
+ await expect(userBar).toHaveCount(0)
+ }
+
+ const meSidebar = page.getByTestId(tid.dmSidebarPending)
+ const serverSidebar = expected.serverId
+ ? page.getByTestId(tid.channelSidebarPending(expected.serverId))
+ : page.locator(`[data-testid^="${tid.channelSidebarPending("")}"]`)
+ await expect(meSidebar).toHaveCount(expected.sidebar === "me" ? 1 : 0)
+ await expect(serverSidebar).toHaveCount(expected.sidebar === "server" ? 1 : 0)
+ if (expected.sidebar === "me") await expectVisibility(meSidebar, !detailMobile)
+ if (expected.sidebar === "server") await expectVisibility(serverSidebar, !detailMobile)
+
+ const main = page.getByTestId(tid.pendingMain(expected.main))
+ await expect(main).toHaveCount(1)
+ await expectVisibility(main, !listMobile)
+ await expect(frame.getByRole("button")).toHaveCount(0)
+ await expect(frame.locator("a")).toHaveCount(0)
+ for (const value of distinctiveStrings) await expect(frame).not.toContainText(value)
+}
+
+async function closeHeldContext(
+ context: BrowserContext,
+ gate: Awaited<ReturnType<typeof holdSession>>,
+) {
+ gate.abort()
+ await context.close()
+}
+
+test.describe.serial("community initial-load module skeletons", () => {
+ let serverId: string
+ let channelId: string
+ let dmId: string
+ let serverName: string
+ let channelName: string
+ let privateMessage: string
+
+ test.beforeAll(async () => {
+ const stamp = Date.now()
+ serverName = `COLD SERVER ${stamp}`
+ channelName = `cold-channel-${stamp}`
+ privateMessage = `PRIVATE COLD MESSAGE ${stamp}`
+ serverId = await seedServer("alice", serverName)
+ channelId = await seedChannel("alice", serverId, channelName)
+ await seedMessage("alice", channelId, privateMessage)
+ dmId = await seedDm("alice", userId("bob"))
+ await seedDmMessage("alice", dmId, privateMessage)
+ })
+
+ test("cold mobile paths expose only their URL-owned inert modules", async ({ asUser }) => {
+ test.setTimeout(240_000)
+ const cases: Array<[string, ExpectedFrame]> = [
+ ["/c", { route: "community-root-redirect", surface: "detail", sidebar: "me", main: "machines" }],
+ ["/c/me", { route: "me-root", surface: "list", sidebar: "me", main: "me-root" }],
+ ["/c/me/friends", { route: "me-friends", surface: "detail", sidebar: "me", main: "friends" }],
+ ["/c/me/machines", { route: "me-machines", surface: "detail", sidebar: "me", main: "machines" }],
+ ["/c/me/bots", { route: "me-bots", surface: "detail", sidebar: "me", main: "bots" }],
+ [`/c/me/${dmId}`, { route: "dm-detail", surface: "detail", sidebar: "me", main: "dm" }],
+ [`/c/channels/${serverId}`, { route: "server-root", surface: "list", sidebar: "server", main: "server-landing", serverId }],
+ [`/c/channels/${serverId}/${channelId}`, { route: "server-detail", surface: "detail", sidebar: "server", main: "server-conversation", serverId }],
+ [`/c/channels/${serverId}/settings`, { route: "server-settings-redirect", surface: "list", sidebar: "server", main: "server-landing", serverId }],
+ ["/c/me/not%5Cdm", { route: "unknown", surface: "neutral", sidebar: "none", main: "route-resolution" }],
+ ]
+
+ for (const [pathname, expected] of cases) {
+ const { context, page } = await asUser("alice")
+ await page.setViewportSize({ width: 390, height: 844 })
+ const gate = await holdSession(page)
+ const traffic = captureCommunityTraffic(page)
+ await page.goto(pathname, { waitUntil: "commit" })
+ await expect.poll(gate.hits).toBeGreaterThan(0)
+ await expectOwnedFrame(page, expected, [serverName, channelName, privateMessage])
+ expect(traffic.requests).toEqual([])
+ expect(traffic.sockets()).toBe(0)
+ if (expected.main === "server-conversation") {
+ await expect(page.getByTestId(tid.channelHeaderServerLoading)).toBeVisible()
+ await expect(page.getByRole("button", { name: "Back" })).toHaveCount(0)
+ }
+ await closeHeldContext(context, gate)
+ }
+ })
+
+ test("desktop cold frames retain all route-owned shell columns", async ({ asUser }) => {
+ test.setTimeout(120_000)
+ for (const [pathname, expected] of [
+ [`/c/me/${dmId}`, { route: "dm-detail", surface: "detail", sidebar: "me", main: "dm" }],
+ [`/c/channels/${serverId}`, { route: "server-root", surface: "list", sidebar: "server", main: "server-landing", serverId }],
+ [`/c/channels/${serverId}/${channelId}`, { route: "server-detail", surface: "detail", sidebar: "server", main: "server-conversation", serverId }],
+ ] satisfies Array<[string, ExpectedFrame]>) {
+ const { context, page } = await asUser("alice")
+ await page.setViewportSize({ width: 1280, height: 900 })
+ const gate = await holdSession(page)
+ const traffic = captureCommunityTraffic(page)
+ await page.goto(pathname, { waitUntil: "commit" })
+ await expect.poll(gate.hits).toBeGreaterThan(0)
+ await expectOwnedFrame(page, expected, [serverName, channelName, privateMessage])
+ expect(traffic.requests).toEqual([])
+ expect(traffic.sockets()).toBe(0)
+ await closeHeldContext(context, gate)
+ }
+ })
+
+ test("639↔640 preserves one pending main node with zero request or socket delta", async ({ asUser }) => {
+ test.setTimeout(120_000)
+ for (const [pathname, mainKind] of [
+ [`/c/me/${dmId}`, "dm"],
+ [`/c/channels/${serverId}/${channelId}`, "server-conversation"],
+ ] as const) {
+ const { context, page } = await asUser("alice")
+ await page.setViewportSize({ width: 639, height: 844 })
+ const gate = await holdSession(page)
+ await page.goto(pathname, { waitUntil: "commit" })
+ await expect.poll(gate.hits).toBeGreaterThan(0)
+ const main = page.getByTestId(tid.pendingMain(mainKind))
+ await expect(main).toBeVisible()
+ await main.evaluate((node) => { Reflect.set(window, "__communityInitialMain", node) })
+
+ const traffic = captureCommunityTraffic(page)
+ await page.setViewportSize({ width: 640, height: 844 })
+ await expect(main).toBeVisible()
+ expect(await main.evaluate((node) => (
+ Reflect.get(window, "__communityInitialMain") === node
+ ))).toBe(true)
+ await page.setViewportSize({ width: 639, height: 844 })
+ await expect(main).toBeVisible()
+ expect(await main.evaluate((node) => (
+ Reflect.get(window, "__communityInitialMain") === node
+ ))).toBe(true)
+ expect(traffic.requests).toEqual([])
+ expect(traffic.sockets()).toBe(0)
+ await closeHeldContext(context, gate)
+ }
+ })
+
+ test("releasing identity mounts one user-keyed shell without duplicate route work", async ({ asUser }) => {
+ test.setTimeout(120_000)
+ const { page } = await asUser("alice")
+ await page.setViewportSize({ width: 390, height: 844 })
+ const gate = await holdSession(page)
+ const traffic = captureCommunityTraffic(page)
+ await page.goto(`/c/channels/${serverId}/${channelId}`, { waitUntil: "commit" })
+ await expect.poll(gate.hits).toBeGreaterThan(0)
+ await expect(page.getByTestId(tid.pendingMain("server-conversation"))).toBeVisible()
+ expect(traffic.requests).toEqual([])
+ expect(traffic.sockets()).toBe(0)
+
+ gate.release()
+ await expect(page.getByTestId(tid.initialFrame)).toHaveCount(0, { timeout: 30_000 })
+ await expect(page.getByTestId(tid.composerInput)).toBeVisible({ timeout: 30_000 })
+ await expect.poll(traffic.sockets).toBe(1)
+ const exactMessageReads = traffic.requests.filter(({ method, pathname, search }) => (
+ method === "GET"
+ && pathname === `/api/community/channels/${channelId}/messages`
+ && search === ""
+ ))
+ await expect.poll(() => traffic.responses.filter(({ method, pathname, search, status }) => (
+ method === "GET"
+ && pathname === `/api/community/channels/${channelId}/messages`
+ && search === ""
+ && status === 200
+ )).length).toBe(1)
+ await page.waitForTimeout(200)
+ const exactMessageFailures = traffic.failures.filter(({ method, pathname, search }) => (
+ method === "GET"
+ && pathname === `/api/community/channels/${channelId}/messages`
+ && search === ""
+ ))
+ expect(exactMessageReads).toHaveLength(1 + exactMessageFailures.length)
+ expect(exactMessageFailures.every(({ error }) => error === "net::ERR_ABORTED")).toBe(true)
+ const readOnlyPostPaths = new Set([
+ "/api/community/messages/batch",
+ "/api/community/messages/tags/batch",
+ "/api/community/channels/participants/batch",
+ ])
+ expect(traffic.requests.filter(({ method, pathname }) => (
+ !["GET", "HEAD", "OPTIONS"].includes(method)
+ && !(method === "POST" && readOnlyPostPaths.has(pathname))
+ )))
+ .toEqual([])
+ })
+})