#24
Add persistent account sessions and instant workspace navigation
Summary
- enable Better Auth multi-session account switching while preserving existing device sessions
- replace route skeleton flashes with a persistent mail shell and Next.js 16.3 partial prefetching
- keep user preferences and theme synchronized across cached inbox and settings route trees
- make the non-sensitive theme cookie available to the pre-hydration theme script
- prefetch inbox tabs on mount and mail or tab destinations on hover or keyboard focus
- keep workspace tabs stable, reorderable, and persistent, with icon-led bulk close actions
- preserve the original rounded tab connectors while removing the one-pixel seam
- scaffold safe local defaults and generated auth secrets for
pnpm dev:livewhen.envvalues are absent
Validation
pnpm test— 88 passed- changed-file ESLint — passed
pnpm exec tsc --noEmit— passedpnpm build— passed with Cache Components and Partial Prefetching enabledgit diff --check origin/main...HEAD— passed- manual browser coverage for account switching, shell hydration, navigation prefetching, tab order, drag and keyboard reorder, context-menu actions, persistence, and connector rendering in light and dark themes
- browser-verified Light → Dark → Inbox and Dark → Light → Inbox without a hard refresh; the pre-hydration theme cookie is readable
Known repository check
pnpm lintstill reports the two pre-existing CommonJSrequire()violations inbabel.config.jsandpostcss.config.js; changed files pass ESLint.
Activity
6mikeyreviewed3mo ago
c0a99dc into main3mo ago
Reviewed the diff against
main(auth/session flow, persistent shell + prefetching, workspace tab persistence/reorder, and thedev:liveenv scaffolding script).Auth / multi-session (
lib/auth.ts,lib/preserve-current-session.ts,components/auth/account-sessions.tsx,lib/auth-client.ts)preserveCurrentSession()correctly guards onctx.context.sessionand signs the preserved cookie viactx.setSignedCookie, matching the pattern the built-inmultiSessionplugin uses for its own device-session cookies.better-authis pinned to^1.7.2, which is well past the1.4.0fix for the multi-session sign-out forged-cookie advisory (GHSA-wmjr-v86c-m9jj), so the "Sign out all accounts" flow (authClient.signOut()) is on a patched, non-vulnerable release.AccountSessionMenuGroupcorrectly filterscurrentUser.idout of the listed device sessions and disables switching while a switch is in flight (busyToken).lib/multi-session.test.mjs, which exercises the "pre-plugin session preserved, then switched" path end-to-end against a realbetterAuth()instance.Persistent shell / prefetching (
app-shell.tsx,mail-hydration-shell.tsx,mail-account-shell.tsx, layout changes)body > [data-mail-shell]selectormail-hydration-shell.tsxdepends on actually holds: none ofRootLayout,MailLayout, orAccountLayoutContentinsert a wrapping DOM element between<body>and theAppShellroot div, so the loading-skeleton/shell-swap logic inapp/globals.css(body:has(> [data-mail-shell]) > [data-mail-shell-loading]) will fire as intended.AppShellis instantiated once per account layout and folder pages render aschildren, which is what makes the shell persistent across folder/thread navigation rather than remounting per route — matches the PR's stated goal.useWorkspaceTabs's localStorage sync (useSyncExternalStore+storage/custom-event listeners) has a sane in-memory fallback (workspaceTabsFallback) whenlocalStoragethrows (private mode / quota).Workspace tabs (
lib/mail/workspace-tabs.ts,components/shell/workspace-tabs.tsx)validTab()restricts restored tabhrefs to same-origin/mail/-prefixed paths and rejects//-prefixed values, which prevents a poisonedlocalStorageentry from turning into an open redirect/XSS vector through the rendered<Link>.lib/mail/workspace-tabs.test.mjsfor parse/serialize round-tripping, corrupt-entry rejection, reorder, and close-action semantics.Dev tooling (
scripts/scaffold-env.sh,scripts/dev-live.sh).envis written via amktemp+chmod 600+ atomicmv, and the secret is produced withcrypto.randomBytes(32), so this doesn't introduce a local secrets-handling regression. Dev-only, not part of the production path.No blocking correctness or security issues found in this pass. Validation claims in the PR body (tests, tsc, lint, build) are consistent with what's covered by the touched files.