Skip to content

Commit

Permalink
fix: ssr build issue (#46)
Browse files Browse the repository at this point in the history
* fix: ssr build issue

* Create green-onions-protect.md
  • Loading branch information
zernonia authored May 6, 2024
1 parent c2fbd36 commit 49733ea
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/green-onions-protect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"vaul-vue": patch
---

fix: ssr build issue
16 changes: 8 additions & 8 deletions packages/vaul-vue/src/controls.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { computed, ref, watch, watchEffect } from 'vue'
import type { ComponentPublicInstance, Ref } from 'vue'
import { isClient } from '@vueuse/core'
import { dampenValue, getTranslateY, reset, set } from './helpers'
import { TRANSITIONS, VELOCITY_THRESHOLD } from './constants'
import { useSnapPoints } from './useSnapPoints'
Expand Down Expand Up @@ -195,9 +196,8 @@ export function useDrawer(props: UseDrawerProps & DialogEmitHandlers): DrawerRoo
const swipeAmount = drawerRef.value ? getTranslateY(drawerRef.value.$el) : null
const date = new Date()

if (element.hasAttribute('data-vaul-no-drag') || element.closest('[data-vaul-no-drag]')) {
return false;
}
if (element.hasAttribute('data-vaul-no-drag') || element.closest('[data-vaul-no-drag]'))
return false

// Allow scrolling when animating
if (openTime.value && date.getTime() - openTime.value.getTime() < 500)
Expand Down Expand Up @@ -424,13 +424,13 @@ export function useDrawer(props: UseDrawerProps & DialogEmitHandlers): DrawerRoo
}

watchEffect(() => {
if (!isOpen.value && shouldScaleBackground.value) {
if (!isOpen.value && shouldScaleBackground.value && isClient) {
// Can't use `onAnimationEnd` as the component will be invisible by then
const id = setTimeout(() => {
reset(document.body);
}, 200);
reset(document.body)
}, 200)

return () => clearTimeout(id);
return () => clearTimeout(id)
}
})

Expand Down Expand Up @@ -533,7 +533,7 @@ export function useDrawer(props: UseDrawerProps & DialogEmitHandlers): DrawerRoo
// setting original styles initially
set(document.body, {
background: document.body.style.backgroundColor || document.body.style.background,
});
})
// setting body styles, with cache ignored, so that we can get correct original styles in reset
set(
document.body,
Expand Down

0 comments on commit 49733ea

Please sign in to comment.