datacamp / datacamp-light

Convert any blog or website to an interactive learning platform for data science
GNU Affero General Public License v3.0
1.3k stars 353 forks source link

RStudio and Bookdown: LazyLoading of exercises not working #106

Closed martinschmelzer closed 5 years ago

martinschmelzer commented 5 years ago

When creating a bookdown document using your example exercises, the first exercise loads normally. The others do not load when scrolling them into the viewport. It is like the "inViewport" event is not triggered. When generating basic RMarkdown document with several exercises it works as expected.

rv2e commented 5 years ago

We could add an option to disable the lazy loading functionality. This should solve your problem.

cstigler commented 5 years ago

We're also having this issue, loading DCL exercises inside of an iFrame. Since the iFrame is a fixed height, I think this messes with react-lazyload's calculations and it never tries to load the exercise. This appears to be a known issue with react-lazyload, see this issue on their tracker.

The lazy load also appears not to work if re-rendering into an area that is already visible on the page: it stays stuck on the placeholder until I scroll again. Ideally DCL would detect that it's already rendered in a visible area and load itself immediately.

An option to turn off lazy loading would be greatly appreciated and is probably the easiest solution for now. In the case of one commenter on the above react-lazyload issue, they fixed lazy loading properly by "replac[ing] it [with] a custom component based on IntersectionObserver with similar reduced API," but that sounds like a bigger fix.

cstigler commented 5 years ago

Submitted a PR to add an option to disable lazy-loading, which should fix these issues: https://github.com/datacamp/datacamp-light/pull/136