Skip to content

Commit f9b868c

Browse files
committed
Support async loading
Fixes widget not initializing if loaded async or after the `DOMContentLoaded` event fires. That event fires when `readystate` changes from initial state `loading` to `interactive`, so we should only use the listener if the current state is `loading`.
1 parent 44b94de commit f9b868c

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/index.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ if (typeof exports !== undefined) {
66
if (typeof window !== undefined) {
77
window.netlifyIdentity = netlifyIdentity;
88
}
9-
10-
document.addEventListener("DOMContentLoaded", () => {
9+
if (document.readyState === "loading") {
10+
document.addEventListener("DOMContentLoaded", () => {
11+
netlifyIdentity.init();
12+
});
13+
} else {
1114
netlifyIdentity.init();
12-
});
15+
}

0 commit comments

Comments
 (0)