Skip to content

Commit c509234

Browse files
committed
fix: checking if document is defined
1 parent 70ffd2c commit c509234

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/use-swr.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,12 @@ const now = (() => {
5555
})()
5656

5757
// setup DOM events listeners for `focus` and `reconnect` actions
58-
if (!IS_SERVER && window.addEventListener && document.addEventListener) {
58+
if (
59+
!IS_SERVER &&
60+
window.addEventListener &&
61+
typeof document !== 'undefined' &&
62+
typeof document.addEventListener !== 'undefined'
63+
) {
5964
const revalidate = revalidators => {
6065
if (!defaultConfig.isDocumentVisible() || !defaultConfig.isOnline()) return
6166

0 commit comments

Comments
 (0)