Skip to content
This repository was archived by the owner on Jan 19, 2023. It is now read-only.

Commit 42f76d1

Browse files
committed
Reduce dependency on existence of window
1 parent b3fa8ae commit 42f76d1

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/react-image-lightbox.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ class ReactImageLightbox extends Component {
172172

173173
// Attach key and mouse input events
174174
attachListeners() {
175-
if (!this.listenersAttached) {
175+
if (!this.listenersAttached && typeof window !== 'undefined') {
176176
window.addEventListener('resize', this.handleWindowResize);
177177
window.addEventListener('mouseup', this.handleMouseUp);
178178
window.addEventListener('touchend', this.handleMouseUp);

src/util.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
* @return {?number} ieVersion - IE version as an integer, or undefined if not IE
55
*/
66
export function getIEVersion() {
7-
const match = navigator.userAgent.match(/(?:MSIE |Trident\/.*; rv:)(\d+)/);
7+
if (typeof window === 'undefined') {
8+
return undefined;
9+
}
10+
11+
const match = window.navigator.userAgent.match(/(?:MSIE |Trident\/.*; rv:)(\d+)/);
812
return match ? parseInt(match[1], 10) : undefined;
913
}
1014

0 commit comments

Comments
 (0)