[backend/asp] Fix BlazorSsrHandoffMiddleware not getting triggered
This commit is contained in:
parent
1cccdcb832
commit
55f7b48d80
1 changed files with 16 additions and 13 deletions
|
@ -1,30 +1,33 @@
|
|||
using System.Collections.Concurrent;
|
||||
using System.Reflection;
|
||||
using Iceshrimp.Backend.Core.Extensions;
|
||||
using Microsoft.AspNetCore.Components.Endpoints;
|
||||
|
||||
namespace Iceshrimp.Backend.Core.Middleware;
|
||||
|
||||
public class BlazorSsrHandoffMiddleware(RequestDelegate next) : ConditionalMiddleware<BlazorSsrAttribute>
|
||||
public class BlazorSsrHandoffMiddleware(RequestDelegate next) : IConditionalMiddleware
|
||||
{
|
||||
private static readonly ConcurrentDictionary<Endpoint, bool> Cache = [];
|
||||
|
||||
public async Task InvokeAsync(HttpContext context)
|
||||
{
|
||||
var attribute = context.GetEndpoint()
|
||||
?.Metadata.GetMetadata<RootComponentMetadata>()
|
||||
?.Type.GetCustomAttributes<BlazorSsrAttribute>()
|
||||
.FirstOrDefault();
|
||||
|
||||
if (attribute != null)
|
||||
context.Response.OnStarting(() =>
|
||||
{
|
||||
context.Response.OnStarting(() =>
|
||||
{
|
||||
context.Response.Headers.Remove("blazor-enhanced-nav");
|
||||
return Task.CompletedTask;
|
||||
});
|
||||
}
|
||||
context.Response.Headers.Remove("blazor-enhanced-nav");
|
||||
return Task.CompletedTask;
|
||||
});
|
||||
|
||||
await next(context);
|
||||
}
|
||||
|
||||
public static bool Predicate(HttpContext ctx)
|
||||
=> ctx.GetEndpoint() is { } endpoint &&
|
||||
Cache.GetOrAdd(endpoint, e => e.Metadata.GetMetadata<RootComponentMetadata>()
|
||||
?.Type
|
||||
.GetCustomAttributes<BlazorSsrAttribute>()
|
||||
.Any() ??
|
||||
false);
|
||||
|
||||
public static void DisableBlazorJsInitializers(RazorComponentsServiceOptions options)
|
||||
{
|
||||
var property =
|
||||
|
|
Loading…
Add table
Reference in a new issue