Skip to content

[Validation] Showing content per environment with EnvironmentView #68482

Description

@oroztocil

Scenario contact: @javiercn

Scenario

The EnvironmentView component renders its child content only when the current hosting environment matches its Include and Exclude parameters, following the same semantics as the environment tag helper in MVC and Razor Pages. This validates the matching rules, that hidden content is genuinely absent rather than merely styled out, and that each hosting model reports the environment you expect it to.

Minimum build

.NET 11 Preview 7 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

What to build

A page and a shared layout that between them use EnvironmentView for four kinds of content: something shown only while developing, something shown in any pre-production environment, something hidden in production but shown everywhere else, and something shown only in production. Put at least one in the layout so it appears on every page, and make each visually obvious so you can tell at a glance which rendered.

Also display the current environment name on the page, so you can compare what you configured against what the app reports.

Things to try

  • Running under Development, Production, and your own environment name.
  • An environment name written in a different case than the one the app is running under.
  • Extra spaces around the names in a comma-separated list.
  • The same environment named in both Include and Exclude on one block.
  • An empty Include list, and a block with neither parameter.
  • Nesting one EnvironmentView inside another.
  • Publishing the app and running the published output, especially for standalone WebAssembly.
  • Giving the client project a different environment than the server, then reloading.
  • In Interactive Auto, the first visit and then a reload once the app has been cached.

Expected behavior

Content appears only in the environments it was declared for. Comma-separated lists accept several names with surrounding whitespace ignored, and names match regardless of case. Where an environment is both included and excluded, the exclusion wins. Content that should be hidden is absent from the markup rather than hidden with CSS. Each hosting model reports the environment its own configuration gives it.

Must hold

  • Content restricted to an environment renders in that environment and is absent from the page source in every other one, rather than present but hidden.
  • An environment name written in a different case than the running environment still matches.
  • Names separated by commas with surrounding spaces all match.
  • An environment named in both Include and Exclude renders nothing.
  • A block with an empty Include list, and a block with neither parameter, both render in every environment.
  • Where the client project is configured with a different environment than the server, the content left on screen once the component is interactive matches the environment the client reports.

Expected differences between configurations

  • A published standalone WebAssembly app takes its environment from the host serving it and reports Production unless that host says otherwise, so environment-dependent content can differ between running locally and running from a published deployment.
  • In Interactive Auto the first visit renders on the server and later visits render in the browser, so if the two sides are configured with different environments the same page shows different content before and after the app is cached.

Documentation to use

What to report

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

Metadata

Metadata

Labels

ValidationThis issue is used to track validation effortsarea-blazorIncludes: Blazor, Razor Componentsvalidation-scenarioThis issue describes a validation testing scenario

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions