Skip to content

Upgrade core-js to v3.1.3 and enable URL polyfill

Paul Gascou-Vaillancourt requested to merge upgrade-core-js into master

What does this MR do?

  • core-js has been upgraded to v3.1.3
  • import statements have been updated to reflect core-js' new structure
  • URL() polyfill has been enabled

Why is this needed?

In gitlab-ee, the isSafeUrl utility attempts to create an URL instance with a fall back on an <a> element for IE11. This doesn't seem to work as expected because the resulting parsedUrl won't have the required protocol property on IE11, thus causing all URLs to be considered unsafe.

By polyfilling URL, we'll be able to remove the try/catch from the utility and rely solely on the URL instance whatever the browser.

That polyfill was first introduced in core-js@3.0.0.

How to test this?

To make sure core-js polyfills still work after the upgrade, each polyfilled method can be tested by appending the following code to app/assets/javascripts/commons/polyfills.js:

const array = [1, 2, 3, 4];
console.log(array.fill(0, 2, 4));
console.log(array.find(v => v === 2));
console.log(array.findIndex(v => v === 2));
console.log(Array.from('foo'));
console.log(array.includes(2));

const obj1 = { foo: 'bar' };
const obj2 = { sponge: 'bob' };
const obj3 = Object.assign({}, obj1, obj2);
console.log(obj3);
console.log(Object.values(obj3));
console.log(Object.entries(obj3));

const promise = new Promise(resolve => {
  resolve('Promise resolved!');
});
promise
  .then(data => {
    console.log(data);
  })
  .catch(() => {
    console.log('fail');
  })
  .finally(() => {
    console.log('finally');
  });

const icons = '☃★♲';
console.log(icons.codePointAt(1));
console.log(String.fromCodePoint(9731, 9733, 9842, 0x2f804));

const string = 'fuzzbuzzbizz';
console.log(string.includes('buzz'));

const symbol = Symbol('s');
console.log(typeof symbol);

const map = new Map();
const mapKey = 'foo';
map.set(mapKey, 'map value');
console.log(map.get(mapKey));

const weakMap = new WeakMap();
const weakMapKey = {};
weakMap.set(weakMapKey, 'weak map value');
console.log(weakMap.get(weakMapKey));

console.log(new URL('https://gitlab.com/'));

This is confirmed to work on IE11.

Does this MR meet the acceptance criteria?

Conformity

Performance and testing

Edited by Paul Gascou-Vaillancourt

Merge request reports