From 2ad76a4bf1318c1f7741de5a4b86df21201a6f62 Mon Sep 17 00:00:00 2001 From: sebastien Date: Mon, 2 Nov 2026 10:42:15 +0100 Subject: [PATCH] refactor: use Node.js 26 built-ins for locale calendars and the MDX processors cache (AI-assisted) - Intl.Locale: V8 14.6 removed the non-standard `calendars` getter, use `getCalendars()` - MDX processors cache: use `Map.prototype.getOrInsertComputed()` Co-Authored-By: Claude Opus 5.5 --- packages/docusaurus-mdx-loader/src/processor.ts | 10 +++------- packages/docusaurus/src/server/i18n.ts | 15 ++------------- 2 files changed, 5 insertions(+), 20 deletions(-) diff --git a/packages/docusaurus-mdx-loader/src/processor.ts b/packages/docusaurus-mdx-loader/src/processor.ts index ac311aa2c061..ded4525cb12b 100644 --- a/packages/docusaurus-mdx-loader/src/processor.ts +++ b/packages/docusaurus-mdx-loader/src/processor.ts @@ -278,13 +278,9 @@ function createProcessorsCacheEntry({ }: { options: Options; }): SimpleProcessors { - const compilers = ProcessorsCache.get(options); - if (compilers) { - return compilers; - } - const processors = createProcessors({options}); - ProcessorsCache.set(options, processors); - return processors; + return ProcessorsCache.getOrInsertComputed(options, () => + createProcessors({options}), + ); } export function getProcessor({ diff --git a/packages/docusaurus/src/server/i18n.ts b/packages/docusaurus/src/server/i18n.ts index e565453d4b3d..251495cd6bcb 100644 --- a/packages/docusaurus/src/server/i18n.ts +++ b/packages/docusaurus/src/server/i18n.ts @@ -60,19 +60,8 @@ function getDefaultCalendar(localeStr: string) { return locale.calendar; } - // Not well-supported but server code can infer a calendar from the locale - // See https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getCalendars - // See https://caniuse.com/mdn-javascript_builtins_intl_locale_getcalendars - const calendars = - locale.getCalendars?.() ?? - // @ts-expect-error: non-std attribute (V8/Chromium/Node) - locale.calendars; - - if (calendars instanceof Array && calendars[0]) { - return calendars[0]; - } - - return 'gregory'; + // Calendars are sorted by preference + return locale.getCalendars()[0] ?? 'gregory'; } function getDefaultDirection(localeStr: string) {