clear `src` attribute on recycled `<img>` nodes
See original GitHub issueHere’s a codepen with the problem: when the src
attribute of an image is changed, the old picture will keep showing while the new picture is loading. This behavior persists even if the image is removed from the DOM. When combined with Preact’s node-caching, this can get crazy, with old pictures showing up again in unrelated places.
Clearing the image with .removeAttribute('src')
should solve the issue. I’ll plan on putting together a pull request here shorty.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:7 (4 by maintainers)
Top Results From Across the Web
clear src attribute on recycled <img> nodes #351 - GitHub
Here's a codepen with the problem: when the src attribute of an image is changed, the old picture will keep showing while the...
Read more >Clear img src Attribute Using JavaScript - Linux Hint
Approach 1: Clear img src Attribute in JavaScript Using removeAttribute() Method · Specify the stated image having the specified “id” and the “src”...
Read more >How can I prevent memory leaks when removing images in ...
Remove image src attribute before removing the image from the DOM; Set image src to " " before removing the image from the...
Read more >WebView - Android Developers
Tell view hierarchy that the global view attributes need to be re-evaluated. void, removeAllViews(). Call this method to remove all child views from...
Read more >Persistent Volumes | Kubernetes
When a user is done with their volume, they can delete the PVC objects ... Currently, volumes can either be Retained, Recycled, or...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Had the same problem. Solved it by adding the key={src} to my image component and it worked. Got the idea here: https://stackoverflow.com/questions/50690956/react-img-not-immediately-changing-when-src-changes-how-can-i-fix-this
I’ve also been running into this problem with old images showing while new images load, which is not a trivial amount of time. The old images may be visible for seconds.
I tried using
.removeAttribute('src')
oncomponentWillUnmount
, which did work to start each image on a clean slate but there is some sort of race condition there because sometimes the new image would end up without an src attribute. It was unworkable.I settled on creating this component as a replacement for
<img>
elements, which seemed to provide both a clean slate and resolve the.removeAttribute('src')
race condition: