Skip to content

Stable ES features are not always polyfilled when needed #8875

Closed

Description

@skoging

Describe the bug

Even with import 'react-app-polyfill/stable', some stable ES features are not polyfilled, such as String#matchAll.

Even importing String#matchAll directly from core-js does not work: import 'core-js/stable/string/match-all'

https://caniuse.com/#feat=mdn-javascript_builtins_string_matchall

Steps to reproduce

(Write your steps here:)

yarn create react-app polyfill-bug
cd polyfill-bug
yarn add react-app-polyfill
// index.js
import 'react-app-polyfill/ie11'
import 'react-app-polyfill/stable'
import 'core-js/stable/string/match-all'

const matches = 'some test string'.matchAll(/s(.)/g);
// IE11 or Safari:
// Error: Object doesn't support property or method 'matchAll'

console.log(Array.from(matches))
// [["te", "e"], ["t ", " "], ["tr", "r"]]

Expected behavior

Polyfill for stable ES features should be part of the bundle when importing react-app-polyfill/stable.

In the case it isn't, explicitly importing the polyfill for the feature should work.

Activity

  1. skoging commented on Apr 22, 2020

    @skoging
    ContributorAuthor

    I believe the issue is a mismatch between the core-js dependency version: ^3.5.0 and the babel preset-env option corejs: 3.

    core-js recommends specifying the minor version in the preset-env options: corejs: '3.6' to make sure stable features added in minor versions are correctly handled.

    This description matches the behavior seen in this issue, and a local edit of the babel preset in node_modules/babel-preset-react-app/create.js confirmed that this change fixes the problem.

    The easy solution is to change the preset-env option to specify the minor version, both 3.5 an 3.6 worked with String#matchAll when I tested it. Seeing as these settings are in different packages (react-app-polyfill and babel-preset-react-app) that don't depend on each other, I'm not sure what the best approach to keeping these versions in sync is.

  2. Mrman commented on Apr 24, 2020

    @Mrman

    This would close #8779 too :)

  3. stale commented on May 24, 2020

    @stale

    This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.

  4. stale commented on May 30, 2020

    @stale

    This issue has been automatically closed because it has not had any recent activity. If you have a question or comment, please open a new issue.

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

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions