Skip to content

Move BasePath into Components.Web - #69117

Merged
javiercn merged 3 commits into
mainfrom
copilot/fix-basepath-component-issue
Sep 8, 2026
Merged

Move BasePath into Components.Web#69117
javiercn merged 3 commits into
mainfrom
copilot/fix-basepath-component-issue

Conversation

Copilot AI commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Move BasePath into Microsoft.AspNetCore.Components.Web namespace

  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • There's an open issue for the PR that you are making. If you'd like to propose a new feature or change, please open an issue to discuss the change or find an existing issue.

Move BasePath into Microsoft.AspNetCore.Components.Web

Description

BasePath was introduced under Microsoft.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.

  • Namespace fix: move BasePath to Microsoft.AspNetCore.Components.Web so the component lives with the rest of the browser-facing Blazor primitives.
  • Import cleanup: remove the unnecessary @using Microsoft.AspNetCore.Components.Endpoints from the default template and sample/test app imports to avoid the invalid missing-namespace scenario.
  • API alignment: update the public API metadata to reflect the moved type and keep the shipped contract consistent.
@using Microsoft.AspNetCore.Components.Web

<BasePath />

This keeps the intended app pattern aligned with the framework surface and avoids the silent runtime HTML breakage caused by a missing namespace import.

Copilot AI changed the title [WIP] Fix BasePath component not triggering build error in .NET upgrade Move BasePath into Components.Web Sep 8, 2026
Copilot AI requested a review from javiercn September 8, 2026 12:59
@Youssef1313

Copy link
Copy Markdown
Member

@javiercn #69118 targets release/11.0 and I filled the servicing template there already. I think we can close this PR to main and just get the other PR in.

@javiercn
javiercn marked this pull request as ready for review September 8, 2026 13:37
@javiercn
javiercn requested a review from a team as a code owner September 8, 2026 13:37
Copilot AI lite review requested due to automatic review settings September 8, 2026 13:37
Comment thread src/Components/Endpoints/test/Routing/BasePathTest.cs
@@ -1,5 +1,4 @@
@using Microsoft.AspNetCore.Components.Endpoints


Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: unnecessary blank line

@Youssef1313 Youssef1313 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with small comments 🚀

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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 BasePath into the Microsoft.AspNetCore.Components.Web namespace (and update its unit test accordingly).
  • Remove @using Microsoft.AspNetCore.Components.Endpoints from the Blazor Web project template, samples, and test server razor roots.
  • Update PublicAPI.Unshipped.txt to 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.

@javiercn
javiercn enabled auto-merge (squash) September 8, 2026 14:05
@javiercn
javiercn merged commit 6b886dd into main Sep 8, 2026
31 of 32 checks passed
@javiercn
javiercn deleted the copilot/fix-basepath-component-issue branch September 8, 2026 15:31
Comment on lines +2 to +3
Microsoft.AspNetCore.Components.Web.BasePath
Microsoft.AspNetCore.Components.Web.BasePath.BasePath() -> void

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think @javiercn has more context here due to #64590 (comment)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That host specific behavior doesn't belong on shared abstractions assemblies and that namespace <-> library is not a hard rule, but a common convention.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any reason for having to keep it in .Endpoints.

@javiercn

javiercn commented Sep 8, 2026

Copy link
Copy Markdown
Member

/backport to release/11.0

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Started backporting to release/11.0 (link to workflow run)

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

Labels

None yet

Projects

None yet

6 participants