Skip to content

Incorrect polyfill causes crash #734

@denke8

Description

@denke8

Describe the bug
It's not exactly a bug on the library itself, rather a request for stronger verification.

Context:
I'm developing a widget, that is embedded into many different CMSs. There is one in particular, that has the following code:

 if (!window.requestIdleCallback) {
        window.requestIdleCallback = (cb) => {
            setTimeout(cb, 0);
        }
    }

It does not implement the interface correctly, and does not implement the cancel feature at all.

This does the following to OverlayScrollbars at this point:

  • Assume the browser does not natively support requestIdleCallback
  • idleSupported becomes true since wnd.requestIdleCallback is a function
  • cIdle becomes undefined since cancelIdleCallback is not implemented
  • the app crashes when cIdle is called (when the UI is destroyed)

To Reproduce

  • Inject the above code before creating a scrollbars component
  • Create a scrollbars component
  • Destroy the component
  • Crash happens

Environment

  • OverlayScrollbars version:
  overlayscrollbars: 2.11.5
  overlayscrollbars-react: 0.5.6
  • Used Operating System(s): MacOS, IOS (any)
  • Used Browser(s) (with version): Safari (any) / IOS Safari (any)

Additional context
This is more of a workaround request than a bug report. What I'd like to ask is, when idleSupported is being set, either:

  • Also check that typeof wnd.cancelIdleCallback === 'function' (minimal solution)
  • Verify that window.requestIdleCallback is native code, perhaps by requestIdleCallback.toString() .includes('[native code]') (Imo more robust solution)

I'd be happy to contribute too, if you are okay with one of the above suggestions ...?

I know that this is not something that your library should have to do, so thank you for considering it!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions