fix: improve useInViewObserver hook to trigger when observer is in view on mount #18446
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this PR do?
This pull request makes inViewObserver trigger when ref element already intersect view port on mount.
Currently, inViewObserver triggers only when ref element "enters" view port after component mount. This makes infinite scroll loading behavior doesn't work on first page load if view port contains inViewObserver ref element
This PR makes inViewObserver always trigger when ref element is in view, even on first mount, making its behavior more consistent.
As a consequence, any infinite scrolling list that use inViewObserver will continue to load element on first mount up until the point ref element doesn't intersect the view port any more.
Before
Personal.Event.Types.Cal.com.-.2.January.2025.mp4
After
https___www.loom.com_share_60b418ebda554e90a711a6ed0be295f4.-.New.mp4
Loom Video: https://www.loom.com/share/60b418ebda554e90a711a6ed0be295f4?sid=4e41bb73-9501-4f0f-8df2-e0d2953c64c4
Mandatory Tasks (DO NOT REMOVE)
How should this be tested?