Skip to content

Commit fb24f61

Browse files
mattleibowCopilot
andcommitted
Make BlazorWebView file-provider wrapping opt-in via AppType
The net11.0 base added UsePlatformHandler / IBlazorWebViewHandler and a test (BlazorWebViewUsesCustomHandlerOperations) that asserts CreateFileProvider returns the handler's own file provider by identity. The fingerprinting work wrapped the platform provider whenever a bundled asset manifest was present - even with no AppType - which broke that identity for every app with static web assets. Bind the whole feature (host-page rendering + @assets fingerprinting) to AppType: when AppType is null, return the platform provider unchanged, exactly preserving legacy behaviour. Fingerprinting only needs the wrapper on the AppType path, which is where the manifest's ResourceAssetCollection is injected into the renderer. MacCatalyst device tests: 45 passed, 1 pre-existing skip - including the base's custom-handler tests and the AppType/fingerprint tests together. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 2ca68fe1-bef6-46a6-a0fd-17b7654cef34
1 parent 6f78016 commit fb24f61

1 file changed

Lines changed: 14 additions & 17 deletions

File tree

src/BlazorWebView/src/Maui/BlazorWebView.cs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -165,28 +165,25 @@ public virtual IFileProvider CreateFileProvider(string contentRootDir)
165165
// Call into the platform-specific code to get that platform's asset file provider
166166
var platformFileProvider = GetBlazorWebViewHandler().CreateFileProvider(contentRootDir);
167167

168+
// Everything below is opt-in via AppType. For the legacy HostPage (index.html) path, return
169+
// the platform provider unchanged so existing behaviour - including the handler's own file
170+
// provider instance - is preserved exactly.
171+
if (AppType is null)
172+
{
173+
return platformFileProvider;
174+
}
175+
168176
// Load the bundled static web assets manifest (if present) so that @Assets fingerprinting
169177
// and fingerprinted-route serving work. The manifest lives outside the web root and is read
170178
// from the app package, so it is never served to the web view. Absent (or on platforms
171-
// without app-package access), fingerprinting simply stays off and behaviour is unchanged.
179+
// without app-package access), fingerprinting simply stays off.
172180
var manifest = StaticWebAssetsManifest.TryLoad();
173181

174-
string? hostPageRelativePath = null;
175-
if (AppType is not null)
176-
{
177-
// When AppType is set, render the host document once. This also collects any interactive
178-
// components declared with a render mode and registers them so they attach to the live
179-
// document, and resolves @Assets using the manifest.
180-
EnsureAppTypeRendered(manifest?.Assets);
181-
hostPageRelativePath = Path.GetRelativePath(contentRootDir, HostPage!);
182-
}
183-
184-
// If there is nothing to add (no AppType document and no manifest), return the platform
185-
// provider unchanged to preserve existing behaviour exactly.
186-
if (hostPageRelativePath is null && manifest is null)
187-
{
188-
return platformFileProvider;
189-
}
182+
// Render the host document once. This also collects any interactive components declared with
183+
// a render mode and registers them so they attach to the live document, and resolves @Assets
184+
// using the manifest.
185+
EnsureAppTypeRendered(manifest?.Assets);
186+
var hostPageRelativePath = Path.GetRelativePath(contentRootDir, HostPage!);
190187

191188
return new BlazorWebViewFileProvider(platformFileProvider, hostPageRelativePath, _renderedHostPageHtml, manifest);
192189
}

0 commit comments

Comments
 (0)