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

fix: cannot access 'unobserve' before initialization #587

Conversation

kik4
Copy link
Contributor

@kik4 kik4 commented Oct 23, 2022

Hello!
I got an error ReferenceError: cannot access 'unobserve' before initialization when IntersectionObserver is undefined, fallbackInView and triggerOnce of useInView is true.
When that condition is met, 'unobserve' is before initialization at line 73 in useInView.tsx.
So I added an initialization line and created this PR. Please check it.

@vercel
Copy link

vercel bot commented Oct 23, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
react-intersection-observer ✅ Ready (Inspect) Visit Preview Oct 23, 2022 at 8:12AM (UTC)

@codesandbox-ci
Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 5dc11dc:

Sandbox Source
useInView Configuration
InView render props Configuration
InView plain children Configuration

@thebuilder
Copy link
Owner

Can you make sandbox that replicates it? I fail to see how this PR changes anything.
There is already an if to check unobserve exists before calling it.

@kik4
Copy link
Contributor Author

kik4 commented Oct 24, 2022

Here it is.
These are set IntersectionObserver = undefined for fallback behavior and the options of useInView.
v9.4.0: https://codesandbox.io/s/useinview-forked-dt66bx (Doesn't work)
this PR: https://codesandbox.io/s/useinview-forked-pwr0hr

@thebuilder
Copy link
Owner

Ah - Okay, i see - Makes sense.

@thebuilder thebuilder merged commit 3c2f4a1 into thebuilder:master Oct 24, 2022
@thebuilder
Copy link
Owner

🎉 This PR is included in version 9.4.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

2 participants