Move BasePath into Components.Web - #69117
Conversation
Co-authored-by: javiercn <[email protected]>
Co-authored-by: javiercn <[email protected]>
| @@ -1,5 +1,4 @@ | |||
| @using Microsoft.AspNetCore.Components.Endpoints | |||
|
|
|||
|
|
|||
Youssef1313
left a comment
There was a problem hiding this comment.
LGTM with small comments 🚀
There was a problem hiding this comment.
🟢 Approval recommended
The namespace move is consistently applied across implementation/tests/templates and the public API metadata update matches the new type identity.
Pull request overview
This PR addresses a Razor Components upgrade pitfall where using <BasePath /> without importing Microsoft.AspNetCore.Components.Endpoints can silently emit a literal <BasePath /> tag and break <head> parsing. It resolves this by relocating the BasePath component into the Microsoft.AspNetCore.Components.Web namespace and then removing now-unnecessary @using Microsoft.AspNetCore.Components.Endpoints directives from templates/samples/test assets, while aligning the Endpoints assembly public API metadata.
Changes:
- Move
BasePathinto theMicrosoft.AspNetCore.Components.Webnamespace (and update its unit test accordingly). - Remove
@using Microsoft.AspNetCore.Components.Endpointsfrom the Blazor Web project template, samples, and test server razor roots. - Update
PublicAPI.Unshipped.txtto reflect the new fully-qualified API name.
File summaries
| File | Description |
|---|---|
| src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Components/_Imports.razor | Removes unnecessary Endpoints namespace import from the default template imports. |
| src/Components/test/testassets/Components.TestServer/RazorComponents/Root.razor | Removes Endpoints import; relies on Microsoft.AspNetCore.Components.Web for <BasePath />. |
| src/Components/test/testassets/Components.TestServer/RazorComponents/RemoteAuthenticationApp.razor | Removes Endpoints import so <BasePath /> resolves via Web namespace imports. |
| src/Components/test/testassets/Components.TestServer/RazorComponents/Pages/ResourceCollection/Index.razor | Removes Endpoints import; keeps Web import for component usage. |
| src/Components/test/testassets/Components.TestServer/RazorComponents/NamedFormContextNoFormContextApp.razor | Removes Endpoints import; <BasePath /> resolves via Web namespace. |
| src/Components/test/testassets/Components.TestServer/RazorComponents/App.razor | Removes Endpoints import; continues using Web namespace. |
| src/Components/Samples/BlazorWebAppPerPage/Components/_Imports.razor | Removes Endpoints import from sample app imports. |
| src/Components/Samples/BlazorWebAppGlobal/Components/_Imports.razor | Removes Endpoints import from sample app imports. |
| src/Components/Endpoints/test/Routing/BasePathTest.cs | Updates test namespace to match the component’s new namespace. |
| src/Components/Endpoints/src/Routing/BasePath.cs | Moves BasePath component type into Microsoft.AspNetCore.Components.Web. |
| src/Components/Endpoints/src/PublicAPI.Unshipped.txt | Updates unshipped API entries to the new namespace-qualified name. |
Review details
- Files reviewed: 11/11 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
| Microsoft.AspNetCore.Components.Web.BasePath | ||
| Microsoft.AspNetCore.Components.Web.BasePath.BasePath() -> void |
There was a problem hiding this comment.
The mismatch between the namespace and assembly sounds weird to me.
The PR at some point was moving it to the other assembly, what was the reason to change it back here?
There was a problem hiding this comment.
I think @javiercn has more context here due to #64590 (comment)
There was a problem hiding this comment.
That host specific behavior doesn't belong on shared abstractions assemblies and that namespace <-> library is not a hard rule, but a common convention.
There was a problem hiding this comment.
I don't see any reason for having to keep it in .Endpoints.
|
/backport to release/11.0 |
|
Started backporting to |
Move BasePath into
Microsoft.AspNetCore.Components.WebnamespaceMove BasePath into Microsoft.AspNetCore.Components.Web
Description
BasePathwas introduced underMicrosoft.AspNetCore.Components.Endpoints, which is not a namespace most Blazor apps import by default. In upgraded apps, using<BasePath />without the extra import could leave a literal tag in the rendered HTML and break the document head.BasePathtoMicrosoft.AspNetCore.Components.Webso the component lives with the rest of the browser-facing Blazor primitives.@using Microsoft.AspNetCore.Components.Endpointsfrom the default template and sample/test app imports to avoid the invalid missing-namespace scenario.This keeps the intended app pattern aligned with the framework surface and avoids the silent runtime HTML breakage caused by a missing namespace import.