Skip to content
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

Blazor WASM App navigation won't stop image request when image is a stream (webcam) #55219

Closed
1 task done
emmuss opened this issue Apr 19, 2024 · 3 comments
Closed
1 task done
Labels
area-blazor Includes: Blazor, Razor Components ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. question Status: Resolved

Comments

@emmuss
Copy link

emmuss commented Apr 19, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

When an <img> tag has an source attibute poiting to a never ending stream (webcam) navigation between blazor pages won't dispose the stream, the application keeps building up streams for each navigation request, even trying to remove the tag from the dom using javascript does not work.

see the attached image, 4 navigations between the two pages have been executed and the streams keep accumulating.

image

Expected Behavior

image streaming comes to a halt when the page is disposed.

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

8.0.204

Anything else?

No response

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-blazor Includes: Blazor, Razor Components label Apr 19, 2024
@emmuss
Copy link
Author

emmuss commented Apr 19, 2024

This is my current solution to stop the stream:

    async ValueTask IAsyncDisposable.DisposeAsync()
    {
        await JS.InvokeVoidAsync("eval", "document.getElementById('webCam').src = 'https://i.imgur.com/c24qDz2_d.jpeg?maxwidth=520&shape=thumb&fidelity=high'");
    }

@javiercn
Copy link
Member

@emmuss thanks for contacting us.

Does setting the image source to '' achieve the same effect?

We don't think this is something that the framework can effectively handle and its something that you have to handle in your app. In a regular navigation the page would go away, but in an enhanced nav, the document is preserved, hence the change in behavior.

There's really nothing the framework can do out of the box as we don't have a way to detect this situation (the browser is doing the request, not Blazor), so I suspect the only way to achieve this is to do something similar to what you are doing. Maybe you could think of encapsulating this in a component with its related JS and hook on to "enhancedload" to trigger the behavior to cancel the stream.

@javiercn javiercn added question ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. labels Apr 21, 2024
Copy link
Contributor

This issue has been resolved and has not had any activity for 1 day. It will be closed for housekeeping purposes.

See our Issue Management Policies for more information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. question Status: Resolved
Projects
None yet
Development

No branches or pull requests

2 participants