Merge pull request #2 from ArnasDon/fix/supabase-client-singleton

Fix auth lock contention and empty error logs (runtime errors)
This commit is contained in:
Arnas Donauskas 2026-04-16 19:40:46 +03:00 committed by GitHub
commit b9647822ff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 2 deletions

View File

@ -54,7 +54,13 @@ export function ConversationList({
.order("last_message_at", { ascending: false });
if (error) {
console.error("Failed to fetch conversations:", error);
// Supabase errors have non-enumerable properties — log fields explicitly
console.error("Failed to fetch conversations:", {
message: error.message,
details: error.details,
hint: error.hint,
code: error.code,
});
setLoading(false);
return;
}

View File

@ -1,8 +1,18 @@
import { createBrowserClient } from '@supabase/ssr'
import type { SupabaseClient } from '@supabase/supabase-js'
// Singleton instance — one client shared across the whole browser session.
// Creating multiple clients causes auth-lock contention ("Lock was released
// because another request stole it") and intermittent fetch failures.
let browserClient: SupabaseClient | undefined
export function createClient() {
return createBrowserClient(
if (browserClient) return browserClient
browserClient = createBrowserClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!
)
return browserClient
}