dotnet / dotnet/sdk

Default StaticWebAssetSpaFallbackEnabled to true in Microsoft.NET.Sdk.BlazorWebAssembly

Open
#54,624 0 comments 1 reaction 2 assignees Claimed by @javiercn View on GitHub
Area-AspNetCore untriaged
Dominant language
C#
Stars
3.2k
Forks
1.3k
PR merge metrics
PR metrics pending

Description

## Summary

`StaticWebAssetSpaFallbackEnabled` defaults to `false` in [`Microsoft.NET.Sdk.StaticWebAssets.targets`](https://github.com/dotnet/sdk/blob/main/src/StaticWebAssetsSdk/Targets/Microsoft.NET.Sdk.StaticWebAssets.targets). For projects using `Microsoft.NET.Sdk.BlazorWebAssembly` it is the right default and every Blazor WASM consumer ends up having to opt in:

```xml

true

```

Recent examples on the aspnetcore side that had to add it manually:

- `dotnet/aspnetcore` PR [#66729](https://github.com/dotnet/aspnetcore/pull/66729) (commit `b24ff65cc6`) sets it in the standalone Blazor WebAssembly template, `StandaloneApp`, `Wasm.Performance.TestApp`, `GlobalizationWasmApp`, and removes the legacy `SpaFallback.targets` shim. It also drops `MapFallbackToFile("index.html")` from `Microsoft.AspNetCore.Components.Gateway` now that the SPA fallback is emitted as a `{**fallback:nonfile}` endpoint with `Order=int.MaxValue` in the static-asset manifest.

## Proposal

Have `Microsoft.NET.Sdk.BlazorWebAssembly` (and any other WASM-flavored SDKs) default `StaticWebAssetSpaFallbackEnabled` to `true` so app authors don''t need to set it themselves and consumers of the published static-asset manifest (gateway, `MapStaticAssets` in a hosted server, etc.) get SPA-fallback routing without any extra wiring.

User opt-out remains via setting the property explicitly to `false`.

## Why this matters

- The manifest-side support (`StaticAssetDescriptor.Order`, `Order` parsed at endpoint factory) shipped in dotnet/aspnetcore PR [#65975](https://github.com/dotnet/aspnetcore/pull/65975) and the negotiation-matcher fix shipped in [#65973](https://github.com/dotnet/aspnetcore/pull/65973). With those in place, the only remaining thing standing between a published WASM app and a working SPA fallback served by `MapStaticAssets` is this one MSBuild property.
- It removes the need for `MapFallbackToFile("index.html")` calls from every host that fronts a Blazor WASM app.

cc @javiercn

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.