From eaa1d7432b1e8ec5c64d8e1dd6b223902dc1c232 Mon Sep 17 00:00:00 2001 From: Till JS Date: Tue, 28 Apr 2026 15:10:15 +0200 Subject: [PATCH] fix: silence two cosmetic boot-time devtools warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. /api/auth/organization/get-active-member 400 The Better-Auth org plugin returns 400 ("active organization not found") whenever the session has no activeOrganizationId yet — i.e. on every fresh inkognito login. The fetch was already tolerated (fetchActiveMember returns null on 400), but the network panel logged it as a noisy red row. Fix: gate the call on the localStorage hint. The hint is set by writeActiveSpaceHint() after every successful set-active, so its presence is a reliable proxy for "session has activeOrganizationId set". Without a hint we go straight to list + auto-activate Personal — same effective outcome, no 400. 2. Chrome "Autofocus processing was blocked" on /onboarding/name and /onboarding/wish The static `autofocus` attribute races the previous route's focus owner across the SvelteKit transition. Chrome refuses to honour autofocus when a document already has a focused element and warns. Fix: replace the attribute with `bind:this={el}` + a $effect that imperatively `el.focus()`s after `tick()` — by then the outgoing page has unmounted and there's no competing focus claim. The svelte-ignore directives are no longer needed and have been removed. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../src/lib/data/scope/active-space.svelte.ts | 46 ++++++++++++------- .../routes/(app)/onboarding/name/+page.svelte | 13 +++++- .../routes/(app)/onboarding/wish/+page.svelte | 16 ++++++- 3 files changed, 55 insertions(+), 20 deletions(-) diff --git a/apps/mana/apps/web/src/lib/data/scope/active-space.svelte.ts b/apps/mana/apps/web/src/lib/data/scope/active-space.svelte.ts index 41aeaff68..351171069 100644 --- a/apps/mana/apps/web/src/lib/data/scope/active-space.svelte.ts +++ b/apps/mana/apps/web/src/lib/data/scope/active-space.svelte.ts @@ -186,13 +186,22 @@ export function writeActiveSpaceHint(id: string | null): void { /** * Resolve the user's active space. Order of truth: - * 1. Server-side active member (get-active-member) — trustworthy when - * Better Auth's activeOrganizationId landed in the session. - * 2. Client-side hint from localStorage — survives cookie drops across - * page reloads in dev. If present, we call set-active to re-sync - * the server to match. + * 1. **Localstorage hint present** — we've already gone through the + * list+set-active flow on this device, so `get-active-member` is + * certain to return 200 (Better Auth's session has an + * activeOrganizationId). Call it as the source of truth (reflects + * cross-tab switches the user may have made elsewhere). + * 2. **No hint** — fresh session. `get-active-member` would return + * 400 ("active organization not found") because nothing has been + * set yet. Skip the call entirely so the network panel stays clean, + * and go straight to list + activate-Personal-or-localStorage-hint. * 3. Personal space fallback — brand-new session, no previous choice. * + * The skip-on-fresh-session optimisation eliminates the noisy 400 the + * webapp used to log on every fresh inkognito login. Functionally + * equivalent — `fetchActiveMember()` returned `null` on 400 anyway and + * we fell through to the same auto-activate path. + * * Errors captured in `lastError`; status flips to 'error'. Callers can * retry via `loadActiveSpace({ force: true })`. */ @@ -203,20 +212,25 @@ export async function loadActiveSpace(opts: { force?: boolean } = {}): Promise o.id === hintId) : null; const chosen = hinted ?? orgs.find((o) => o.type === 'personal') ?? null; diff --git a/apps/mana/apps/web/src/routes/(app)/onboarding/name/+page.svelte b/apps/mana/apps/web/src/routes/(app)/onboarding/name/+page.svelte index 748b700b8..515126aa3 100644 --- a/apps/mana/apps/web/src/routes/(app)/onboarding/name/+page.svelte +++ b/apps/mana/apps/web/src/routes/(app)/onboarding/name/+page.svelte @@ -6,6 +6,7 @@ -->