question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ResizeObserver polyfill does not work when bundled

See original GitHub issue

What

ResizeObserver is undefined when the RO polyfill script is used.

repro: https://codesandbox.io/s/polyfill-io-resizeobserver-failing-to-install-t3pwln?file=/src/polyfill.js

Details

Required setup:

  • Use Safari (or any browser that doesn’t have Resize Observer)
  • Go to Safari devtools and disable Resize Observer ** Develop > Experimental Features > Uncheck Resize Observer
  • go to https://t3pwln.csb.app/

Upon visiting that page you’ll see ReferenceError: Can't find variable: ResizeObserver

I’m at a bit of a loss why this isn’t working.

What I’ve done is just copy/paste the output from https://polyfill.io/v3/polyfill.js?version=3.110.1&features=ResizeObserver using a spoofed UA of

Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0.2 Safari/E7FBAF

But whats really mind bending is if I use the polyfill.io script in the index.html the polyfill works as expected.

What am I missing here?

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:10

github_iconTop GitHub Comments

1reaction
wesgrocommented, Oct 18, 2022

Apologies, this appears to be something with how we bundle the polyfills that breaks the UMD in this case. Will investigate locally.

0reactions
wesgrocommented, Oct 19, 2022

Ideally we have some way to test and verify polyfills when bundled. This guards users against regressions. Having tests of this nature is very difficult. We also have to be careful that the fix for your setup isn’t a bug for someone else.

Agree! This is a tricky problem…

On my end I can always patch the package to modify the RO implementation to work for us if a change here is seen as too risky. So far changing it to use exports has been fruitful but I can’t guarantee anything outside of my usage

Read more comments on GitHub >

github_iconTop Results From Across the Web

ResizeObserver Polyfill creates errors with Webpack & UglifyJS
Looks like 1.4.x uses ResizeObserver polyfill which created the above error when webpack & uglifyjs are bundling. Technically you would be ...
Read more >
Loading polyfills conditionally & bundles - Stack Overflow
Say I have my index file which is the main file exported with the library, should I add this statement outside the function...
Read more >
4lolo/resize-observer-polyfill - npm
A polyfill for the Resize Observer API. Implementation is based on the MutationObserver and uses Mutation Events as a fall back if the...
Read more >
resize-observer-polyfill v1.5.1 Bundlephobia
Size of resize-observer-polyfill v1.5.1 is 7.8 kB (minified), and 2.5 kB when compressed using GZIP. Bundlephobia helps you find the performance impact of ......
Read more >
resize-observer-polyfill/README.md - UNPKG
The CDN for resize-observer-polyfill. ... (has style problems in IE10 and lower). 14. 15, ## Installation ... Creates UMD bundle in the `dist`...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found