segmentio / segmentio/analytics.js-integrations

Promise.prototype.finally not defined in MS Edge due to replacement in @segment/tracktor module

Open
#480 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
125
Forks
136
Avg merge
2h 45m
Merged PRs (30d)
1

Description

Something in the @segment/tracktor module has a dependency on an old version of core-js where Promise.prototype.finally is not defined. In Microsoft Edge, the native Promise object gets replaced by the core-js version which can cause things to break if code depends on using finally

This is a related issue where the core-js author references the fact that v2 or less does not implement Promise#finally in its polyfill (see: https://github.com/zloirock/core-js/blob/v2/modules/es6.promise.js)

To reproduce, in the @segment/tracktor project, in the build/index.html file, replace the line <script type="text/javascript" src="tracktor.js"></script> with:

<script>
  console.log('running native Promise#finally')
  Promise.resolve(true).finally(() =>
    console.log('Promise#finally executed')
  )
</script>
<script type="text/javascript" src="tracktor.js"></script>
<script>
  document
    .getElementById('dynamic-btn')
    .addEventListener('click', function () {
      console.log('button clicked')
      console.log('Promise#finally no longer here')
      console.log(Promise.prototype.finally)
      Promise.resolve(true).finally(() => console.log('this will not run'))
    })
</script>

and run on Edge.

image

What I'm guessing is happening is:

  1. @babel/preset-env@7.4.5 depends on core-js-compat@3.1.1
  2. core-js-compat tells @babel/preset-env to include things from core-js
  3. @babel/preset-env finds an included core-js installed
    a. wait-on@3.3.0 depends on core-js@2.6.5
    b. jest-dev-server@4.3.0 depends on wait-on@3.3.0
  4. @babel/preset-env injects the core-js@2.6.5 polyfills it determines are needed based on the defined targets and built ins

@babel/preset-env emits a warning about this here: https://github.com/babel/babel/blob/c5ba345ac26d90fb5da8954f00f5c7285ee5ada8/packages/babel-preset-env/src/normalize-options.js#L220

I think this can be alleviated by explicitly defining a dependency on core-js@^3.6.5

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue in the @segment/tracktor project using build/index.html and Microsoft Edge, then inspect the dependency chain involving @babel/preset-env, core-js-compat, wait-on, and jest-dev-server. Done means loading tracktor.js no longer removes Promise.prototype.finally and the provided click-handler reproduction succeeds.

Written by the indexing model from the issue text.

Assessment

Tech stack
babel, javascript
Domain
web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.