Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 1bdca93

Browse files
committed
fix(jqLite): revert the #ready() optimization until jQuery does the same
The change unfortunatelly makes us incompatible with jQuery which always falls back to onLoad. Not falling back to onLoad is a possible breaking change because if Angular was added to the document during DOMContentLoaded document.readyState at this point is 'interactive' which we'd need to add to our check, but more importantly if more scripts are added during DOMContentLoaded these won't be loaded before we bootstrap, which can cause angular modules not to be found during bootstrap. This load ordering issues is really just a cornercase that should be handled via manual bootstrap, but until jQuery has the same behavior we shouldn't do something else.
1 parent bf1a57a commit 1bdca93

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/jqLite.js

+16-3
Original file line numberDiff line numberDiff line change
@@ -454,11 +454,24 @@ function jqLiteRemove(element, keepData) {
454454
//////////////////////////////////////////
455455
var JQLitePrototype = JQLite.prototype = {
456456
ready: function(fn) {
457-
// check if document already is loaded
457+
var fired = false;
458+
459+
function trigger() {
460+
if (fired) return;
461+
fired = true;
462+
fn();
463+
}
464+
465+
// check if document is already loaded
458466
if (document.readyState === 'complete'){
459-
setTimeout(fn);
467+
setTimeout(trigger);
460468
} else {
461-
this.on('DOMContentLoaded', fn);
469+
this.on('DOMContentLoaded', trigger); // works for modern browsers and IE9
470+
// we can not use jqLite since we are not done loading and jQuery could be loaded later.
471+
// jshint -W064
472+
JQLite(window).on('load', trigger); // fallback to window.onload for others
473+
// jshint +W064
474+
this.on('DOMContentLoaded', trigger);
462475
}
463476
},
464477
toString: function() {

0 commit comments

Comments
 (0)