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.

onEnter always fires on page load even when the component isn't on the viewport

See original GitHub issue

Had to add this extra logic in order to make it work properly (just when the component is on the viewport), this.revealTo(50, true) is just a custom method that needs to be called when the component is on the viewport.

onEnterViewport = () => {
  if (this.state.onViewport === true) this.revealTo(50, true);
  this.setState({onViewport: true});
}

And this is at the end of the render:

<Waypoint onEnter={() => this.onEnterViewport()} />

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
lauterrycommented, Oct 21, 2016

hi @trotzig

Thanks for the input.

I have a page where contents display conditionally causing the page height to be dynamically sized on load.

I think i have to put the Waypoint inside the if instead of outside :

<Waypoint onEnter={() => console.log('entered!');} />

if (doDisplay) {
 <img src='http://placehold.it/500x500' style={{ height: 500 }}>
 <img src='http://placehold.it/500x500' style={{ height: 500 }}>
 <img src='http://placehold.it/500x500' style={{ height: 500 }}>
}
if (doDisplay) {
 <Waypoint onEnter={() => console.log('entered!');} />
 <img src='http://placehold.it/500x500' style={{ height: 500 }}>
 <img src='http://placehold.it/500x500' style={{ height: 500 }}>
 <img src='http://placehold.it/500x500' style={{ height: 500 }}>
}

I’ll let you know

1reaction
trotzigcommented, Oct 21, 2016

Are the pages you are referring to publicly accessible? In general, the most common reason that waypoints are triggered prematurely on load is because of dynamic content on the page asynchronously making the page taller. Images for instance, can cause this.

<img src='http://placehold.it/500x500'>
<img src='http://placehold.it/500x500'>
<img src='http://placehold.it/500x500'>
<Waypoint onEnter={() => console.log('entered!');} />

Despite the images taking up 1500px, on initial load they don’t take up any space at all. We can fix this with some css:

<img src='http://placehold.it/500x500' style={{ height: 500 }}>
<img src='http://placehold.it/500x500' style={{ height: 500 }}>
<img src='http://placehold.it/500x500' style={{ height: 500 }}>
<Waypoint onEnter={() => console.log('entered!');} />

This waypoint won’t be triggered until you actually scroll down.

Could this be the case? It doesn’t have to be images at all, there are other types of dynamically sized content that can cause this behavior.

If you add the debug prop, there’s a chance you might see something interesting. You can paste the output from it here and I’ll help you too.

Read more comments on GitHub >

github_iconTop Results From Across the Web

onEnter always fires on page load even when the component ...
Hi @juancabrera, and thanks for using react-waypoint. We have a test that checks for waypoints outside the viewport on mount. It would be...
Read more >
IntersectionObserver callback firing immediately on page load
lazy-load element enters the viewport, but callback() also fires once when the page is initially loaded, which triggers `console.log('observer ...
Read more >
GSAP scrollTrigger firing on page load, not “start” trigger ...
I'm trying to make the second block of text on my screen animate when I scroll down on it. The second block of...
Read more >
react-waypoint - npm
When the window is resized; When it is mounted (fires onEnter if it's visible on the page); When it is updated/re-rendered by its...
Read more >
Release Notes for Ext JS 5.1.3 - Sencha
EXTJS-19592 Image Sprites do not fire sprite events. Events (4) ... EXTJS-16187 Page Analyzer throws error and won't load; EXTJS-16725 Ext.ux.event.
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