#24

Add persistent account sessions and instant workspace navigation

MergedstylesshOwnermerged intofrom

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:live when .env values are absent

Validation

  • pnpm test — 88 passed
  • changed-file ESLint — passed
  • pnpm exec tsc --noEmit — passed
  • pnpm build — passed with Cache Components and Partial Prefetching enabled
  • git 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 lint still reports the two pre-existing CommonJS require() violations in babel.config.js and postcss.config.js; changed files pass ESLint.

Activity

6
mikeyreviewed3mo ago
mikey3mo ago

Reviewed the diff against main (auth/session flow, persistent shell + prefetching, workspace tab persistence/reorder, and the dev:live env 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 on ctx.context.session and signs the preserved cookie via ctx.setSignedCookie, matching the pattern the built-in multiSession plugin uses for its own device-session cookies.
  • better-auth is pinned to ^1.7.2, which is well past the 1.4.0 fix 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.
  • AccountSessionMenuGroup correctly filters currentUser.id out of the listed device sessions and disables switching while a switch is in flight (busyToken).
  • Covered by lib/multi-session.test.mjs, which exercises the "pre-plugin session preserved, then switched" path end-to-end against a real betterAuth() instance.

Persistent shell / prefetching (app-shell.tsx, mail-hydration-shell.tsx, mail-account-shell.tsx, layout changes)

  • Verified the body > [data-mail-shell] selector mail-hydration-shell.tsx depends on actually holds: none of RootLayout, MailLayout, or AccountLayoutContent insert a wrapping DOM element between <body> and the AppShell root div, so the loading-skeleton/shell-swap logic in app/globals.css (body:has(> [data-mail-shell]) > [data-mail-shell-loading]) will fire as intended.
  • AppShell is instantiated once per account layout and folder pages render as children, 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) when localStorage throws (private mode / quota).

Workspace tabs (lib/mail/workspace-tabs.ts, components/shell/workspace-tabs.tsx)

  • validTab() restricts restored tab hrefs to same-origin /mail/-prefixed paths and rejects //-prefixed values, which prevents a poisoned localStorage entry from turning into an open redirect/XSS vector through the rendered <Link>.
  • Good unit coverage in lib/mail/workspace-tabs.test.mjs for parse/serialize round-tripping, corrupt-entry rejection, reorder, and close-action semantics.

Dev tooling (scripts/scaffold-env.sh, scripts/dev-live.sh)

  • Generated .env is written via a mktemp + chmod 600 + atomic mv, and the secret is produced with crypto.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.

stylessh merged commit c0a99dc into main3mo ago

Branch stylessh/account-sessions-instant-navigation has been merged.

Checking branch