-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Downloads of unmounted images aren't canceled #290
Comments
Thanks for this, all valid points. V4 is super flexible in how image downloading is done which has the downside of making it harder to predict what the right cancelation methodology would be. Let me give this some thought on how to go about it. Until then, ideas are welcome! |
Not sure this is a related issue, but I'm seeing this manifested in other ways when combining Output in console:
|
@c5inco correct. I encountered similar issue with unmounting components. |
Thanks for the feedback guys! The complexity here designing is an API which returns Have some possible ideas, but those require a breaking change. Open to API/code suggestions! |
I also have output in console |
The error has been depreciated in React 18 and should no longer show. Regarding the issue at hand, I'm thinking of adding a Thoughts? |
A PR has been opened to address this. There is a link with a preview build - it would be great if you could download and manually install that and test. Thanks! To test, download and in your projects directory run |
Background info:
When the browser starts to download an image via a plain html img tag, and the img tag is removed from the DOM while the image is being downloaded or even before the image download starts, the browser will continue to download the image. This problem doesn't occur in plain non-JS server side rendered application, because a new HTTP page request will abort all images. But for JavaScript applications, the images have to be aborted manually by setting the src attribute to an empty-string. More info about this problem is shown here: https://stackoverflow.com/questions/59270779/react-downloads-pending-images-of-previous-render
If no solution would be implemented, this would cause the downloading (and loading) of images to be stacked/accumulated invisibly in the browser, which causes bandwidth waste. It also causes a delay in the rendering of new pages, because the browser will first download all images from all previously closed pages.
(Personally, I think this is a flaw in the DOM standard. )
Fixed in React-Image since 2.1.1?
There was a pull request which would automatically cancel image download when those images were umounted. #223
Which included a plain JavaScript demo to demonstrate that cancellation is possible in the DOM: https://jsbin.com/zakeqaseru/1/edit?output
A solution was implemented in React-Image 2.1.0 with a fix followed in 2.1.1: https://github.com/mbrevda/react-image/blob/master/CHANGELOG.md
But React-Image doesn't seem to cancel the download on unmount. You can verify this here:
https://codesandbox.io/s/upbeat-hopper-kucou
https://kucou.csb.app/
(Apart from the image cancellation problem, for some unknown reason, CodeSandbox gives an error for React-Image 2.x, but does work for 4.x. But I have also tried it locally, were is does run, but still has the cancellation problem.)
The text was updated successfully, but these errors were encountered: