Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion src/app/__tests__/not-found.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@ import { render, screen } from "@testing-library/react"
* not "Profile not found" (Greptile on #267).
*/

const { pathname, lookupActor, lookupRecord } = vi.hoisted(() => ({
const { pathname, lookupActor, lookupRecord, resolveHandle } = vi.hoisted(() => ({
pathname: { value: "" },
lookupActor: vi.fn(),
lookupRecord: vi.fn(),
resolveHandle: vi.fn(),
}))
vi.mock("next/headers", () => ({
headers: async () => new Headers({ "x-pathname": pathname.value }),
}))
vi.mock("@/lib/og-metadata", () => ({ lookupActor, lookupRecord }))
vi.mock("@/lib/atproto/did", () => ({ resolveHandle }))

import NotFoundPage from "../not-found"

Expand All @@ -28,6 +30,7 @@ async function renderAt(path: string) {
beforeEach(() => {
lookupActor.mockReset().mockResolvedValue({ status: "found", did: "did:plc:alice", handle: "alice.example.com" })
lookupRecord.mockReset().mockResolvedValue({ uri: "", value: {} })
resolveHandle.mockReset().mockResolvedValue(null)
})

describe("not-found page", () => {
Expand All @@ -49,6 +52,24 @@ describe("not-found page", () => {
)
})

it("a DID-addressed missing record links the profile by its handle", async () => {
lookupActor.mockResolvedValue({ status: "found", did: "did:plc:alice", handle: null })
lookupRecord.mockResolvedValue("missing")
resolveHandle.mockResolvedValue("alice.example.com")
await renderAt("/did:plc:alice/activity/3abc")
expect(screen.getByRole("link", { name: "View @alice.example.com" }).getAttribute("href")).toBe(
"/alice.example.com",
)
})

it("falls back to the DID when the handle can't be resolved", async () => {
lookupActor.mockResolvedValue({ status: "found", did: "did:plc:alice", handle: null })
lookupRecord.mockResolvedValue("missing")
resolveHandle.mockRejectedValue(new Error("down"))
await renderAt("/did:plc:alice/activity/3abc")
expect(screen.getByRole("link", { name: "View @did:plc:alice" })).toBeTruthy()
})

it("a missing record's edit page is a missing record too", async () => {
lookupRecord.mockResolvedValue("missing")
expect(await renderAt("/alice.example.com/activity/3abc/edit")).toBe("Activity not found")
Expand Down
8 changes: 7 additions & 1 deletion src/app/not-found.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { FileQuestion, UserX } from "lucide-react";
import Button from "@/components/ui/button";
import EmptyState from "@/components/ui/empty-state";
import NotFoundMarker from "@/components/layout/not-found-marker";
import { resolveHandle } from "@/lib/atproto/did";
import { lookupActor, lookupRecord } from "@/lib/og-metadata";
import {
collectionForType,
Expand Down Expand Up @@ -45,7 +46,12 @@ async function whatIsMissing(pathname: string | null): Promise<Missing> {
const [, type, rkey] = segments;
if (segments.length >= 3 && isRecordType(type) && rkey) {
const record = await lookupRecord(resolved.did, collectionForType(type), rkey);
if (record === "missing") return { kind: "record", actor: actor.value, type };
if (record === "missing") {
// A DID-addressed link still names the profile by its handle.
const handle =
resolved.handle ?? (await resolveHandle(resolved.did).catch(() => null));
return { kind: "record", actor: handle ?? actor.value, type };
Comment on lines +51 to +53

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Slow lookup removes profile link

If resolveHandle outlasts the remaining 3-second budget, the page discards the already-confirmed missing record. It shows “Page not found” without the profile link instead of falling back to the DID. Keep the known record result when the optional handle lookup times out, and add a stalled-lookup test.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/app/not-found.tsx
Line: 51-53

Comment:
**Slow lookup removes profile link**

If `resolveHandle` outlasts the remaining 3-second budget, the page discards the already-confirmed missing record. It shows “Page not found” without the profile link instead of falling back to the DID. Keep the known record result when the optional handle lookup times out, and add a stalled-lookup test.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Claude Code Fix in Codex

}
}
return null;
}
Expand Down
Loading