Skip to content

Commit

Permalink
Fixed wrong if (window) check (#508)
Browse files Browse the repository at this point in the history
`if (window)` it is incorrect check that throws `ReferenceError` error in non-browser environment. When you want to check potentially uninitialised variable, you must do it using typeof construction. Btw, i'm getting `ReferenceError: window is not defined` when u just import tribute (w/o `new Tribute`) in Node js (server side rendering). It's strange, i supposed, that initialisation runs after i call `new Tribute`.
  • Loading branch information
f0rmat1k authored Nov 30, 2020
1 parent de47a92 commit f4bd8d2
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ if (!Array.prototype.find) {
}
}

if (window && typeof window.CustomEvent !== "function") {
if (typeof window !== 'undefined' && typeof window.CustomEvent !== "function") {
function CustomEvent(event, params) {
params = params || {
bubbles: false,
Expand All @@ -38,4 +38,4 @@ if (window && typeof window.CustomEvent !== "function") {
}

window.CustomEvent = CustomEvent
}
}

0 comments on commit f4bd8d2

Please sign in to comment.