KingSora / OverlayScrollbars

A javascript scrollbar plugin that hides the native scrollbars, provides custom styleable overlay scrollbars, and preserves the native functionality and feel.
https://kingsora.github.io/OverlayScrollbars
MIT License
3.78k stars 214 forks source link

overflow: undefined breaks OverlayScrollbarsComponent #586

Closed krutoo closed 10 months ago

krutoo commented 10 months ago

Describe the bug I use react version like this:

<OverlayScrollbarsComponent
  defer={false}
  options={{
    overflow: undefined,
  }}
>
  {children}
</OverlayScrollbarsComponent>

TypeScript types say that overflow is not required options so there is no type check errors

But when i render it then it fails with error:

TypeError: Cannot read properties of undefined (reading 'x')

To Reproduce Steps to reproduce the behavior:

  1. Go to https://stackblitz.com/edit/overlayscrollbars-react-l1mfu8?file=src%2Findex.css
  2. Click on Open in new tab
  3. Open dev console
  4. See errors "something is undefined"

Expected behavior undefined value should be interpreted as not provided overflow option i think

KingSora commented 10 months ago

@krutoo thanks for the report :)

I'll take a look.. Im just curious, whats exactly the usecase here? What do you expext the overflow option to be when you specify it like this?

krutoo commented 10 months ago

@KingSora this is consistent with the work of javascript, for example, when destructuring objects, you can assign a default value that will be applied regardless of whether the object has an undefined value or is not defined at all:

const source = { a: undefined };

const { a = 1, b = 2 } = source;

console.log(a, b) // 1 2

In my case i have component that passes a value to an internal component OverlayScrollbarsComponent:

function MyComponent ({ overflow }) {
  return <OverlayScrollbarsComponent options={{ overflow }} />
}

Is optional prop, but MyComponent breaks when is not passed or passed as undefined

KingSora commented 10 months ago

I've released v2.4.4 which should fix this issue.