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(useIntersectionObserver): update syntax to handle stricter types #4333

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

cyrilf
Copy link

@cyrilf cyrilf commented Nov 9, 2024

References:

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

Description

Due to stricter types planned on the upcoming v4 of Nuxt, the demo example needs to be updated.
You can look at this Nuxt issue for reference.
The Typescript issue occurs when future: { compatibilityVersion: 4 }, is applied in the nuxt.config.ts file.

The change is not Nuxt related though, it concerns anyone.
It's simply applying an extra check on the IntersectionObserverCallback argument to ensure we handle the possibility of having an entry being undefined instead of immediately de-structuring.

Additional context

Reproduction link of the issue

As a bonus, it makes the code a bit more beginner-friendly (we could even use the name entries and access it via entries[0]?.isIntersecting but I think that's out-of-scope from vueuse, as all information are already available on MDN.

I made a choice towards visibility but feel free to choose another way of writing it

For instance: (for brevity but less beginner-friendly)

- targetIsVisible.value = entry?.isIntersecting || false
+ targetIsVisible.value = !!entry?.isIntersecting

@dosubot dosubot bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Nov 9, 2024
@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels Nov 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:S This PR changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant