Skip to content

Commit 577b5ff

Browse files
committed
don't rely on time
1 parent 14fe016 commit 577b5ff

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

web_src/js/init.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
// This script is for critical JS that needs to run as soon as possible.
2-
// Do not import any dependencies and keep to vanilla JS only.
2+
3+
let attempts = 0;
4+
requestAnimationFrame(function wait() {
5+
if (document.querySelector('script[src*="index.js"]') || ++attempts > 100) return init();
6+
requestAnimationFrame(wait);
7+
});
38

49
// This function runs before DOMContentLoaded and checks if most of the page
510
// has loaded so we can do DOM mutations before anything is painted on the screen.
6-
requestAnimationFrame(function init(elapsed) {
7-
if (elapsed > 10000) return;
8-
if (!document.querySelector('script[src*="index.js"]')) return requestAnimationFrame(init);
9-
11+
function init() {
1012
// Synchronously set clone button states and urls here to avoid flickering
1113
// on page load. initRepoCloneLink calls this when proto changes.
1214
// this applies the protocol-dependant clone url to all elements with the
@@ -32,4 +34,4 @@ requestAnimationFrame(function init(elapsed) {
3234
el.href = `vscode://vscode.git/clone?url=${encodeURIComponent(link)}`;
3335
}
3436
})();
35-
});
37+
}

0 commit comments

Comments
 (0)