Skip to content

[Validation] Setting BrowserOptions from server code #68815

Done

Description

@oroztocil

Scenario contact: @javiercn

Scenario

Settings that govern how a Blazor app behaves in the browser, such as how noisy its logging is and how hard it tries to reconnect after losing its connection, have traditionally been written in JavaScript at the bottom of a page. That puts them out of reach of configuration files, feature flags and anything that varies per request. This validates that those settings can be decided in server code instead, including differently for different visitors.

Minimum build

.NET 11 RC1 or later.

Configurations to cover

  • Blazor Web App
    • Static SSR
    • Interactive Server
    • Interactive WebAssembly
    • Interactive Auto
  • Standalone WebAssembly
  • Hybrid (MAUI)

Also exercise

  • Published output
  • An existing .NET 10 app upgraded to .NET 11
  • Trimming or ahead-of-time compilation
  • More than one server instance, or a proxy in front
  • Hot Reload
  • An IDE as well as the command line
  • Container

Setup

You need to be able to stop and restart the server while the browser stays open, so you can watch what happens to a live app when its connection drops and comes back.

Two places set these options, and both are worth covering:

  • MapRazorComponents<App>().WithBrowserOptions(...) in server startup, which applies to the whole endpoint.
  • A <ConfigureBrowser Options="..." /> component in the page, which can vary per request.

BrowserOptions.GetBrowserOptions(httpContext) reads what is currently in effect.

What to build

An app whose browser-side behavior is decided in server code rather than in a script on the page. Through WithBrowserOptions, set LogLevel, and set InteractiveServer.ReconnectionMaxRetries and InteractiveServer.ReconnectionRetryInterval to something clearly different from the default, such as far fewer attempts spaced further apart. Point InteractiveServer.ReconnectionDialogId at reconnection UI of your own so you can tell yours from the built-in one.

Then add a <ConfigureBrowser> in the page that varies some of these by request, for example turning detailed logging on only for requests carrying a particular query string or header, or only for a signed-in administrator, so you can compare two browsers side by side.

Add a page whose content changes when you navigate to it, and drive StaticServer.PreserveDom from the server, so you can see the effect of DOM preservation being switched off.

Things to try

  • Loading the app and watching the browser console for the amount of logging you asked for.
  • Loading it again with the condition that turns on detailed logging, and comparing.
  • Opening two browsers at once, one meeting the condition and one not.
  • Stopping the server while the app is open, and watching the reconnection attempts and your own reconnection dialog.
  • Restarting the server and seeing whether the app recovers.
  • Stopping it for longer than your reconnection settings allow, so the attempts run out.
  • Navigating between pages with StaticServer.PreserveDom set to true and to false.
  • Setting an option at the endpoint and overriding it per request with <ConfigureBrowser>, to see which wins.
  • Reading back the values with BrowserOptions.GetBrowserOptions(httpContext) and comparing them with what the browser actually did.
  • Removing the server-side settings entirely to confirm the defaults return.

Expected behavior

Options set in server code reach the browser, and options that vary by request vary independently for each visitor.

Must hold

  • The browser console shows the level set in LogLevel, not the default level.
  • Reconnection follows ReconnectionMaxRetries and ReconnectionRetryInterval rather than the defaults, and the dialog named by ReconnectionDialogId is used instead of the built-in one.
  • Two browsers loading the app at the same time, one meeting the request-based condition and one not, receive different settings.
  • Setting StaticServer.PreserveDom to false visibly stops DOM preservation across enhanced navigation, and true restores it. This property is the inverse of the underlying option, so confirm the sense is not flipped.
  • When the attempts run out, the app reaches the same end state it would have reached with the defaults.
  • Removing the server-side configuration restores the default behavior with nothing left over.

Expected differences between configurations

  • Reconnection behavior is only observable in the configurations that keep a live connection to the server. In Interactive Auto it applies on the visits that run on the server.

Documentation to use

The API names above were taken from the shipped code, not from docs. If you cannot find this documented anywhere, say so in the report.

What to report

Report results using the format described in the validation testing manual. Include link to a repository with the test app.

Note

Disclaimer: This validation scenario may have been written with AI assistance and may contain errors. It is a testing aid, not an official specification of intended behavior or security guarantees. Its expectations alone do not establish a bug or vulnerability. Verify suspected issues independently against official documentation and reproducible product behavior before reporting them.

