Skip to content

Commit 3cb3663

Browse files
committed
fix: Add SSR support
1 parent 340a0de commit 3cb3663

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

index.js

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,26 @@ let _throttle = require('lodash.throttle')
44

55
let supportsPassive = false
66
try {
7-
var opts = Object.defineProperty({}, 'passive', {
8-
get: function() {
9-
supportsPassive = true
10-
},
11-
})
12-
window.addEventListener('testPassive', null, opts)
13-
window.removeEventListener('testPassive', null, opts)
7+
if (typeof window !== 'undefined') {
8+
var opts = Object.defineProperty({}, 'passive', {
9+
get: function() {
10+
supportsPassive = true
11+
},
12+
})
13+
window.addEventListener('testPassive', null, opts)
14+
window.removeEventListener('testPassive', null, opts)
15+
}
1416
} catch (e) {}
1517

16-
let getPosition = () => ({
17-
x: window.pageXOffset,
18-
y: window.pageYOffset,
19-
})
18+
let getPosition = () => {
19+
if (typeof window === 'undefined') {
20+
return { x: 0, y: 0 };
21+
}
22+
return {
23+
x: window.pageXOffset,
24+
y: window.pageYOffset,
25+
};
26+
};
2027

2128
let defaultOptions = {
2229
throttle: 100,

0 commit comments

Comments
 (0)