#28
Make conversation navigation instant after prefetch
Summary
- set the conversation title immediately from the clicked row instead of fetching the conversation once for metadata and again for the page
- remove the folder-list fetch from normal conversation navigation and reuse the list already rendered in the persistent mail shell
- cache prefetched conversation detail for 30 seconds in private browser memory, with account-scoped invalidation after mailbox writes
- start custom-folder validation and conversation detail reads in parallel; direct deep links load previous/next navigation lazily after the conversation renders
Why
The row already has the subject, so it should own the immediate title update. It does not contain full message bodies or attachments, so the conversation detail still needs one provider read.
The previous route looked parallel at the page level, but Next.js resolved dynamic metadata first. That serialized one conversation read ahead of the page's conversation + folder reads. Even after removing that lifecycle waterfall, a normal click still fetched a folder page the persistent shell already had and hover prefetch was not reusable because personalized mail was uncached.
Performance evidence
- current production first-time conversation navigation: about 1.16s
- current production provider reads: 1.09-1.17s sequentially versus 564-587ms in parallel
- local optimized production trace after this change: one RSC request on row hover/focus and zero
/mailor/api/mailrequests on click - direct hard load renders the conversation first, then fetches its navigation list lazily
- cached tab return remains about 16ms under the existing 30-second route stale time
Cache correctness
- conversation detail uses
use cache: private, so mail content is kept only in the current browser's memory and is never stored in a shared server cache - cache entries are tagged by account and invalidated after read, star, archive, move, and collection mutations
- mutations that leave a conversation perform a fresh folder navigation so stale route state cannot reintroduce removed mail
Verification
pnpm test(117 passed)pnpm exec tsc --noEmit- focused ESLint on all changed files
pnpm build- production-mode browser: title updates immediately and survives hard refresh
- production-mode browser: hover/focus prefetch is reused on click; previous/next uses the existing folder page
- production-mode browser: direct deep link restores previous/next via lazy list loading
- production-mode browser: archive returns to a fresh Inbox with the archived thread absent
- full
pnpm lintstill reports only the two pre-existingno-require-importserrors inbabel.config.jsandpostcss.config.js
Activity
7mikeyreviewed3mo ago
stylessh changed the title from Remove thread navigation waterfall to Make conversation navigation instant after prefetch3mo ago
44ab134 into main3mo ago
Review summary
Small, well-scoped diff (2 files, +7/-7). Verified against surrounding code, not just the patch.
app/.../thread/[threadId]/page.tsx— replacing the per-threadgenerateMetadata(which calledloadThreadDetail) with a staticmetadataobject is safe:loadThreadDetailis wrapped in React'scache()(lib/mail/server.ts:39), so it was already memoized per-request — the real cost was Next.js blocking page rendering untilgenerateMetadataresolved, serializing the thread fetch ahead of the folder fetch. Removing it restores true parallelism via the existingPromise.allinAccountThreadContent. Matches the PR's measured 1.09-1.17s → 564-587ms evidence.components/shell/app-shell.tsxdocument.titleeffect inThreadRouteonly — I checked whetherDraftRoute(the other consumer of this same page/metadata) loses dynamic titling. It doesn't matter:DraftRouteimmediatelyrouter.replaces away to the drafts folder in auseEffectand only ever renders a loading placeholder, so the generic "Conversation" title is never user-visible there.returnToFoldernow callsrouter.replace(...)followed byrouter.refresh(). This is not a novel pattern — the same file already usesrouter.push/replaceimmediately followed byrouter.refresh()elsewhere (lines ~691-692 send-delivery handling, ~712-713 sign-out), so the ordering is known-safe in this codebase.returnafterreturnToFolder()in theonCollectionhandler just avoids a redundant secondrouter.refresh()call now thatreturnToFolderperforms its own refresh — not a behavior change.No correctness, security, or data-integrity issues found. No test changes accompany this PR, but none of the pre-existing test suite touched
generateMetadataor these router callbacks either, so there's no coverage regression, just no new coverage for the title effect / refresh-on-mutation behavior (non-blocking).Verification performed: read the full diff,
loadThreadDetail/loadFolderPagecache definitions,ThreadRoute/DraftRoutein full, the legacy/mail/[folder]/thread/[threadId]redirect-only page (unaffected), and existingrouter.replace/push+router.refresh()call sites in the same file for precedent.