Activity

  1. added
    Validation
    validation-scenario
    area-blazor
    on Aug 26, 2026
  2. added this to the 11.0-rc2 milestone on Aug 26, 2026
  3. self-assigned this
    on Aug 27, 2026
  4. irfanajaffer commented on Sep 4, 2026

    @irfanajaffer
    Contributor

    Test report

    • Build tested: .NET SDK 11.0.100-preview.7.26381.103
    • Configurations tested: Blazor Web App - Static SSR, Interactive Server, and Interactive Auto
    • Also exercised: endpoint and per-request options; normal versus detailed browser logging; custom reconnect UI; reconnect timing, recovery, and exhaustion; first and cached Interactive Auto visits; enhanced navigation with both PreserveDom values; concurrent visitors; and two Interactive Server instances behind a YARP proxy
    • OS and tools: Windows 11; Chromium-based browsers with DevTools; Visual Studio Code and the command line
    • Sample app and evidence: BrowserOptionsServerConfiguration
    • Related API issue: GetBrowserOptions(HttpContext) usage in #68815 does not match the shipped API invocation #69045
    • Outcome: works with issues. Reconnection behavior, proxy routing and affinity, and Interactive Auto execution-mode behavior passed. Browser LogLevel differentiation and the PreserveDom inverse behavior failed. Effective request and visitor isolation could not be demonstrated because browser logging did not provide a behavioral discriminator.

    All three samples built with zero warnings and zero errors.

    Checks

    Check Result Evidence/observation
    Static SSR, Interactive Server, and Interactive Auto build successfully. Pass Static SSR build, Interactive Server build, Interactive Auto build
    The configured reconnect count and interval are honored. Pass Three attempts occurred at approximately five-second intervals. Retry timing
    The configured reconnect dialog is displayed. Pass Custom reconnect dialog
    An existing page recovers when the server restarts before retries are exhausted. Pass Reconnect recovery
    The page reaches the terminal failed-to-rejoin state after configured retries are exhausted. Pass Retry exhaustion
    Removing BrowserOptions produces the complete default reconnect sequence. Pass Default reconnect comparison
    Interactive Auto uses Server on a fresh visit and WebAssembly on a cached reload. Pass Server-backed visit, cached reload
    Static SSR DOM preservation enabled. Failed The expected enabled-mode behavior was not demonstrated by the validation. The corrected routed fixture reported sameNode=true and clientStatePreserved=true.
    Static SSR DOM preservation disabled. Failed The node was not replaced as expected; the corrected routed fixture also reported sameNode=true and clientStatePreserved=true. PreserveDom comparison
    LogLevel.Warning and LogLevel.Trace produce distinguishable browser output. Fail Both Interactive Server requests emitted the same Blazor Information startup messages. Static SSR output was empty or otherwise non-differentiating. Static SSR comparison, Server normal, Server detailed
    Request-level options override endpoint options. Server merge passed; browser consumption failed The request-level value overrode the endpoint value in the serialized payload, but the browser logging effect remained non-differentiating.
    Two concurrent visitors receive independently applied BrowserOptions. Distribution/isolation passed; browser consumption failed Separate profiles received distinct serialized values with independent request IDs and WebSockets, but browser logging remained non-differentiating. Concurrent visitors
    Multi-instance proxy routing and interactive-session affinity work. Pass Both backends were reached, and each interactive client retained a working sticky WebSocket session. Proxy results
    BrowserOptions remain isolated through multi-instance proxy routing. Distribution/isolation passed; browser consumption failed Routing, affinity, and distinct serialized payload delivery passed, but the browser did not observably apply each client's LogLevel.

    For the logging comparison, the normal request used LogLevel.Warning and the detailed request used LogLevel.Trace. Both Interactive Server requests emitted the same Blazor Information startup messages, including Normalizing '_blazor' and WebSocket connected; no repeatable Trace/Debug distinction appeared.

    Both Ssr.PreserveDom=false and Ssr.PreserveDom=true produced sameNode=true, clientStatePreserved=true, and focusPreserved=false. The validation therefore records both DOM preservation checks as Failed because the expected inverse behavior was not demonstrated. No manual Blazor.start configuration fallback was used.

    Problems

    The API names in #68815 differ from the API surface exposed by the pinned Preview 7 SDK. As in the #68816 validation report, these are issue-description/API-name differences rather than sample build failures.

    Validation issue API Available Preview 7 API Result
    InteractiveServer.ReconnectionMaxRetries Server.ReconnectionMaxRetries Available under a different property path
    InteractiveServer.ReconnectionRetryInterval Server.ReconnectionRetryInterval Available under a different property path
    InteractiveServer.ReconnectionDialogId Server.ReconnectionDialogId Available under a different property path
    StaticServer.PreserveDom Ssr.PreserveDom Available under a different property path
    BrowserOptions.GetBrowserOptions(HttpContext) HttpContext.GetBrowserOptions() from Microsoft.AspNetCore.Components Available with a different method receiver/invocation; the notation in #68815 was not verifiable as written
    WithBrowserOptions(...) WithBrowserOptions(...) Available and tested
    <ConfigureBrowser Options="..." /> <ConfigureBrowser Options="..." /> Available and tested

    The samples therefore used the Preview 7 property paths:

    options.Server.ReconnectionMaxRetries = 3;
    options.Server.ReconnectionRetryInterval = TimeSpan.FromSeconds(5);
    options.Server.ReconnectionDialogId = "validation-reconnect-modal";
    options.Ssr.PreserveDom = true;

    During the original validation, following BrowserOptions.GetBrowserOptions(httpContext) as though BrowserOptions were the receiver produced CS1061, so effective-options readback was recorded as not verifiable. The follow-up investigation in #69045 confirmed that Preview 7 ships the API as an HttpContext extension method:

    using Microsoft.AspNetCore.Components;
    
    BrowserOptions effectiveOptions = httpContext.GetBrowserOptions();

    The namespace is required because it is not included in the Web SDK implicit usings. This corrects the earlier conclusion that no corresponding Preview 7 member exists, but it does not retroactively turn the original effective-options comparisons into passes; those scenarios remain not demonstrated or inconclusive based on the captured behavioral evidence.

    The remaining behavioral problems are:

    • Browser logging did not differ between LogLevel.Warning and LogLevel.Trace.
    • Ssr.PreserveDom=false did not produce the inverse of Ssr.PreserveDom=true; both settings preserved node identity and client state in the corrected enhanced-navigation fixture.
    • Request override precedence and direct/proxy visitor isolation could not be established from effective behavior because the logging signal did not differ.

    Could the scenario owner confirm whether Server and Ssr are the intended Preview 7 property paths, and whether the observed LogLevel and Ssr.PreserveDom=false behavior should be reported as product defects?

    Not covered

    Only the effective-options readback checks that depended on the BrowserOptions.GetBrowserOptions(HttpContext) notation in #68815 were not tested during the original validation. As documented in #69045, the shipped Preview 7 invocation is httpContext.GetBrowserOptions() with Microsoft.AspNetCore.Components imported.

  5. irfanajaffer commented on Sep 4, 2026

    @irfanajaffer
    Contributor

    The application was again tested using .NET SDK 11.0.100-rc.2.26453.114, and the shipped API BrowserOptions.GetBrowserOptions(HttpContext) is available and functioning as expected.

    Validation confirmed both compile-time and runtime availability:

    • The project builds successfully with no compilation errors.
    • BrowserOptions.GetBrowserOptions(HttpContext) resolves correctly and is accessible from application code.
    • Runtime verification returned the expected BrowserOptions instance with the configured values.
    • Browser options configured through WithBrowserOptions(...) and were successfully retrieved and validated.

    I have also published the updated validation sample in the repository and used it as the basis for the verification scenarios:

    [BrowserOptions API Verification Sample](https://github.com/irfanajaffer/BrowseroptionsApiVerification/tree/main)

    In addition, the browser option properties validated in the original scenario remain available and functional in the RC build, including:

    options.InteractiveServer.ReconnectionMaxRetries
    
    options.InteractiveServer.ReconnectionRetryInterval
    
    options.InteractiveServer.ReconnectionDialogId
    
    options.StaticServer.PreserveDom
    

    Based on these validation results, the scenario remains applicable for RC1 and later releases. The shipped API surface was successfully validated, but the behavioral failures observed during validation remain unchanged.

    All originally identified validation concerns have now been addressed and verified. No pending validation work remains for this scenario.

  6. oroztocil commented on Sep 4, 2026

    @oroztocil
    MemberAuthor

    @irfanajaffer Thanks for re-testing with RC1. Do I understand correctly that all the failed checks from the first report #68815 (comment) are fixed in RC1? Or do any of the problems transfer to RC1, when using the latest API?

  7. irfanajaffer commented on Sep 7, 2026

    @irfanajaffer
    Contributor

    @oroztocil ,

    Thanks for the update. We were able to only confirm that the APIs referenced in the issue are available in the RC1 build as expected.

    However, the validation scenarios that were previously documented as failed in my earlier update are still failing even when tested against RC1. The API availability issue appears to be resolved, but the behavioral failures observed during validation remain unchanged.

    Could you please review these failed cases from your end and share your feedback on whether the current behavior is expected or if any additional configuration/testing approach is required?

    Thanks.

  8. modified the milestones: 11.0-rc2, Backlog on Sep 21, 2026
  9. oroztocil commented on Nov 30, 2026

    @oroztocil
    MemberAuthor

    The remaining issue has been tracked and fixed in #70510.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Validationarea-blazorvalidation-scenario

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions