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.

Load not work when parent element has display: none;

See original GitHub issue

When I have a <LazyLoad> inside an element with display: none and I change this display to block, the content not load. This content only will load after a scroll interaction.

The code is like that:

export default function App() {
  const [tab, setTab] = useState(1);

  return (
    <div className="App">
      <ul className="tabs">
        <li>
          <button onClick={() => setTab(1)}>tab 1</button>
        </li>
        <li>
          <button onClick={() => setTab(2)}>tab 2</button>
        </li>
      </ul>

      <div className="content">
        <div style={{ display: tab === 1 ? "block" : "none" }}>
          <p>Content of tab 1</p>
          <LazyLoad>
            <img src="https://via.placeholder.com/150?text=Content 1" alt="1" />
          </LazyLoad>
        </div>
        <div style={{ display: tab === 2 ? "block" : "none" }}>
          <p>Content of tab 2</p>
          <LazyLoad>
            <img src="https://via.placeholder.com/150?text=Content 1" alt="2" />
          </LazyLoad>
        </div>
      </div>
    </div>
  );
}

The problem is that:

Screen Recording 2020-06-12 at 07 07 PM

And the complete code is here:

https://codesandbox.io/s/determined-hoover-z6cff?file=/src/App.js:104-960

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
guilourocommented, Jun 29, 2020

@guilouro Did you found a solution? I’m facing the same problem.

@geraldstrobl I created my own implementation using IntersectionObserver. But before it, I needed to change the location of the <LazyLoad />.

<LazyLoad>
  <div className="content">
    <div style={{ display: tab === 1 ? "block" : "none" }}>
      <p>Content of tab 1</p>
      <img src="https://via.placeholder.com/150?text=Content 1" alt="1" />
    </div>
    <div style={{ display: tab === 2 ? "block" : "none" }}>
      <p>Content of tab 2</p>
      <img src="https://via.placeholder.com/150?text=Content 2" alt="2" />
    </div>
  </div>
</LazyLoad>
0reactions
berk9595commented, Apr 30, 2021

Hi, is it fixed ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Does a parent element with "display: none" cause child imgs ...
Based on related questions here on SO, the general solution seems to be to use $(window).load(func); to run the grayscale generation code.
Read more >
HTML DOM Style display Property - W3Schools
Property Values ; none, Element will not be displayed ; run-in, Element is rendered as block-level or inline element. Depends on context ;...
Read more >
display - CSS: Cascading Style Sheets - MDN Web Docs
Using a display value of none on an element will remove it from the accessibility tree. This will cause the element and all...
Read more >
What is the difference between visibility:hidden and display ...
Both the visibility & display property is quite useful in CSS. ... none: It will not display any element. inline: It is the...
Read more >
Comparing Various Ways to Hide Things in CSS
If an image tag (or parent element) has a display property set to none either through inline CSS or by selector, the image...
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