Skip to content
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

fixes requireJS mixins racecondition with require calls in dom #39097

Open
wants to merge 5 commits into
base: 2.4-develop
Choose a base branch
from
Open
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
12 changes: 6 additions & 6 deletions app/code/Magento/RequireJs/Block/Html/Head/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,18 +123,18 @@ protected function _prepareLayout()
$after = $staticAsset->getFilePath();
}
}
$requireJsConfig = $this->fileManager->createRequireJsConfigAsset();
$assetCollection->insert(
$requireJsConfig->getFilePath(),
$requireJsConfig,
$after
);
$requireJsMixinsConfig = $this->fileManager->createRequireJsMixinsAsset();
$assetCollection->insert(
$requireJsMixinsConfig->getFilePath(),
$requireJsMixinsConfig,
$after
);
$requireJsConfig = $this->fileManager->createRequireJsConfigAsset();
$assetCollection->insert(
$requireJsConfig->getFilePath(),
$requireJsConfig,
$after
);
return parent::_prepareLayout();
}
}
6 changes: 0 additions & 6 deletions app/code/Magento/Theme/view/base/requirejs-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,3 @@ var config = {
}
}
};

require(['jquery'], function ($) {
'use strict';

$.noConflict();
});
7 changes: 7 additions & 0 deletions lib/web/mage/requirejs/mixins.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,4 +253,11 @@ require([

return queueItem;
};

require(['jquery'], function ($) {
'use strict';

$.noConflict();
});

});
139 changes: 61 additions & 78 deletions lib/web/requirejs/require.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** vim: et:ts=4:sw=4:sts=4
* @license RequireJS 2.3.6 Copyright jQuery Foundation and other contributors.
* @license RequireJS 2.3.7 Copyright jQuery Foundation and other contributors.
* Released under MIT license, https://github.com/requirejs/requirejs/blob/master/LICENSE
*/
//Not using strict: uneven strict support in browsers, #392, and causes
Expand All @@ -11,7 +11,7 @@ var requirejs, require, define;
(function (global, setTimeout) {
var req, s, head, baseElement, dataMain, src,
interactiveScript, currentlyAddingScript, mainScript, subPath,
version = '2.3.6',
version = '2.3.7',
commentRegExp = /\/\*[\s\S]*?\*\/|([^:"'=]|^)\/\/.*$/mg,
cjsRequireRegExp = /[^.]\s*require\s*\(\s*["']([^'"\s]+)["']\s*\)/g,
jsSuffixRegExp = /\.js$/,
Expand All @@ -26,14 +26,15 @@ var requirejs, require, define;
// then 'complete'. The UA check is unfortunate, but not sure how
//to feature test w/o causing perf issues.
readyRegExp = isBrowser && navigator.platform === 'PLAYSTATION 3' ?
/^complete$/ : /^(complete|loaded)$/,
/^complete$/ : /^(complete|loaded)$/,
defContextName = '_',
//Oh the tragedy, detecting opera. See the usage of isOpera for reason.
isOpera = typeof opera !== 'undefined' && opera.toString() === '[object Opera]',
contexts = {},
cfg = {},
globalDefQueue = [],
useInteractive = false;
useInteractive = false,
disallowedProps = ['__proto__', 'constructor'];

//Could match something like ')//comment', do not lose the prefix to comment.
function commentReplace(match, singlePrefix) {
Expand Down Expand Up @@ -94,7 +95,7 @@ var requirejs, require, define;
function eachProp(obj, func) {
var prop;
for (prop in obj) {
if (hasProp(obj, prop)) {
if (hasProp(obj, prop) && disallowedProps.indexOf(prop) == -1) {
if (func(obj[prop], prop)) {
break;
}
Expand Down Expand Up @@ -359,7 +360,7 @@ var requirejs, require, define;
if (isBrowser) {
each(scripts(), function (scriptNode) {
if (scriptNode.getAttribute('data-requiremodule') === name &&
scriptNode.getAttribute('data-requirecontext') === context.contextName) {
scriptNode.getAttribute('data-requirecontext') === context.contextName) {
scriptNode.parentNode.removeChild(scriptNode);
return true;
}
Expand Down Expand Up @@ -456,8 +457,8 @@ var requirejs, require, define;
// loading of a loader plugin. But for now, fixes the
// common uses. Details in #1131
normalizedName = name.indexOf('!') === -1 ?
normalize(name, parentName, applyMap) :
name;
normalize(name, parentName, applyMap) :
name;
}
} else {
//A regular module.
Expand All @@ -479,8 +480,8 @@ var requirejs, require, define;
//normalization, stamp it with a unique ID so two matching relative
//ids that may conflict can be separate.
suffix = prefix && !pluginModule && !isNormalized ?
'_unnormalized' + (unnormalizedCounter += 1) :
'';
'_unnormalized' + (unnormalizedCounter += 1) :
'';

return {
prefix: prefix,
Expand All @@ -491,8 +492,8 @@ var requirejs, require, define;
originalName: originalName,
isDefine: isDefine,
id: (prefix ?
prefix + '!' + normalizedName :
normalizedName) + suffix
prefix + '!' + normalizedName :
normalizedName) + suffix
};
}

Expand All @@ -512,7 +513,7 @@ var requirejs, require, define;
mod = getOwn(registry, id);

if (hasProp(defined, id) &&
(!mod || mod.defineEmitComplete)) {
(!mod || mod.defineEmitComplete)) {
if (name === 'defined') {
fn(defined[id]);
}
Expand Down Expand Up @@ -974,8 +975,8 @@ var requirejs, require, define;
//prefix and name should already be normalized, no need
//for applying map config again either.
normalizedMap = makeModuleMap(map.prefix + '!' + name,
this.map.parentMap,
true);
this.map.parentMap,
true);
on(normalizedMap,
'defined', bind(this, function (value) {
this.map.normalizedMap = normalizedMap;
Expand Down Expand Up @@ -1067,10 +1068,10 @@ var requirejs, require, define;
req.exec(text);
} catch (e) {
return onError(makeError('fromtexteval',
'fromText eval for ' + id +
' failed: ' + e,
e,
[id]));
'fromText eval for ' + id +
' failed: ' + e,
e,
[id]));
}

if (hasInteractive) {
Expand Down Expand Up @@ -1117,9 +1118,9 @@ var requirejs, require, define;
//Dependency needs to be converted to a depMap
//and wired up to this module.
depMap = makeModuleMap(depMap,
(this.map.isDefine ? this.map : this.map.parentMap),
false,
!this.skipMap);
(this.map.isDefine ? this.map : this.map.parentMap),
false,
!this.skipMap);
this.depMaps[i] = depMap;

handler = getOwn(handlers, depMap.id);
Expand Down Expand Up @@ -1272,7 +1273,6 @@ var requirejs, require, define;
defQueueMap: {},
Module: Module,
makeModuleMap: makeModuleMap,
nextTick: req.nextTick,
onError: onError,

/**
Expand Down Expand Up @@ -1363,8 +1363,8 @@ var requirejs, require, define;
//envs have different conventions: some use a module name,
//some use a file name.
config.pkgs[name] = pkgObj.name + '/' + (pkgObj.main || 'main')
.replace(currDirRegExp, '')
.replace(jsSuffixRegExp, '');
.replace(currDirRegExp, '')
.replace(jsSuffixRegExp, '');
});
}

Expand Down Expand Up @@ -1434,36 +1434,29 @@ var requirejs, require, define;

if (!hasProp(defined, id)) {
return onError(makeError('notloaded', 'Module name "' +
id +
'" has not been loaded yet for context: ' +
contextName +
(relMap ? '' : '. Use require([])')));
id +
'" has not been loaded yet for context: ' +
contextName +
(relMap ? '' : '. Use require([])')));
}
return defined[id];
}

//Grab defines waiting in the global queue.
intakeDefines();

//Mark all the dependencies as needing to be loaded.
AndresInSpace marked this conversation as resolved.
Show resolved Hide resolved
context.nextTick(function () {
//Some defines could have been added since the
//require call, collect them.
intakeDefines();

requireMod = getModule(makeModuleMap(null, relMap));
requireMod = getModule(makeModuleMap(null, relMap));

//Store if map config should be applied to this require
//call for dependencies.
requireMod.skipMap = options.skipMap;
//Store if map config should be applied to this require
//call for dependencies.
requireMod.skipMap = options.skipMap;

requireMod.init(deps, callback, errback, {
enabled: true
});

checkLoaded();
requireMod.init(deps, callback, errback, {
enabled: true
});

checkLoaded();

return localRequire;
}

Expand All @@ -1489,7 +1482,7 @@ var requirejs, require, define;
}

return context.nameToUrl(normalize(moduleNamePlusExt,
relMap && relMap.id, true), ext, true);
relMap && relMap.id, true), ext, true);
},

defined: function (id) {
Expand Down Expand Up @@ -1601,9 +1594,9 @@ var requirejs, require, define;
return;
} else {
return onError(makeError('nodefine',
'No define call for ' + moduleName,
null,
[moduleName]));
'No define call for ' + moduleName,
null,
[moduleName]));
}
} else {
//A script that does not call define(), so just simulate
Expand Down Expand Up @@ -1676,7 +1669,7 @@ var requirejs, require, define;
}

return config.urlArgs && !/^blob\:/.test(url) ?
url + config.urlArgs(moduleName, url) : url;
url + config.urlArgs(moduleName, url) : url;
},

//Delegates to req.load. Broken out as a separate function to
Expand Down Expand Up @@ -1707,7 +1700,7 @@ var requirejs, require, define;
//all old browsers will be supported, but this one was easy enough
//to support and still makes sense.
if (evt.type === 'load' ||
(readyRegExp.test((evt.currentTarget || evt.srcElement).readyState))) {
(readyRegExp.test((evt.currentTarget || evt.srcElement).readyState))) {
//Reset interactive script so a script node is not held onto for
//to long.
interactiveScript = null;
Expand Down Expand Up @@ -1736,9 +1729,9 @@ var requirejs, require, define;
}
});
return onError(makeError('scripterror', 'Script error for "' + data.id +
(parents.length ?
'", needed by: ' + parents.join(', ') :
'"'), evt, [data.id]));
(parents.length ?
'", needed by: ' + parents.join(', ') :
'"'), evt, [data.id]));
}
}
};
Expand Down Expand Up @@ -1805,16 +1798,6 @@ var requirejs, require, define;
return req(config);
};

/**
* Execute something after the current tick
* of the event loop. Override for other envs
* that have a better solution than setTimeout.
* @param {Function} fn function to execute later.
*/
req.nextTick = typeof setTimeout !== 'undefined' ? function (fn) {
setTimeout(fn, 4);
} : function (fn) { fn(); };

/**
* Export require as a global, but only if it does not already exist.
*/
Expand Down Expand Up @@ -1874,8 +1857,8 @@ var requirejs, require, define;
*/
req.createNode = function (config, moduleName, url) {
var node = config.xhtml ?
document.createElementNS('http://www.w3.org/1999/xhtml', 'html:script') :
document.createElement('script');
document.createElementNS('http://www.w3.org/1999/xhtml', 'html:script') :
document.createElement('script');
node.type = config.scriptType || 'text/javascript';
node.charset = 'utf-8';
node.async = true;
Expand Down Expand Up @@ -1910,15 +1893,15 @@ var requirejs, require, define;
//UNFORTUNATELY Opera implements attachEvent but does not follow the script
//script execution mode.
if (node.attachEvent &&
//Check if node.attachEvent is artificially added by custom script or
//natively supported by browser
//read https://github.com/requirejs/requirejs/issues/187
//if we can NOT find [native code] then it must NOT natively supported.
//in IE8, node.attachEvent does not have toString()
//Note the test for "[native code" with no closing brace, see:
//https://github.com/requirejs/requirejs/issues/273
!(node.attachEvent.toString && node.attachEvent.toString().indexOf('[native code') < 0) &&
!isOpera) {
//Check if node.attachEvent is artificially added by custom script or
//natively supported by browser
//read https://github.com/requirejs/requirejs/issues/187
//if we can NOT find [native code] then it must NOT natively supported.
//in IE8, node.attachEvent does not have toString()
//Note the test for "[native code" with no closing brace, see:
//https://github.com/requirejs/requirejs/issues/273
!(node.attachEvent.toString && node.attachEvent.toString().indexOf('[native code') < 0) &&
!isOpera) {
//Probably IE. IE (at least 6-8) do not fire
//script onload right after executing the script, so
//we cannot tie the anonymous define call to a name.
Expand Down Expand Up @@ -1982,10 +1965,10 @@ var requirejs, require, define;
context.completeLoad(moduleName);
} catch (e) {
context.onError(makeError('importscripts',
'importScripts failed for ' +
moduleName + ' at ' + url,
e,
[moduleName]));
'importScripts failed for ' +
moduleName + ' at ' + url,
e,
[moduleName]));
}
}
};
Expand Down