Skip to content

Commit

Permalink
fix: Support non-browser environments
Browse files Browse the repository at this point in the history
  • Loading branch information
Daydreamer-riri committed May 7, 2024
1 parent a380f11 commit e65bca5
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/helpers/setAnimationFrameTimeout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ export function clearAnimationFrameTimeout(canceller: Canceller) {
cancelAnimationFrame(canceller.id)
}

const isBrowser = typeof document !== 'undefined'

export function nextTick(callback: () => unknown) {
if (!isBrowser)
return setAnimationFrameTimeout(callback, 0)

return setTimeout(() => {
// Reading document.body.offsetTop can force browser to repaint before transition to the next state
Number.isNaN(document.body.offsetTop) || callback()
Expand Down

0 comments on commit e65bca5

Please sign in to comment.