Skip to content

fix: preserve instance scope when resolving fallback locales - #3189

Open
OskarEichler wants to merge 1 commit into
iamkun:devfrom
OskarEichler:codex/locale-isolation
Open

fix: preserve instance scope when resolving fallback locales#3189
OskarEichler wants to merge 1 commit into
iamkun:devfrom
OskarEichler:codex/locale-isolation

Conversation

@OskarEichler

Copy link
Copy Markdown

Fixes

  • Keep regional locale fallback local when invoked through an instance or a local-only locale lookup. dayjs().locale('en-US') must not change the global locale from fr to en.
  • Keep construction safe when a requested locale is unavailable: use the current global locale rather than leaving $L undefined. This preserves the previous unknown-regional fallback and also handles unsupported non-regional constructor locales consistently.

The recursive parseLocale call previously dropped isLocal. Forwarding it fixes the global mutation; the constructor fallback prevents a new formatting failure when neither the region nor its base language is registered.

Reproduction

const dayjs = require('dayjs')
require('dayjs/locale/fr')
dayjs.locale('fr')
dayjs('2026-08-27').locale('en-US')
console.log(dayjs.locale()) // before: en; after: fr

Compatibility

No public API, type, dependency, or minimum-runtime changes. Explicit global dayjs.locale('en-US') still changes the global locale. Existing instances and date values remain unchanged. Unknown instance-local locales retain that instance's locale. Code relying on the accidental global mutation must call the global setter explicitly; unsupported constructor locales now safely use the global default.

Verification

  • All 794 existing tests in 93 suites; 100% line coverage.
  • Existing timezone and timezone-plugin matrices (eight runs).
  • Lint, all 40 declaration files, ESM/UMD/plugin/locale builds, and size limit.
  • 29 focused source checks covering regional/case/unknown locales, construction, local/global registration, immutability, UTC, relative time, and custom-format parsing followed by locale selection.
  • Repeated the existing suite and builds on release 1.11.23 with the backport.

No test files were added or modified. The old size-limit Webpack dependency needs NODE_OPTIONS=--openssl-legacy-provider under Node 22; that was a verification-only setting, not a package change. Existing Handlebars coverage-report and Kurdish mixed-export warnings remain. CustomParseFormat's separate direct regional-language lookup is unchanged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant