Skip to content

intl-displaynames shouldPolyfill incorrectly indicates that polyfill is required #5889

Closed as not planned

Description

@pvdstel

Which package?

@formatjs/intl-displaynames version 7.1.2 (latest at time of writing)

Describe the bug

The shouldPolyfill function (source) returns a truthy value ('en', if no arguments are specified), even though the browser I am using fully supports Intl.DisplayNames.

This happens because the function decides that Chrome has a script bug (hasScriptBug). It does this by checking what the return value of new DisplayNames(['en'], { type: 'script' }).of('arab') is.

While this check works fine in Firefox, in Chrome this check appears to be case sensitive. The string 'arab' produces 'arab' whereas 'Arab' produces 'Arabic'. The same is true for (for example) 'maya' which gives 'maya' whereas 'Maya' gives 'Mayan hieroglyphs'.

The Unicode code list specifies these script codes with uppercase letters. Would it be sensible to use 'Arab' instead of 'arab' here?

This causes polyfills to be loaded unnecessarily in the site.

> new Intl.DisplayNames(["en"], { type: "script" }).of("arab")
< 'arab'
> new Intl.DisplayNames(["en"], { type: "script" }).of("Arab")
< 'Arabic'
Image

To Reproduce

I am running this in Chrome 143, which as of this writing is the most up-to-date release.

Reproducible Steps/Repo

Steps to reproduce the behavior:

  1. Run the following code:
    import { shouldPolyfill as shouldPolyfillDisplayNames } from '@formatjs/intl-displaynames/should-polyfill.js';
    
    console.log(shouldPolyfillDisplayNames()); // prints 'en' in Chrome, undefined in Firefox

Desktop (please complete the following information):

  • OS: Windows 11
  • Browsers: Chrome / Edge 143 (latest at time of writing); Firefox 148 (beta at time of writing; not affected).
  • Package version: 7.1.2

Expected behavior

I expect shouldPolyfill to return a falsy value in browsers that fully support the Intl.DisplayNames API. This could be solved by using 'Arab' instead of 'arab'. However, I don't know if this is the right way to approach this problem, so I'm opening an issue instead of creating a pull request.

Activity

  1. longlho commented on Jan 14, 2026

    @longlho
    Member

    Thanks for reporting. Looks like the spec canonicalize code to be title case. We'll take a look

    Image
  2. longlho commented on Jan 15, 2026

    @longlho
    Member

    So this is indeed a Chrome bug still, according to https://tc39.es/ecma402/#sec-Intl.DisplayNames.prototype.of

    4. Set code to ? [CanonicalCodeForDisplayNames](https://tc39.es/ecma402/#sec-canonicalcodefordisplaynames)(displayNames.[[Type]], code).
    5. Let fields be displayNames.[[Fields]].
    

    so browser's supposed to canonicalize arab to Arab before lookup, but it's not. This is why it's returning arab instead of Arabic

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions