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
34.51k stars 9.75k forks source link

Issue with OutputCache in Blazor SSR #55534

Open zubairkhakwani opened 1 week ago

zubairkhakwani commented 1 week ago

Is there an existing issue for this?

Describe the bug

Initially, everything functions as expected. However, upon adding the OutputCache attribute, two significant issues arise

  1. Script Functionality Breakdown: Upon revisiting the cached Home page, script functionality becomes non-responsive. Despite logging within the OnUpdate method, the console remains empty, indicating a failure in executing JavaScript functionality. This impedes the user experience and disrupts the intended behavior of the page.
  2. Excessive Reloading with Hash Navigation Furthermore, when navigating to a link within the same page containing a hash (#element), Blazor's JavaScript file (blazor.web.js) inexplicably reloads the page multiple times.

I am using BlazorPageScript nuget package provided by @MackinnonBuck to work with PageScript

If I remove @attribute [OutputCache(Duration = 2000)] it works fine.

Additionally, I've created a Video demonstrating the precise steps to replicate the issues.

https://github.com/dotnet/aspnetcore/assets/38009549/f78fba32-ca14-4874-90dc-5cd0105652c5

Expected Behavior

should works and navigating to #elements in same page should not reload pages multiple times. ### Steps To Reproduce Repo link to reproduce this issue. [minimalistic project which reproduces this issue](https://github.com/zubairkhakwani/BlazorCacheIssue) ### Exceptions (if any) _No response_ ### .NET Version 8.0.204 ### Anything else? _No response_
zubairkhakwani commented 1 week ago

@danroth27 @SteveSandersonMS @mkArtakMSFT I believe that addressing the issue related to Output Cache is crucial for enhancing the performance and scalability of SSR websites. Since this appears to be a solvable bug (Hopefully :D), I propose considering its resolution for inclusion in the .NET 9 release. Thank you for addressing this matter & Thank you for Blazor, Have a good day.