From 127ad5a315d5822e5e32201b62b510c8e7a65b25 Mon Sep 17 00:00:00 2001 From: Giancarlo Buomprisco Date: Sun, 26 May 2024 14:44:43 +0700 Subject: [PATCH] Force no cache in Supabase clients with Next.js (#27) * Update navigation menu text color and disable caching in Supabase clients Updated the active and hover text colors for the navigation menu in the UI package. Also, added prevention of any sort of caching in the Supabase clients (server-actions.client.ts, route-handler.client.ts, server-component.client.ts) to be eventually removed in Next v15. Automatic token refresh is also turned off in the server-component client. * Increase content items limit in docs loader The content items limit in the documentation loader has been increased to the maximum safe integer. This ensures that all documentation entries are retrieved from the CMS, avoiding any potential omissions due to arbitrary limits. --- apps/web/app/(marketing)/docs/_lib/server/docs.loader.ts | 1 + packages/supabase/src/clients/route-handler.client.ts | 4 ++++ packages/supabase/src/clients/server-actions.client.ts | 4 ++++ packages/supabase/src/clients/server-component.client.ts | 5 +++++ packages/ui/src/makerkit/bordered-navigation-menu.tsx | 5 +++-- 5 files changed, 17 insertions(+), 2 deletions(-) diff --git a/apps/web/app/(marketing)/docs/_lib/server/docs.loader.ts b/apps/web/app/(marketing)/docs/_lib/server/docs.loader.ts index 6d4c713a6..d9e4be4d2 100644 --- a/apps/web/app/(marketing)/docs/_lib/server/docs.loader.ts +++ b/apps/web/app/(marketing)/docs/_lib/server/docs.loader.ts @@ -8,6 +8,7 @@ export const getDocs = cache(async (language: string | undefined) => { const { items: pages } = await cms.getContentItems({ collection: 'documentation', language, + limit: Number.MAX_SAFE_INTEGER, }); return pages; diff --git a/packages/supabase/src/clients/route-handler.client.ts b/packages/supabase/src/clients/route-handler.client.ts index 0728e1bbb..85ea0b079 100644 --- a/packages/supabase/src/clients/route-handler.client.ts +++ b/packages/supabase/src/clients/route-handler.client.ts @@ -1,5 +1,6 @@ import 'server-only'; +import { unstable_noStore as noStore } from 'next/cache'; import { cookies } from 'next/headers'; import type { CookieOptions } from '@supabase/ssr'; @@ -24,6 +25,9 @@ export function getSupabaseRouteHandlerClient( admin: false, }, ) { + // prevent any caching (to be removed in Next v15) + noStore(); + if (params.admin) { warnServiceRoleKeyUsage(); diff --git a/packages/supabase/src/clients/server-actions.client.ts b/packages/supabase/src/clients/server-actions.client.ts index 14be8244d..c57f479af 100644 --- a/packages/supabase/src/clients/server-actions.client.ts +++ b/packages/supabase/src/clients/server-actions.client.ts @@ -1,5 +1,6 @@ import 'server-only'; +import { unstable_noStore as noStore } from 'next/cache'; import { cookies } from 'next/headers'; import { createServerClient } from '@supabase/ssr'; @@ -25,6 +26,9 @@ function createServerSupabaseClient< export function getSupabaseServerActionClient< GenericSchema extends Database = Database, >(params?: { admin: boolean }) { + // prevent any caching (to be removed in Next v15) + noStore(); + const keys = getSupabaseClientKeys(); const admin = params?.admin ?? false; diff --git a/packages/supabase/src/clients/server-component.client.ts b/packages/supabase/src/clients/server-component.client.ts index 29aa29dc0..45a300d7a 100644 --- a/packages/supabase/src/clients/server-component.client.ts +++ b/packages/supabase/src/clients/server-component.client.ts @@ -1,5 +1,6 @@ import 'server-only'; +import { unstable_noStore as noStore } from 'next/cache'; import { cookies } from 'next/headers'; import { createServerClient } from '@supabase/ssr'; @@ -23,12 +24,16 @@ export function getSupabaseServerComponentClient( admin: false, }, ) { + // prevent any caching (to be removed in Next v15) + noStore(); + if (params.admin) { warnServiceRoleKeyUsage(); return createServerClient(keys.url, serviceRoleKey, { auth: { persistSession: false, + autoRefreshToken: false, }, cookies: {}, }); diff --git a/packages/ui/src/makerkit/bordered-navigation-menu.tsx b/packages/ui/src/makerkit/bordered-navigation-menu.tsx index 7f8a05dd3..96162b174 100644 --- a/packages/ui/src/makerkit/bordered-navigation-menu.tsx +++ b/packages/ui/src/makerkit/bordered-navigation-menu.tsx @@ -38,8 +38,9 @@ export function BorderedNavigationMenuItem(props: {