{"version":3,"file":"warmDynamicLocale.mjs","names":[],"sources":["../../../src/client/warmDynamicLocale.ts"],"sourcesContent":["import { preloadDynamic } from './useLoadDynamic';\n\n/** Starts the loads one rendered dictionary needs for a given locale. */\nexport type DynamicLocaleWarmer = (locale: string) => void;\n\n/** One warmer per dictionary key rendered so far through the dynamic path. */\nconst warmers = new Map<string, DynamicLocaleWarmer>();\n\n/**\n * Records how to preload a rendered dictionary for any locale, so a later\n * locale switch can start all of them at once.\n *\n * @param key - Dictionary key; a later call for the same key replaces it.\n * @param warmer - Starts the dictionary's chunk loads for a locale.\n */\nexport const registerDynamicLocaleWarmer = (\n  key: string,\n  warmer: DynamicLocaleWarmer\n): void => {\n  warmers.set(key, warmer);\n};\n\n/**\n * Starts loading, in parallel, every registered dictionary for `locale`.\n *\n * Called on the first cache miss of a render: without it, a renderer that\n * stops at the first suspended component (Redact, or React without sibling\n * prerendering) discovers one chunk per retry and waterfalls the whole page.\n * Client-only, since a server render would load every locale it ever served.\n *\n * @param locale - The locale the render is missing.\n */\nexport const warmDynamicLocale = (locale: string): void => {\n  if (typeof window === 'undefined') return;\n\n  for (const warmer of warmers.values()) {\n    warmer(locale);\n  }\n};\n\n/**\n * Builds a warmer that preloads one chunk per cache key.\n *\n * @param getChunks - Lists the chunks (cache key + loader) needed for a locale.\n * @returns A warmer filling the `useLoadDynamic` suspender cache.\n */\nexport const createDynamicLocaleWarmer =\n  (\n    getChunks: (\n      locale: string\n    ) => { cacheKey: string; loader: () => Promise<unknown> }[]\n  ): DynamicLocaleWarmer =>\n  (locale) => {\n    for (const { cacheKey, loader } of getChunks(locale)) {\n      // Rejections stay in the cache; the render that reads it surfaces them.\n      void preloadDynamic(cacheKey, loader);\n    }\n  };\n"],"mappings":";;;;AAMA,MAAM,0BAAU,IAAI,IAAiC;;;;;;;;AASrD,MAAa,+BACX,KACA,WACS;CACT,QAAQ,IAAI,KAAK,MAAM;AACzB;;;;;;;;;;;AAYA,MAAa,qBAAqB,WAAyB;CACzD,IAAI,OAAO,WAAW,aAAa;CAEnC,KAAK,MAAM,UAAU,QAAQ,OAAO,GAClC,OAAO,MAAM;AAEjB;;;;;;;AAQA,MAAa,6BAET,eAID,WAAW;CACV,KAAK,MAAM,EAAE,UAAU,YAAY,UAAU,MAAM,GAEjD,AAAK,eAAe,UAAU,MAAM;AAExC"}