Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ResizeObserver support #1497

Open
csantos1113 opened this issue Jul 25, 2024 · 1 comment
Open

Add ResizeObserver support #1497

csantos1113 opened this issue Jul 25, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@csantos1113
Copy link

csantos1113 commented Jul 25, 2024

Is your feature request related to a problem? Please describe.
Could it be possible to add support for ResizeObserver?

I'm currently using vitest + happy-dom and I had a poor stub for the ResizeObserver; although it wasn't working but I didn't really know why, at first.

Then I noticed this in my code:

if (typeof global.ResizeObserver !== 'undefined') {
  return global.ResizeObserver;
}

So it made me realize that happy-dom already has a ResizeObserver stub with a bunch of // TODO 😅

Describe the solution you'd like
My poor stub is far from optimal so I'm not going to share it here as it's not worth it; and I'm unsure how hard it'd be to build one from scratch.

But I could suggest something like https://github.com/juggle/resize-observer which I found by looking at the code of one of the libraries I use: https://github.com/ZeeCoder/use-resize-observer/blob/465fbc11c92e1b97a1dcb526b44ce4d889956951/tests/ie/polyfilled.tsx#L15-L25

Describe alternatives you've considered
For now the solution for my case is deleting this code

if (typeof global.ResizeObserver !== 'undefined') {
  return global.ResizeObserver;
}

and forcing my poor stub to be applied regardless if there is a ResizeObserver or not

@csantos1113 csantos1113 added the enhancement New feature or request label Jul 25, 2024
@webJose
Copy link

webJose commented Aug 2, 2024

I need this too, to test Svelte v5 libraries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants