Skip to content

Commit

Permalink
Fixes SSR errors by checking for window. (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
guanzo authored and ndelvalle committed Dec 7, 2018
1 parent df13e58 commit 8f7e6ef
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/v-click-outside.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const isTouch = 'ontouchstart' in window || navigator.msMaxTouchPoints > 0
const isTouch = (typeof window !== 'undefined') &&
('ontouchstart' in window || navigator.msMaxTouchPoints > 0)
const events = isTouch ? ['touchstart', 'click'] : ['click']

const instances = []
Expand Down Expand Up @@ -73,6 +74,4 @@ const directive = {
instances,
}

// Note: This is to disable the directive on server side, there should be a better way.
// https://github.com/ndelvalle/v-click-outside/issues/22
export default (typeof window !== 'undefined' ? directive : {})
export default directive

0 comments on commit 8f7e6ef

Please sign in to comment.