a fork of iceshrimp.net but a tweaked frontend to my personal liking. waow
fediverse social-media social iceshrimp fedi
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

[backend/asp] Fix BlazorSsrHandoffMiddleware not getting triggered

+16 -13
+16 -13
Iceshrimp.Backend/Core/Middleware/BlazorSsrHandoffMiddleware.cs
··· 1 + using System.Collections.Concurrent; 1 2 using System.Reflection; 2 3 using Iceshrimp.Backend.Core.Extensions; 3 4 using Microsoft.AspNetCore.Components.Endpoints; 4 5 5 6 namespace Iceshrimp.Backend.Core.Middleware; 6 7 7 - public class BlazorSsrHandoffMiddleware(RequestDelegate next) : ConditionalMiddleware<BlazorSsrAttribute> 8 + public class BlazorSsrHandoffMiddleware(RequestDelegate next) : IConditionalMiddleware 8 9 { 10 + private static readonly ConcurrentDictionary<Endpoint, bool> Cache = []; 11 + 9 12 public async Task InvokeAsync(HttpContext context) 10 13 { 11 - var attribute = context.GetEndpoint() 12 - ?.Metadata.GetMetadata<RootComponentMetadata>() 13 - ?.Type.GetCustomAttributes<BlazorSsrAttribute>() 14 - .FirstOrDefault(); 15 - 16 - if (attribute != null) 14 + context.Response.OnStarting(() => 17 15 { 18 - context.Response.OnStarting(() => 19 - { 20 - context.Response.Headers.Remove("blazor-enhanced-nav"); 21 - return Task.CompletedTask; 22 - }); 23 - } 16 + context.Response.Headers.Remove("blazor-enhanced-nav"); 17 + return Task.CompletedTask; 18 + }); 24 19 25 20 await next(context); 26 21 } 22 + 23 + public static bool Predicate(HttpContext ctx) 24 + => ctx.GetEndpoint() is { } endpoint && 25 + Cache.GetOrAdd(endpoint, e => e.Metadata.GetMetadata<RootComponentMetadata>() 26 + ?.Type 27 + .GetCustomAttributes<BlazorSsrAttribute>() 28 + .Any() ?? 29 + false); 27 30 28 31 public static void DisableBlazorJsInitializers(RazorComponentsServiceOptions options) 29 32 {