question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

rootMargin not working until after the first time intersecting

See original GitHub issue

Bug Report

Describe the Bug

The rootMargin is being ignore until after the first time the IntersectionObserver fires isIntersecting.

How to Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Provide custom rootMargin and custom ref
  2. Scroll down
  3. Observe the isIntersecting is false until the element is visible.
  4. Scroll down again
  5. Observe the isIntersecting is true at the expected rootMargin

CodeSandbox Link

https://codesandbox.io/s/react-cool-inviewissues495-0g4yk

Expected Behavior

Should respect the rootMargin on the initial scroll

Screenshots

image

Your Environment

  • Device: MacBook Pro
  • OS: macOS X
  • Browser: Chrome
  • Version: v1.2.2

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
wellyshencommented, Apr 4, 2021

@stramel Thank you bro, your issues really helpful.

1reaction
stramelcommented, Apr 4, 2021

Going to close this issue in favor of a new one to show the other issues that I have found with scrollDirection and inView.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Intersection Observer rootMargin not working as expected on ...
Result: Image only loads when intersecting at viewport , which rootMargin seems to not be working on horizontal level. Here is an example:...
Read more >
An Explanation of How the Intersection Observer Watches
Also note that the rootMargin does not work if the root element is not an actual element on the page, such as the...
Read more >
Lazy loading using the Intersection Observer API
Lazy loading is a technique that allows us to delay loading nonessential content in our application until after the initial page load.
Read more >
Intersection Observer API - MDN Web Docs
The first time the observer is initially asked to watch a target ... the root margin, rootMargin , when creating the IntersectionObserver ....
Read more >
Intersection Observer - W3C
Publication as a First Public Working Draft does not imply ... of changes) { console.log(change.time); // Timestamp when the change occurred ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found