dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.57k stars 10.05k forks source link

Blazor (Server) Exception when clicking on back button (or navigating) from a non blazor page #26474

Closed RobinHood-80 closed 3 years ago

RobinHood-80 commented 4 years ago

Describe the bug

Sometimes hitting a back button in the browser, or navigating back (even programmatically) a blazor exception is raised after the page is loaded.

To Reproduce

please clone this repo and open on vs2019 then run it: https://github.com/RobinHood-80/Bug the main page show detailed steps on how to reproduce in the most deterministic way the issue. in this page there are also listed the main info about environment configuration etc.

i think is somewhat similar to this https://github.com/dotnet/aspnetcore/issues/24626

Instructions on how to reproduce the problem: 1) There are two links on this page. To reproduce the issue you need to click on the "One", with green background. 2) After you clicked, you will see another blazor page with a link to a std mvc page, click this link 3) As soon the standard mvc page a count down appear, now you should have only this page displayed on the browser 4) right-click on the browser tab and select Duplicate from the context menu. 5) Click on the "cloned" tab to select it and then right-click on the browser Tab select another duplicate. 6) now switch to the most recently cloned tab and repeat the process at [5] until you have 4 tabs opened. 7) wait until the count down reaches to zero on all tabs 8) switch to the last cloned tab (should be the right most one), the button below "click me to show the error" should be enabled 9) click on the button this will execute a "history.back() javascript code." 10) when the previous page mentioned on (2) appear you should see after a short moment the yellow bar of execption. 11) open the browser console. watch out the exception message about the "component record order"

A side note: while clicking on the button on a cloned tab raises the error at least on 90% of situations, i've not been able to reproduce the issue if i click on the first (original) tab

The project uses prerendered mode. I suspect (judging by the delay) that the error is in some way related to a timing issue that make the prerendered tree not in sync with the second render tree that happens after the page is loaded.

Exceptions (if any)

blazor.server.js:19 [2020-09-30T19:52:08.288Z] Error: The list of component records is not valid. e.log @ blazor.server.js:19 blazor.server.js:1 [2020-09-30T19:52:08.291Z] Information: Connection disconnected. blazor.server.js:1 Uncaught (in promise) Error: Invocation canceled due to the underlying connection being closed. at e.connectionClosed (blazor.server.js:1) at e.connection.onclose (blazor.server.js:1) at e.stopConnection (blazor.server.js:1) at e.transport.onclose (blazor.server.js:1) at e.close (blazor.server.js:1) at e.stop (blazor.server.js:1) at e. (blazor.server.js:1) at blazor.server.js:1 at Object.next (blazor.server.js:1) at a (blazor.server.js:1) e.connectionClosed @ blazor.server.js:1 connection.onclose @ blazor.server.js:1 e.stopConnection @ blazor.server.js:1 transport.onclose @ blazor.server.js:1 e.close @ blazor.server.js:1 e.stop @ blazor.server.js:1 (anonymous) @ blazor.server.js:1 (anonymous) @ blazor.server.js:1 (anonymous) @ blazor.server.js:1 a @ blazor.server.js:1 Promise.then (async) c @ blazor.server.js:8 a @ blazor.server.js:8 Promise.then (async) c @ blazor.server.js:8 (anonymous) @ blazor.server.js:8 r @ blazor.server.js:8 E @ blazor.server.js:8 (anonymous) @ blazor.server.js:8 n @ blazor.server.js:1 (anonymous) @ blazor.server.js:1 (anonymous) @ blazor.server.js:1

Further technical details

VS Version: Microsoft Visual Studio Community 2019 Version 16.7.5 VisualStudio.16.Release/16.7.5+30523.141 Microsoft .NET Framework Version 4.8.03761

Installed Version: Community

Visual C++ 2019 00435-60000-00000-AA662 Microsoft Visual C++ 2019

ASP.NET and Web Tools 2019 16.7.532.28833 ASP.NET and Web Tools 2019

ASP.NET Core Razor Language Services 16.1.0.2035807+72d099b977d3a85e65fa3b0614ca8cfc803fef02 Provides languages services for ASP.NET Core Razor.

ASP.NET Web Frameworks and Tools 2019 16.7.532.28833 For additional information, visit https://www.asp.net/

Azure App Service Tools v3.0.0 16.7.532.28833 Azure App Service Tools v3.0.0

Azure Functions and Web Jobs Tools 16.7.532.28833 Azure Functions and Web Jobs Tools

C# Tools 3.7.0-6.20459.4+7ee7c540e3bf19765695b1331c946ddf986d1516 C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools 1.10 Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Extensibility Message Bus 1.2.6 (master@34d6af2) Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.

GitHub.VisualStudio 2.11.106.19330 A Visual Studio Extension that brings the GitHub Flow into Visual Studio.

IntelliCode Extension 1.0 IntelliCode Visual Studio Extension Detailed Info

Microsoft Azure Tools 2.9 Microsoft Azure Tools for Microsoft Visual Studio 2019 - v2.9.30701.1

Microsoft Continuous Delivery Tools for Visual Studio 0.4 Simplifying the configuration of Azure DevOps pipelines from within the Visual Studio IDE.

Microsoft JVM Debugger 1.0 Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Microsoft Library Manager 2.1.79+ge3567815aa.RR Install client-side libraries easily to any web project

Microsoft MI-Based Debugger 1.0 Provides support for connecting Visual Studio to MI compatible debuggers

Microsoft Visual C++ Wizards 1.0 Microsoft Visual C++ Wizards

Microsoft Visual Studio Tools for Containers 1.1 Develop, run, validate your ASP.NET Core applications in the target environment. F5 your application directly into a container with debugging, or CTRL + F5 to edit & refresh your app without having to rebuild the container.

Microsoft Visual Studio VC Package 1.0 Microsoft Visual Studio VC Package

Mono Debugging for Visual Studio 16.7.5 (112c7bc) Support for debugging Mono processes with Visual Studio.

Node.js Tools 1.5.20701.1 Commit Hash:b0da3724234b78593207434292d9f891440edea1 Adds support for developing and debugging Node.js apps in Visual Studio

NuGet Package Manager 5.7.0 NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

ProjectServicesPackage Extension 1.0 ProjectServicesPackage Visual Studio Extension Detailed Info

SQL Server Data Tools 16.0.62008.03130 Microsoft SQL Server Data Tools

TypeScript Tools 16.0.20702.2001 TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools 3.7.0-6.20459.4+7ee7c540e3bf19765695b1331c946ddf986d1516 Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools 10.10.0.0 for F# 4.7 16.7.0-beta.20361.3+3ef6f0b514198c0bfa6c2c09fefe41a740b024d5 Microsoft Visual F# Tools 10.10.0.0 for F# 4.7

Visual Studio Code Debug Adapter Host Package 1.0 Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

Visual Studio Comparison Tools 1.0 Information about my package

Visual Studio Container Tools Extensions (Preview) 1.0 View, manage, and diagnose containers within Visual Studio.

Visual Studio Tools for Containers 1.0 Visual Studio Tools for Containers

VisualStudio.DeviceLog 1.0 Information about my package

VisualStudio.Foo 1.0 Information about my package

VisualStudio.Mac 1.0 Mac Extension for Visual Studio

Xamarin 16.7.000.452 (d16-7@033b1a7) Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer 16.7.0.495 (remotes/origin/d16-7@79c0c522c) Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin Templates 16.7.85 (1bcbbdf) Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.

Xamarin.Android SDK 11.0.2.0 (d16-7/025fde9) Xamarin.Android Reference Assemblies and MSBuild support. Mono: 83105ba Java.Interop: xamarin/java.interop/d16-7@1f3388a ProGuard: Guardsquare/proguard/proguard6.2.2@ebe9000 SQLite: xamarin/sqlite/3.32.1@1a3276b Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-7@017078f

Xamarin.iOS and Xamarin.Mac SDK 14.0.0.0 (7ec3751a1) Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.

Asp.net Info: .NET Core SDK (reflecting any global.json): Version: 3.1.402 Commit: 9b5de826fd

Runtime Environment: OS Name: Windows OS Version: 6.1.7601 OS Platform: Windows RID: win7-x64 Base Path: C:\PROGRAM FILES\DOTNET\sdk\3.1.402\

Host (useful for support): Version: 3.1.8 Commit: 9c1330dedd

.NET Core SDKs installed: 1.0.0-preview2-003131 [C:\PROGRAM FILES\DOTNET\sdk] 2.1.104 [C:\PROGRAM FILES\DOTNET\sdk] 2.1.200 [C:\PROGRAM FILES\DOTNET\sdk] 2.1.201 [C:\PROGRAM FILES\DOTNET\sdk] 2.1.202 [C:\PROGRAM FILES\DOTNET\sdk] 2.1.301 [C:\PROGRAM FILES\DOTNET\sdk] 2.1.400 [C:\PROGRAM FILES\DOTNET\sdk] 2.1.401 [C:\PROGRAM FILES\DOTNET\sdk] 2.1.402 [C:\PROGRAM FILES\DOTNET\sdk] 2.1.403 [C:\PROGRAM FILES\DOTNET\sdk] 2.1.500 [C:\PROGRAM FILES\DOTNET\sdk] 2.1.502 [C:\PROGRAM FILES\DOTNET\sdk] 2.1.503 [C:\PROGRAM FILES\DOTNET\sdk] 2.1.504 [C:\PROGRAM FILES\DOTNET\sdk] 2.1.505 [C:\PROGRAM FILES\DOTNET\sdk] 2.1.507 [C:\PROGRAM FILES\DOTNET\sdk] 2.1.508 [C:\PROGRAM FILES\DOTNET\sdk] 2.1.509 [C:\PROGRAM FILES\DOTNET\sdk] 2.2.101 [C:\PROGRAM FILES\DOTNET\sdk] 2.2.107 [C:\PROGRAM FILES\DOTNET\sdk] 3.0.100 [C:\PROGRAM FILES\DOTNET\sdk] 3.1.402 [C:\PROGRAM FILES\DOTNET\sdk]

