chrisdickinson / raf

requestAnimationFrame polyfill library
MIT License
742 stars 54 forks source link

Add support for globalThis #47

Closed gingerchris closed 2 years ago

gingerchris commented 2 years ago

When running this package in a web worker, window is undefined - but so is global, which causes the browser to throw an error when trying to set root

This update adds support for workers by using globalThis if global is falsey.

gingerchris commented 2 years ago

I think this will also address the issue raised in https://github.com/chrisdickinson/raf/issues/46

ljharb commented 2 years ago

global is defined in node, and every non-broken node module bundler rewrites global into window.

If you’re using webpack 5, for example, you’ll need to un break it by configuring it to polyfill node globals and core modules.

gingerchris commented 2 years ago

@ljharb thanks for looking into this - sorry it's no good in it's current state! I will dig a bit further into my current use-case and see if I can resolve it without changes here.