Skip to content

[PERF Improvements]Load polyfills for browsers that don't support certain features #27618

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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