.NET Core runtimes installed: Microsoft.AspNetCore.All 2.1.1 [C:\PROGRAM FILES\DOTNET\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.2 [C:\PROGRAM FILES\DOTNET\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.3 [C:\PROGRAM FILES\DOTNET\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.4 [C:\PROGRAM FILES\DOTNET\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.5 [C:\PROGRAM FILES\DOTNET\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.6 [C:\PROGRAM FILES\DOTNET\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.7 [C:\PROGRAM FILES\DOTNET\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.8 [C:\PROGRAM FILES\DOTNET\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.9 [C:\PROGRAM FILES\DOTNET\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.11 [C:\PROGRAM FILES\DOTNET\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.12 [C:\PROGRAM FILES\DOTNET\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.13 [C:\PROGRAM FILES\DOTNET\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.22 [C:\PROGRAM FILES\DOTNET\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.2.0 [C:\PROGRAM FILES\DOTNET\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.2.5 [C:\PROGRAM FILES\DOTNET\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.1 [C:\PROGRAM FILES\DOTNET\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.2 [C:\PROGRAM FILES\DOTNET\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.3 [C:\PROGRAM FILES\DOTNET\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.4 [C:\PROGRAM FILES\DOTNET\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.5 [C:\PROGRAM FILES\DOTNET\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.6 [C:\PROGRAM FILES\DOTNET\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.7 [C:\PROGRAM FILES\DOTNET\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.8 [C:\PROGRAM FILES\DOTNET\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.9 [C:\PROGRAM FILES\DOTNET\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.11 [C:\PROGRAM FILES\DOTNET\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.12 [C:\PROGRAM FILES\DOTNET\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.13 [C:\PROGRAM FILES\DOTNET\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.22 [C:\PROGRAM FILES\DOTNET\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.2.0 [C:\PROGRAM FILES\DOTNET\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.2.5 [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.8 [C:\PROGRAM FILES\DOTNET\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 1.0.1 [C:\PROGRAM FILES\DOTNET\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.0.6 [C:\PROGRAM FILES\DOTNET\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.0.7 [C:\PROGRAM FILES\DOTNET\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.0.9 [C:\PROGRAM FILES\DOTNET\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.1 [C:\PROGRAM FILES\DOTNET\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.2 [C:\PROGRAM FILES\DOTNET\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.3-servicing-26724-03 [C:\PROGRAM FILES\DOTNET\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.3 [C:\PROGRAM FILES\DOTNET\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.4 [C:\PROGRAM FILES\DOTNET\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.5 [C:\PROGRAM FILES\DOTNET\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.6 [C:\PROGRAM FILES\DOTNET\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.7 [C:\PROGRAM FILES\DOTNET\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.8 [C:\PROGRAM FILES\DOTNET\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.9 [C:\PROGRAM FILES\DOTNET\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.11 [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.13 [C:\PROGRAM FILES\DOTNET\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.22 [C:\PROGRAM FILES\DOTNET\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.2.0 [C:\PROGRAM FILES\DOTNET\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.2.5 [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.8 [C:\PROGRAM FILES\DOTNET\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.0.0 [C:\PROGRAM FILES\DOTNET\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 3.1.8 [C:\PROGRAM FILES\DOTNET\shared\Microsoft.WindowsDesktop.App]

OS Version: Windows 7 / 10 / Ubuntu linux.

Browser: Google Chrome Version 85.0.4183.121 (Official Build) (64 bit)

RobinHood-80 commented 4 years ago

Hi, further investigations showed me another interesting thing. As said, the issue arise only by doing history.back() javascript code but ONLY on a cloned tab. the first original tab does not trigger the exception , when the problem arise i should see the usual CircuitHandler (see console output) event arise, but they are not here, instead when the problem do not arise i see the usual onCirquitXXXX onConnectionXXXX event from my custom circuithandler class.

also i does appear to be a slight difference between navigating back via browser button and doing the same via history.back(). It is more likely that the problem shows up doing a javascript. history.back()

javiercn commented 4 years ago

@RobinHood-80 thanks for contacting us.

I think this is caused by the caching headers not being properly set. You can set them on a meta tag on _Host.cshtml or as a header in the HTTP response.

RobinHood-80 commented 4 years ago

Hello, Thx for your reply, however: i've already tr i ed this solution. Maybe the browser does not honour the meta tags (it is known they are not so reliable), so i've tryed also with http headers, with no luck. is there a way or a centralized place in asp.net where i can set the caching headers in a way that it does affect ALL http requests and any other forms of comunications on the wire including the signalR traffic ?

ghost commented 4 years ago

Thanks for contacting us. We're moving this issue to the Next sprint planning milestone for future evaluation / consideration. We will evaluate the request when we are planning the work for the next milestone. To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

ghost commented 4 years ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

ghost commented 4 years ago

Thanks for contacting us. We're moving this issue to the Next sprint planning milestone for future evaluation / consideration. We will evaluate the request when we are planning the work for the next milestone. To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

RobinHood-80 commented 3 years ago

Hi, after some testing i've verified that the problem disappear if the proper http header for cache management is sent to the browser. So i confirm it's a cache issue. Thx, for support.