iframe-resizer icon indicating copy to clipboard operation
iframe-resizer copied to clipboard

Adopt ResizeObserver API

Open stefnotch opened this issue 4 years ago • 2 comments

Describe the bug

Currently iframe-resizer relies on a lot of hard work to ensure that it works in every single browser. Like it says in the readme, it even works with IE11, which is a rather impressive feat.

Recently I've noticed that the ResizeObserver API appears to be an API that was created to simplify much of the code required to watch an element's size. Would it be worthwhile to adopt this?

Furthermore, if adopting the ResizeObserver API does indeed seem like a good idea, I personally would love seeing some of the legacy code eventually being deprecated. This part is purely a personal opinion, but it might have some advantages a) lower bundle size, which is amazing for consumers b) less code to maintain c) just a general feeling of being "modern"

stefnotch avatar Jun 10 '21 16:06 stefnotch

I just had a look at this. I think it might make sense to replace MutationObserver with ResizeObserver so that resizing only gets triggered by element mutations that change an element's size. I would welcome a PR if you would like to give it a go. It would need some further investigation to see if it also covered other use cases.

At some point in the future, I will drop support for IE11, but not sure we are quite at that point yet.

davidjbradshaw avatar Jun 15 '21 15:06 davidjbradshaw

I'd provide an exam using ResizeObserver https://stackoverflow.com/a/70334190/1485853

redstoneleo avatar Dec 13 '21 11:12 redstoneleo

I’m adding this to V5, and also dumping IE11 support. Will have to keep a lot of the other detection code, as so that we can still detect resizing of items outside the main document flow.

davidjbradshaw avatar Feb 03 '24 08:02 davidjbradshaw