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

Using an iframe with a dynamic source breaks the back button in firefox (blazor server) #21002

Closed
Trolldemorted opened this issue Apr 19, 2020 · 5 comments
Assignees
Labels
area-blazor Includes: Blazor, Razor Components
Milestone

Comments

@Trolldemorted
Copy link

Describe the bug

Having an iframe where the src attribute is modified within an InvokeAsync block impairs the "One Page Back"-button experience: If you click the button in firefox (75.0), the iframe appears to reload, but you are not redirected to the previous page.

In Edge and Chrome it works fine. In IE11 my sample throws an ObjectDisposedException, which is most likely a different bug I guess?

To Reproduce

Either clone this repo, or use this snippet:

@page "/i/iframe"
@using System.Diagnostics
@if (Url != null)
{
    <iframe src="@(Url)" style="width:100%; height:100%; border:0; border-style:solid;" />
}
else
{
    <div>Url is null</div>
}

@code {
    [Parameter]
    public string? SomeString { get; set; }
    string? Url = null;

    protected override void OnParametersSet()
    {
        Task.Run(async () =>
        {
            await InvokeAsync(() =>
            {
                Url = "https://demo.codimd.org/CGdlv3HDQwaQe_Y6uWKLhw";
                base.StateHasChanged();
            });
        });
    }
}

Open firefox and the index page, click on "iframe" to navigate to /i/iframe, wait for iframepage and the actual iframe to load, press the back button once, and you will see that your browser does not navigate to the previous page.

Further technical details

  • ASP.NET Core version
    3.1.3
  • Include the output of dotnet --info
PS C:\Users\Benni\repositories\BlazorServerIframeBug> dotnet --info
.NET Core SDK (gemäß "global.json"):
 Version:   3.1.201
 Commit:    b1768b4ae7

Laufzeitumgebung:
 OS Name:     Windows
 OS Version:  10.0.18363
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\3.1.201\

Host (useful for support):
  Version: 3.1.3
  Commit:  4a9f85e9f8

.NET Core SDKs installed:
  2.1.202 [C:\Program Files\dotnet\sdk]
  2.1.508 [C:\Program Files\dotnet\sdk]
  2.1.801 [C:\Program Files\dotnet\sdk]
  2.2.203 [C:\Program Files\dotnet\sdk]
  3.0.100-preview9-014004 [C:\Program Files\dotnet\sdk]
  3.0.100 [C:\Program Files\dotnet\sdk]
  3.1.200 [C:\Program Files\dotnet\sdk]
  3.1.201 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.0.0-preview9.19424.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.0.0-preview9-19423-09 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.0.0-preview9-19423-09 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download
  • The IDE (VS / VS Code/ VS4Mac) you're running on, and it's version
    Microsoft Visual Studio Enterprise 2019 Version 16.5.4
@mkArtakMSFT mkArtakMSFT added the area-blazor Includes: Blazor, Razor Components label Apr 20, 2020
@javiercn
Copy link
Member

@Trolldemorted thanks for contacting us.

I'm not sure why it is exposing that behavior, but it seems that the app is crashing in some way by what you describe and these lines of code probably need some error handling:

        Task.Run(async () =>
        {
            await InvokeAsync(() =>
            {
                Url = "https://demo.codimd.org/CGdlv3HDQwaQe_Y6uWKLhw";
                base.StateHasChanged();
            });
        });

I would ask what are you trying to achieve to see if we can offer you alternative ways to accomplish the same result.

@javiercn javiercn added the Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. label Apr 20, 2020
@Trolldemorted
Copy link
Author

In my production use case the src parameter is constructed from a property, which is fetched from a database.

Why do you think the app is crashing? It continues to work just fine - No exceptions in VS debug output, no errors in firefox' console, I can click around, my handlers are being executed correctly, I can navigate between pages, the only problem is the back button, and only in firefox.

Since pressing the back button twice fast enough works (the first button reloads the page, the second press must come before the iframe loads), I assumed that blazor incorrectly pushes a new state to the browser's history when the iframe src is modified in an InvokeAsync block.

@ghost ghost added Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. and removed Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. labels Apr 20, 2020
@mkArtakMSFT
Copy link
Member

@Trolldemorted, it seems that the usage of Task.Run is already a red flag. Try to rework that code to return a task and change the method into static, so the framework is aware when the execution is complete. If you have an issue after that, then share a small repro project with us and we'll see what can be done.

On a side note, do you see the same behavior if Blazor out of picture - if you add same HTML structure in a new html page, will the back button be disabled again?

@mkArtakMSFT mkArtakMSFT added Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. and removed Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. labels Apr 20, 2020
@Trolldemorted
Copy link
Author

I am using Task.Run to have the database access running in a thread without a synchronization context. Are you certain you don't want to fix this bug nevertheless?

The back button is not disabled, it just refers to the same page which pushes a new state as soon as the iframe loads.

Using a normal iframe does not impair firefox' history.

@ghost ghost added Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. and removed Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. labels Apr 20, 2020
@mkArtakMSFT mkArtakMSFT removed the Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. label Apr 21, 2020
@mkArtakMSFT mkArtakMSFT added this to the Discussions milestone Apr 21, 2020
@ghost
Copy link

ghost commented Nov 12, 2020

Thank you for contacting us. Due to a lack of activity on this discussion issue we're closing it in an effort to keep our backlog clean. If you believe there is a concern related to the ASP.NET Core framework, which hasn't been addressed yet, please file a new issue.

This issue will be locked after 30 more days of inactivity. If you still wish to discuss this subject after then, please create a new issue!

@ghost ghost closed this as completed Nov 12, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 12, 2020
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components
Projects
None yet
Development

No branches or pull requests

4 participants