Skip to content

Add URL and URLSearchParams browser platform APIs - #69925

Merged
ilonatommy merged 8 commits into
dotnet:mainfrom
MayaKirova:mkirova/url-api
Nov 4, 2026
Merged

ilonatommy merged 8 commits into
dotnet:mainfrom
MayaKirova:mkirova/url-api

Conversation

@MayaKirova

@MayaKirova MayaKirova commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Project URL and URLSearchParams through the Components Platform package, including caller-owned URL lifetimes, live search parameter iterators, unit coverage, and Interactive Server and WebAssembly browser tests.

Add URL and URLSearchParams browser platform APIs

  • 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.

Summary of the changes (Less than 80 chars)

Description

Add typed URL and URLSearchParams browser APIs

Description

Projects the browser URL and URLSearchParams APIs through Microsoft.AspNetCore.Components.Platform.

  • Adds Window.Url and Window.UrlSearchParams constructor facades.
  • Supports URL construction, parsing, validation, property access, mutation, and serialization.
  • Makes caller-created Url instances caller-owned through IAsyncDisposable.
  • Exposes Url.SearchParams as a stable, non-disposable borrowed wrapper.
  • Uses UrlSearchParamsOwner for independently constructed query parameter collections.
  • Supports string, record, and ordered sequence URLSearchParams constructor inputs.
  • Projects live entries(), keys(), and values() iterators as caller-owned asynchronous wrappers.
  • Adds complete XML documentation and updates PublicAPI.Unshipped.txt.
  • Adds focused unit and public API tests.
  • Adds real-browser coverage for Interactive Server and WebAssembly.

URL.createObjectURL(), URL.revokeObjectURL(), and callback-based URLSearchParams.forEach() are deferred. Object URLs require a projected Blob or MediaSource, and JavaScript-to-.NET callbacks do not yet have an established Components Platform design.

API proposal: #69924

Part of #69881

Project URL and URLSearchParams through the Components Platform package, including caller-owned URL lifetimes, live search parameter iterators, unit coverage, and Interactive Server and WebAssembly browser tests.

Co-authored-by: Copilot <[email protected]>
@github-actions github-actions Bot added the area-blazor Includes: Blazor, Razor Components label Oct 19, 2026
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Oct 19, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Thanks for your PR, @MayaKirova. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

MayaKirova and others added 2 commits October 30, 2026 18:46
Resolve the Platform API baseline and test conflicts by retaining both URL and Cookie Store entries.

Co-authored-by: Copilot <[email protected]>
@MayaKirova
MayaKirova marked this pull request as ready for review October 30, 2026 16:53
Copilot AI balanced review requested due to automatic review settings October 30, 2026 16:53
@MayaKirova
MayaKirova requested a review from a team as a code owner October 30, 2026 16:53

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.

🟡 Changes recommended

Valid query names can break interop parsing, and a SearchParams disposal failure can permanently skip URL reference cleanup.

2 open issues
What changed in this PR

Adds typed browser URL and URLSearchParams APIs to Components Platform, supporting the URL feature request in #69881 and API proposal #69924.

Changes:

  • Exposes constructors through Window, with URL parsing, mutation, and serialization.
  • Adds disposable URL and query-parameter wrappers with live asynchronous enumeration.
  • Adds public API checks, unit tests, and browser coverage for Interactive Server and WebAssembly.
File Description
src/​Components/​Platform/​testassets/​PlatformTestApp/​Components/​Pages/​UrlServer.razor Hosts the Interactive Server URL demo.
src/​Components/​Platform/​testassets/​PlatformTestApp.E2E.Tests/​Tests/​StorageTests.cs Tests URL behavior in both render modes.
src/​Components/​Platform/​testassets/​PlatformTestApp.Client/​Pages/​UrlWebAssembly.razor Hosts the WebAssembly URL demo.
src/​Components/​Platform/​testassets/​PlatformTestApp.Client/​Components/​UrlDemo.razor Exercises URL operations and live enumeration.
src/​Components/​Platform/​test/​UrlTest.cs Covers interop forwarding, enumeration, cancellation, and disposal.
src/​Components/​Platform/​test/​PublicApiTest.cs Checks disposal and asynchronous API contracts.
src/​Components/​Platform/​src/​WindowUrlExtensions.cs Exposes URL constructor facades through Window.
src/​Components/​Platform/​src/​UrlSearchParamsConstructor.cs Supports empty, string, record, and sequence inputs.
src/​Components/​Platform/​src/​UrlSearchParams.cs Implements query operations and live async enumeration.
src/​Components/​Platform/​src/​UrlConstructor.cs Implements URL construction, parsing, and validation.
src/​Components/​Platform/​src/​Url.cs Wraps URL properties, serialization, and ownership.
src/​Components/​Platform/​src/​PublicAPI.Unshipped.txt Records the new public API surface.

Review effort: Balanced

Comment thread src/Components/Platform/src/Url.cs Resolved
MayaKirova and others added 3 commits November 3, 2026 09:44
Refactor disposal logic to ensure _searchParams is checked before disposal and use finally block for _reference disposal.

Co-authored-by: Copilot Autofix powered by AI <[email protected]>

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.

🔵 Needs a closer look

Unresolved issues allow pending SearchParams acquisition to leak a browser reference after disposal and cause iterator advancement to fail when reflection-based JSON serialization is disabled.

No open issues 🎉

2 previously missed issues

In code that hasn't changed since last review

Medium severity Release SearchParams references acquired after URL disposal

src/​Components/​Platform/​src/​UrlSearchParams.cs:241

Disposing a URL while its first SearchParams reference acquisition is pending skips cleanup permanently; the awaiting operation can then use the late reference, which remains cached in the browser. Release late references and reject the awaiting operation in the acquisition-completion path, without making DisposeAsync wait. Extend UrlDisposal_DoesNotWaitForPendingSearchParamsAcquisition to complete acquisition after disposal and assert that the returned reference is released.

Medium severity Provide source-generated JSON metadata for iterator results

src/​Components/​Platform/​src/​UrlSearchParams.cs:263

With reflection-based JSON serialization disabled and source-generated circuit resolvers configured, the first iterator advance fails because no resolver supplies metadata for IteratorResult. Application source-generated contexts cannot reference this private nested type. Use JsonElement with registered metadata and read its done/value fields, or supply package-owned serialization metadata for the internal result.

2 resolved since last review

Review effort: Balanced

@ilonatommy ilonatommy 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.

Looks great. Posting a few small ideas.

Comment thread src/Components/Platform/src/Url.cs Resolved
Comment thread src/Components/Platform/test/UrlTest.cs Resolved
Comment thread src/Components/Platform/test/UrlTest.cs Resolved
@ilonatommy

Copy link
Copy Markdown
Member

/azp run aspnetcore-components-e2e

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@ilonatommy
ilonatommy merged commit 9593835 into dotnet:main Nov 4, 2026
32 checks passed
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

⚠️ Documentation appears necessary, but a draft PR could not be created.

Confidence that documentation is needed: 85%

Drafted a new Blazor JS interop article for the browser URL and URLSearchParams APIs, with a TOC entry scoped to 12.0+. The IBrowserPlatform xref wasn't verified against dotnet-api-docs.

Documentation surfaces considered

  • Conceptual article: Required — New public Url/UrlSearchParams/WindowUrlExtensions APIs in PublicAPI.Unshipped.txt.
  • Migration guidance: Not required — New opt-in APIs; no upgrade action.
  • Breaking change: Not required — Purely additive; no removed or changed behavior.

This branch was previously deployed

1 inactive deployment
copilot-pat-pool — f76c23f7 Deployed Nov 4, 2026 by ilonatommy via conclusion #189
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-blazor Includes: Blazor, Razor Components community-contribution Indicates that the PR has been added by a community member feature-blazor-jsinterop This issue is related to JSInterop in Blazor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants