Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

fix(demos): Fix ready.js to avoid false positive before document load #2180

Merged
merged 2 commits into from
Feb 3, 2018
Merged
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
7 changes: 6 additions & 1 deletion demos/ready.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ window.demoReady = (function(root) {
var POLL_MAX_WAIT_MS = 60 * 1000;

var isReadyCached = false;
var isDomLoaded = false;
var handlers = [];
var testDom = null;
var startTimeMs = null;
Expand All @@ -38,7 +39,7 @@ window.demoReady = (function(root) {
}
ensureDetectionDom();
isReadyCached = getComputedStyle(testDom).position === 'relative' &&
(Boolean(window.mdc) || !root.querySelector('script[src*="material-components-web.js"]'));
(Boolean(window.mdc) || (isDomLoaded && !root.querySelector('script[src*="material-components-web.js"]')));
return isReadyCached;
}

Expand Down Expand Up @@ -94,6 +95,10 @@ window.demoReady = (function(root) {
handlers.length = 0;
}

root.addEventListener('DOMContentLoaded', function() {
isDomLoaded = true;
});

return function addHandler(handler) {
if (isReady()) {
handler(root);
Expand Down