formaui-net.Framework.Themes.Blazor.Server 1.0.0-preview.27

Prefix Reserved
This is a prerelease version of formaui-net.Framework.Themes.Blazor.Server.
dotnet add package formaui-net.Framework.Themes.Blazor.Server --version 1.0.0-preview.27
                    
NuGet\Install-Package formaui-net.Framework.Themes.Blazor.Server -Version 1.0.0-preview.27
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="formaui-net.Framework.Themes.Blazor.Server" Version="1.0.0-preview.27" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="formaui-net.Framework.Themes.Blazor.Server" Version="1.0.0-preview.27" />
                    
Directory.Packages.props
<PackageReference Include="formaui-net.Framework.Themes.Blazor.Server" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add formaui-net.Framework.Themes.Blazor.Server --version 1.0.0-preview.27
                    
#r "nuget: formaui-net.Framework.Themes.Blazor.Server, 1.0.0-preview.27"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package formaui-net.Framework.Themes.Blazor.Server@1.0.0-preview.27
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=formaui-net.Framework.Themes.Blazor.Server&version=1.0.0-preview.27&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=formaui-net.Framework.Themes.Blazor.Server&version=1.0.0-preview.27&prerelease
                    
Install as a Cake Tool

Forma.Framework.Themes.Blazor.Server

The server's half of Forma's theme system. It resolves the theme choice each request starts in, so a server-rendered page is drawn in the reader's theme and scheme from its first paint, keeps the browser's record of the choice beside a host's store, and takes a switch a statically rendered picker posts, as the theme design sets out.

Install

dotnet add package formaui-net.Framework.Themes.Blazor.Server --prerelease

AddFormaServerIntegration(), in formaui-net.Blazor.Server, registers it ahead of the component library's own registration, so a request's scope draws the request's choice. A host that registers the theme system itself calls AddFormaThemeServerIntegration() ahead of AddFormaUIServices().

Setting it up

The pipeline resolves each request's choice before its page renders, and maps the endpoint a statically rendered picker posts a switch to:

var app = builder.Build();

app.UseFormaThemes();
app.UseRouting();

app.MapStaticAssets();
app.MapFormaThemes();

The host's App writes the choice on <html>, as it writes lang and dir, and FormaPageHead links every registered theme's stylesheet and publishes the theme marker the page reads:

@using Forma.Framework.Themes
@inject ThemeRegistry Themes
@inject IThemeState ThemeState

<!DOCTYPE html>
<html lang="en" @attributes="ThemeAttributes.Of(Themes, ThemeState.Choice)">

The choice a request starts in

A request starts in the first of these that names a registered theme:

  1. the choice the host gives the request, ServerIntegrationOptions.GivenThemeChoice;
  2. the host's store's choice, an IThemePreferenceStore the host registers, where its revision is greater than the one the browser's record agreed with, or the browser has no record;
  3. the browser's record;
  4. the registration's default.

A choice naming a theme that isn't registered starts in the default theme in its scheme preference, and a response that starts in the store's choice writes it into the record with the store's revision. A store that fails to read leaves the request in the record or the default, and writes a warning.

The record is the cookie __Host-forma-theme over HTTPS, so only the page's own origin sets it, and forma-theme over plain HTTP, as a development host serves, where a browser refuses a secure cookie.

A choice given to a request

A host gives a request its choice where it registers the server's half, for a page drawn in a choice that isn't the reader's, such as a preview in another theme:

builder.AddFormaServerIntegration(options =>
{
    options.GivenThemeChoice = context => context.Request.Query.ContainsKey("preview")
        ? new ThemeChoice("harbor", ColorSchemePreference.Dark)
        : null;
});

The request starts in that choice ahead of the store and the record, and its page keeps nothing: its response writes no record and reads no store, and its theme marker says so.

The switch endpoint

MapFormaThemes() takes a switch at /_forma/themes, which FormaThemePicker posts where it is rendered statically, and any form of the application's own can post too. The form posts theme, a registered theme's name, scheme, system, light or dark, and returnUrl, an address of the application's own. The endpoint keeps the choice in the store first, one revision past the latest it knows of, then in the record with that revision, and sends the reader back. A store that fails leaves the record holding the choice beside the earlier revision, so the browser draws the new choice and the store keeps its earlier one. A form naming no registered theme or no scheme preference is refused with 400, and a return address that isn't the application's own sends the reader to its root.

The endpoint takes a post as ASP.NET Core checks every form an application reads, in one of two ways:

  • By where the post comes from, in an application built with WebApplication that doesn't call UseAntiforgery(). ASP.NET Core reads the Fetch Metadata the browser sends, so the endpoint takes a post from the application's own pages and refuses one another site sends with 400. The application generates no antiforgery token, so the picker's forms carry none.
  • By an antiforgery token, in an application that calls UseAntiforgery(). Each of the picker's forms carries the token its request generates, and the endpoint refuses a post without a valid one with 400.

Caching pages

A page a host caches for readers who aren't signed in is cached once per choice, since the choice is written into the page:

builder.Services.AddOutputCache(options => options.AddBasePolicy(policy => policy.VaryByFormaTheme()));

A page carrying a statically rendered picker is cached only where the application checks a post by where it comes from. An antiforgery token is one reader's: generating it sets the antiforgery cookie and marks the response not to be kept, so a page carrying one isn't cached.

License

Apache License 2.0, under the repository's LICENSE.

Product Compatible and additional computed target framework versions.
.NET net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on formaui-net.Framework.Themes.Blazor.Server:

Package Downloads
formaui-net.Blazor.Server

The server half of Forma's component library: what a host that renders on the server needs beside the components, the document head FormaPageHead and the registration that adds the interactive server circuit's integrations.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0-preview.27 44 12/3/2026
1.0.0-preview.26 50 12/3/2026
1.0.0-preview.25 56 12/2/2026
1.0.0-preview.24 52 12/1/2026
1.0.0-preview.23 69 11/30/2026
1.0.0-preview.22 70 11/30/2026
1.0.0-preview.21 71 11/29/2026

What this release changed is in Forma's changelog: https://github.com/FormaUI/Forma/blob/v1.0.0-preview.27/CHANGELOG.md