Sitelet https://github.com/angular/angular/issues/27003
Skip to content

i18n locale methods always returns the same reference (lack of immutability)聽#27003

Description

@dzonatan

馃悶 bug report

Affected Package

The issue is caused by package @angular/common.

Description

I18n methods like getLocaleDayNames or getLocaleMonthNames (maybe there are more - haven't checked) always returns the same reference.

Let the code speak for itself:

const dayNames = getLocaleDayNames('en-US', FormStyle.Format, TranslationWidth.Short);
// dayNames = ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"]

dayNames.splice(2);
// dayNames = ["Su", "Mo"];

const freshDayNames = getLocaleDayNames('en-US', FormStyle.Format, TranslationWidth.Short);
// freshDayNames = ["Su", "Mo"]; 
// 馃檧 馃檧 馃檧 

This can lead to undesirable behaviour when some third party library modifies locale data.

馃敩 Minimal Reproduction

https://stackblitz.com/edit/angular-vbiv7d

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions