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

Deal with the case of IntersectionObserver entries list being empty. #12

Merged

Conversation

giordy
Copy link
Contributor

@giordy giordy commented Oct 6, 2021

I ran into a corner case when mocking the interactions with the IntersectionObserver in Jest.

I'm using mockAllIsIntersecting() from react-intersection-observer and this causes the IntersectionObserver callbacks in domobserver.ts to be called with an empty list of entries, which then causes a crash in the code with this error:

TypeError: Cannot read property 'intersectionRatio' of undefined

To deal with this corner case I added a guard in front of the condition against empty lists of entries.

@marijnh marijnh merged commit cbdae1d into codemirror:main Oct 6, 2021
@marijnh
Copy link
Member

marijnh commented Oct 6, 2021

Weird thing to call the callback when there's not thing to report to it, but yeah, if it occurs we should definitely guard against it! Merged.

@giordy
Copy link
Contributor Author

giordy commented Oct 6, 2021

thanks!

@giordy giordy deleted the bugfix-intersection-observer-entries-access branch October 6, 2021 17:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants