From 7ddd0feb0feb2250cd5d844b09b18ddc23723c71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20Ign=C3=A1cio=20Fontoura=20Solla?= Date: Sun, 19 Jul 2026 04:27:04 -0300 Subject: [PATCH] Fix getCachedGlobal typing so production builds typecheck again. The Onda 0 factory Map erased Slug generics to any, breaking keyword/social metadata inference during next build. --- src/utilities/globals.ts | 16 ++++++++++------ src/utilities/supporterPageData.ts | 13 ++++++++----- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/utilities/globals.ts b/src/utilities/globals.ts index 3274f23b..d9237090 100644 --- a/src/utilities/globals.ts +++ b/src/utilities/globals.ts @@ -19,16 +19,20 @@ export async function getGlobal(slug: Slug, depth?: number) const getTag = (slug: string) => `global_${slug}` -const cachedGlobalFactories = new Map>() +type CachedGlobalFactory = () => Promise + +const cachedGlobalFactories = new Map() export const getCachedGlobal = (slug: Slug, depth?: number) => { const tag = getTag(slug) const cacheKey = `${tag}:${depth ?? 0}` - let factory = cachedGlobalFactories.get(cacheKey) - if (!factory) { - factory = unstable_cache(async () => getGlobal(slug, depth), [cacheKey], { tags: [tag] }) - cachedGlobalFactories.set(cacheKey, factory) - } + const existing = cachedGlobalFactories.get(cacheKey) as CachedGlobalFactory | undefined + if (existing) return existing + + const factory = unstable_cache(async () => getGlobal(slug, depth), [cacheKey], { + tags: [tag], + }) as CachedGlobalFactory + cachedGlobalFactories.set(cacheKey, factory as CachedGlobalFactory) return factory } diff --git a/src/utilities/supporterPageData.ts b/src/utilities/supporterPageData.ts index 6193c5e4..6b3e42bf 100644 --- a/src/utilities/supporterPageData.ts +++ b/src/utilities/supporterPageData.ts @@ -52,12 +52,14 @@ const nucleusOptionsSelect = { slug: true, } as const +type NucleusOptionDoc = Pick + export const loadAccessibleNucleusOptions = async ( payload: Pick, user: CampaignUser, coordinatorNucleusIds?: number[], ): Promise => { - let result: { docs: ElectoralNucleus[] } + let result: { docs: NucleusOptionDoc[] } if (user.role === 'coordenador' && coordinatorNucleusIds !== undefined) { if (coordinatorNucleusIds.length === 0) return [] @@ -86,10 +88,11 @@ export const loadAccessibleNucleusOptions = async ( }) } - return result.docs.map((nucleus) => { - const doc = nucleus as ElectoralNucleus - return { id: doc.id, name: doc.name, slug: doc.slug } - }) + return result.docs.map((nucleus) => ({ + id: nucleus.id, + name: nucleus.name, + slug: nucleus.slug, + })) } export const loadSupporterListPageData = async (