Skip to content

Commit 9a296a9

Browse files
committed
🐛 don't throw errors when checking for window in non-DOM environments
1 parent 2214942 commit 9a296a9

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/mnml.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export const mnml = (() => {
114114
};
115115
_loadListener.queue = [] as Array<[MnmlEventCallback, number]>;
116116
_loadListener.loaded = false;
117-
if (window) {
117+
if (typeof window !== "undefined") {
118118
window.addEventListener("load", () => {
119119
_loadListener.queue = _loadListener.queue.sort((a, b) => a[1] - b[1]);
120120
while (_loadListener.queue.length) {
@@ -200,7 +200,7 @@ export const mnml = (() => {
200200
if (["unload", "beforeunload"].includes(eventName)) {
201201
if (typeof selector === "function") {
202202
const _cb = selector as MnmlEventCallback;
203-
if (window) {
203+
if (typeof window !== "undefined") {
204204
window.addEventListener(eventName, _cb);
205205
}
206206
return;

0 commit comments

Comments
 (0)