Skip to content

Commit

Permalink
ENGCOM-7285: [PERF Improvements]Load polyfills for browsers that don'…
Browse files Browse the repository at this point in the history
…t support certain features #27618
  • Loading branch information
slavvka authored May 29, 2020
2 parents b1b1d99 + 0a39260 commit 526d6a0
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 10 deletions.
27 changes: 27 additions & 0 deletions app/code/Magento/Ui/view/base/requirejs-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

var config = {
deps: [],
shim: {
'chartjs/Chart.min': ['moment'],
'tiny_mce_4/tinymce.min': {
Expand All @@ -30,3 +31,29 @@ var config = {
}
}
};

/**
* Adds polyfills only for browser contexts which prevents bundlers from including them.
*/
if (typeof window !== 'undefined' && window.document) {
/**
* Polyfill Map and WeakMap for older browsers that do not support them.
*/
if (typeof Map === 'undefined' || typeof WeakMap === 'undefined') {
config.deps.push('es6-collections');
}

/**
* Polyfill MutationObserver only for the browsers that do not support it.
*/
if (typeof MutationObserver === 'undefined') {
config.deps.push('MutationObserver');
}

/**
* Polyfill FormData object for old browsers that don't have full support for it.
*/
if (typeof FormData === 'undefined' || typeof FormData.prototype.get === 'undefined') {
config.deps.push('FormData');
}
}
3 changes: 1 addition & 2 deletions app/code/Magento/Ui/view/base/web/js/lib/core/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
/* global WeakMap, Map*/
define([
'ko',
'underscore',
'es6-collections'
'underscore'
], function (ko, _) {
'use strict';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ define([
'ko',
'underscore',
'mage/utils/wrapper',
'uiEvents',
'es6-collections'
'uiEvents'
], function (ko, _, wrapper, Events) {
'use strict';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
/* global WeakMap */
define([
'jquery',
'underscore',
'es6-collections'
'underscore'
], function ($, _) {
'use strict';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
define([
'jquery',
'underscore',
'MutationObserver',
'domReady!'
], function ($, _) {
'use strict';
Expand Down
4 changes: 1 addition & 3 deletions app/code/Magento/Ui/view/base/web/js/lib/view/utils/raf.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
*/

/* global WeakMap */
define([
'es6-collections'
], function () {
define([], function () {
'use strict';

var processMap = new WeakMap(),
Expand Down

0 comments on commit 526d6a0

Please sign in to comment.