diff --git a/package.json b/package.json index dd178ae..53a501f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-custom-scroller", - "version": "2.2.0", + "version": "2.2.1", "description": "Super simple React component for creating a custom scrollbar cross-browser and cross-devices", "author": "Vitor Buzinaro ", "license": "MIT", diff --git a/src/useCustomScroller.ts b/src/useCustomScroller.ts index f92c1e2..107a001 100644 --- a/src/useCustomScroller.ts +++ b/src/useCustomScroller.ts @@ -1,10 +1,12 @@ -import type { MouseEvent as ReactMouseEvent, MutableRefObject } from 'react'; -import { useLayoutEffect, useRef, useState, useCallback } from 'react'; +import type { MutableRefObject, MouseEvent as ReactMouseEvent } from 'react'; +import { useCallback, useLayoutEffect, useRef, useState } from 'react'; + +const DEFAULT_SCROLLBAR_WIDTH = 20 /** * We use a negative right on the content to hide original OS scrollbars */ -const OS_SCROLLBAR_WIDTH = (() => { +const OS_SCROLLBAR_WIDTH = typeof window === 'undefined' ? DEFAULT_SCROLLBAR_WIDTH : (() => { const outer = document.createElement('div'); const inner = document.createElement('div'); outer.style.overflow = 'scroll'; @@ -24,7 +26,7 @@ const OS_SCROLLBAR_WIDTH = (() => { * We need this for OSs that automatically hide the scrollbar (so the offset * doesn't change in such case). Eg: macOS with "Automatically based on mouse". */ -const SCROLLBAR_WIDTH = OS_SCROLLBAR_WIDTH || 20; +const SCROLLBAR_WIDTH = OS_SCROLLBAR_WIDTH || DEFAULT_SCROLLBAR_WIDTH; export default function useCustomScroller( customRef: MutableRefObject | undefined,