Skip to content

Commit

Permalink
fix(Toast): check if window exists to run startTimer in CSR only (#1247)
Browse files Browse the repository at this point in the history
* fix(Toast): check if window exists to run startTimer in CSR only

* use isClient to to test if it's CSR
  • Loading branch information
rankjie authored Aug 26, 2024
1 parent bf86fd1 commit a4c1316
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/radix-vue/src/Toast/ToastRootImpl.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script lang="ts">
import { isClient } from '@vueuse/shared'
import type { PrimitiveProps } from '@/Primitive'
import type { SwipeEvent } from './utils'
import { createContext, useForwardExpose } from '@/shared'
Expand Down Expand Up @@ -80,6 +81,11 @@ const remainingRaf = useRafFn(() => {
function startTimer(duration: number) {
if (!duration || duration === Number.POSITIVE_INFINITY)
return
// startTimer is used inside a watch with immediate set to true.
// This results in code execution during SSR.
// Ensure this code only runs in a browser environment
if (!isClient)
return
window.clearTimeout(closeTimerRef.value)
closeTimerStartTimeRef.value = new Date().getTime()
closeTimerRef.value = window.setTimeout(handleClose, duration)
Expand Down

0 comments on commit a4c1316

Please sign in to comment.