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.

Lazy loading isn't working although lazy attribute is true

See original GitHub issue

Bug Report

Describe the Bug

A clear and concise description of what the bug is.

How to Reproduce

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

const fields: JSX.Element[] = []; for (let i = 1; i <= 800; i++) { fields.push( <AspectRatio ratio=“1” style={{ maxWidth: “200px” }}> {/source = {content.moodImage?.previews.s}/} <Img key={i} src={https://source.unsplash.com/random/?image=${i}} style={{ backgroundColor: “grey”, width: “480”, height: “320” }} alt=“REACT COOL IMG” cache lazy debounce={1000} /> </AspectRatio> ); }

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types export function TestPageImages(): JSX.Element { return ( <> <AspectRatio ratio=“1/5” style={{ maxWidth: “400px” }}> <img key={“key”} src={“https://source.unsplash.com/random”} alt=“REACT COOL IMG” /> </AspectRatio> <div className="mb-20 flex flex-wrap pl-5">{fields}</div> </> ); }

Expected Behavior

It should load lazy the images while scrolling, but it loads every single image at the beginning.

Screenshots

Your Environment

  • Device: MacBook Pro
  • OS: macOS
  • Browser: Chrome

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
christineschullercommented, Apr 20, 2021

It works now. Thanks a lot 😃 I probably had a bug in my code or something… it works fine now with your code snippet. Thank you once again!

1reaction
wellyshencommented, Apr 18, 2021

I’d recommend to turn the cache feature on because when images are cached by browser we don’t need to lazily loading them again. So, the user can see the content quickly.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Native lazy-loading (loading=lazy) not working even with flags ...
I had a similar issue when trying to implement it. I use Chrome by default and it was not working. When I tested...
Read more >
Browser-level image lazy loading for the web - web.dev
This post covers the loading attribute and how it can be used to control the loading of images.
Read more >
Lazy loading - Web performance | MDN
Lazy loading can occur on different moments in the application, but it typically happens on some user interactions such as scrolling and ...
Read more >
Any reason for not using loading="lazy" attribute?
One of our community members suggested using loading="lazy" for all images on DEV. Pros are pretty clear to me. But are there any...
Read more >
Lazy loading issues with section medias above the fold #1709
Add a new value "auto" for loading attribute that would either be assigned "eager" or "lazy" depending on the preload value and accumulated...
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