Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions docs/articles/migrate-to-v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ step; see [Version compatibility](version-compatibility.md) for that.
| [Global configuration](#move-global-configuration-to-code) | `<htmx-config>` attributes move to `AddHtmxToolkit()` | **Silent** |
| [Antiforgery](#antiforgery-metadata-is-on-by-default) | Metadata is included by default and no longer stored in `htmx.config` | **Silent** |
| [Toolkit script](#load-the-toolkit-script-as-a-static-asset) | Inline script helpers and `MapHtmxAntiforgeryScript` replaced by a static web asset | Build |
| [URL Tag Helper](#rename-the-url-tag-helper-attributes) | `hx-controller`, `hx-action`, `hx-route-*`, and similar become `asp-*` | **Silent** |
| [URL Tag Helper](#rename-the-url-tag-helper-attributes) | `hx-*` URL attributes become `asp-*`; `hx-host` and `hx-protocol` are removed | **Silent** |
| [Requests](#update-request-handling) | `IsHtmxRequest()` is `false` for history restoration; `Boosted` filter renamed | Build, **silent** |
| [Action result wrappers](#configure-responses-through-responsehtmx) | `IActionResult.Htmx(...)` removed | Build |
| [Polling](#replace-stoppolling) | `StopPolling` removed | Build |
Expand Down Expand Up @@ -219,8 +219,8 @@ HTMX 4.x defines a native `hx-action` attribute, which made the old naming confl
| `hx-route` | `asp-route` |
| `hx-route-*` | `asp-route-*` |
| `hx-all-route-data` | `asp-all-route-data` |
| `hx-host` | `asp-host` |
| `hx-protocol` | `asp-protocol` |
| `hx-host` | Removed |
| `hx-protocol` | Removed |
| `hx-fragment` | `asp-fragment` |

The HTMX request attribute is now required and must be written without a value. In 1.x, `hx-get` was used
Expand Down Expand Up @@ -283,6 +283,10 @@ Check the following while migrating:
See [Links, forms, and buttons](tag-helpers.md#links-forms-and-buttons).
- **An HTMX request attribute with a value throws** when `asp-*` attributes are present, even an empty one such as `hx-get=""`.
An `hx-get="/url"` without `asp-*` attributes is not affected.
- **`hx-host` and `hx-protocol` have no replacement.** They only made the URL absolute, and HTMX 2.x and 4.x
block cross-origin requests by default. For a request to another origin, allow it in the HTMX configuration
and write the URL directly, for example
`hx-get="@Url.Action("Detail", "Speaker", new { id = Model.SpeakerId }, "https", "api.example.com")"`.
- **The Tag Helper order** changed from `-1000` to `-950`, so it runs after the built-in Tag Helpers.
This matters only to custom Tag Helpers that depend on that order.

Expand Down
40 changes: 7 additions & 33 deletions src/Ramstack.HtmxToolkit/TagHelpers/HtmxUrlTagHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace Ramstack.HtmxToolkit.TagHelpers;
/// <c>hx-patch</c>, <c>hx-delete</c>, or HTMX 4.x <c>hx-action</c> attribute together with
/// at least one of the <c>asp-action</c>, <c>asp-controller</c>, <c>asp-area</c>, <c>asp-page</c>,
/// <c>asp-page-handler</c>, <c>asp-route</c>, <c>asp-route-*</c>, <c>asp-all-route-data</c>,
/// <c>asp-host</c>, <c>asp-protocol</c>, or <c>asp-fragment</c> attributes.
/// or <c>asp-fragment</c> attributes.
/// The generated URL is written to the HTMX attribute, which must not have a value.
/// </para>
/// <para>
Expand All @@ -50,8 +50,6 @@ namespace Ramstack.HtmxToolkit.TagHelpers;
[HtmlTargetElement(Attributes = "hx-get," + RouteAttributeName)]
[HtmlTargetElement(Attributes = "hx-get," + RouteValuesDictionaryName)]
[HtmlTargetElement(Attributes = "hx-get," + RouteValuesPrefix + "*")]
[HtmlTargetElement(Attributes = "hx-get," + HostAttributeName)]
[HtmlTargetElement(Attributes = "hx-get," + ProtocolAttributeName)]
[HtmlTargetElement(Attributes = "hx-get," + FragmentAttributeName)]
[HtmlTargetElement(Attributes = "hx-post," + ActionAttributeName)]
[HtmlTargetElement(Attributes = "hx-post," + ControllerAttributeName)]
Expand All @@ -61,8 +59,6 @@ namespace Ramstack.HtmxToolkit.TagHelpers;
[HtmlTargetElement(Attributes = "hx-post," + RouteAttributeName)]
[HtmlTargetElement(Attributes = "hx-post," + RouteValuesDictionaryName)]
[HtmlTargetElement(Attributes = "hx-post," + RouteValuesPrefix + "*")]
[HtmlTargetElement(Attributes = "hx-post," + HostAttributeName)]
[HtmlTargetElement(Attributes = "hx-post," + ProtocolAttributeName)]
[HtmlTargetElement(Attributes = "hx-post," + FragmentAttributeName)]
[HtmlTargetElement(Attributes = "hx-put," + ActionAttributeName)]
[HtmlTargetElement(Attributes = "hx-put," + ControllerAttributeName)]
Expand All @@ -72,8 +68,6 @@ namespace Ramstack.HtmxToolkit.TagHelpers;
[HtmlTargetElement(Attributes = "hx-put," + RouteAttributeName)]
[HtmlTargetElement(Attributes = "hx-put," + RouteValuesDictionaryName)]
[HtmlTargetElement(Attributes = "hx-put," + RouteValuesPrefix + "*")]
[HtmlTargetElement(Attributes = "hx-put," + HostAttributeName)]
[HtmlTargetElement(Attributes = "hx-put," + ProtocolAttributeName)]
[HtmlTargetElement(Attributes = "hx-put," + FragmentAttributeName)]
[HtmlTargetElement(Attributes = "hx-patch," + ActionAttributeName)]
[HtmlTargetElement(Attributes = "hx-patch," + ControllerAttributeName)]
Expand All @@ -83,8 +77,6 @@ namespace Ramstack.HtmxToolkit.TagHelpers;
[HtmlTargetElement(Attributes = "hx-patch," + RouteAttributeName)]
[HtmlTargetElement(Attributes = "hx-patch," + RouteValuesDictionaryName)]
[HtmlTargetElement(Attributes = "hx-patch," + RouteValuesPrefix + "*")]
[HtmlTargetElement(Attributes = "hx-patch," + HostAttributeName)]
[HtmlTargetElement(Attributes = "hx-patch," + ProtocolAttributeName)]
[HtmlTargetElement(Attributes = "hx-patch," + FragmentAttributeName)]
[HtmlTargetElement(Attributes = "hx-delete," + ActionAttributeName)]
[HtmlTargetElement(Attributes = "hx-delete," + ControllerAttributeName)]
Expand All @@ -94,8 +86,6 @@ namespace Ramstack.HtmxToolkit.TagHelpers;
[HtmlTargetElement(Attributes = "hx-delete," + RouteAttributeName)]
[HtmlTargetElement(Attributes = "hx-delete," + RouteValuesDictionaryName)]
[HtmlTargetElement(Attributes = "hx-delete," + RouteValuesPrefix + "*")]
[HtmlTargetElement(Attributes = "hx-delete," + HostAttributeName)]
[HtmlTargetElement(Attributes = "hx-delete," + ProtocolAttributeName)]
[HtmlTargetElement(Attributes = "hx-delete," + FragmentAttributeName)]
[HtmlTargetElement(Attributes = "hx-action," + ActionAttributeName)]
[HtmlTargetElement(Attributes = "hx-action," + ControllerAttributeName)]
Expand All @@ -105,8 +95,6 @@ namespace Ramstack.HtmxToolkit.TagHelpers;
[HtmlTargetElement(Attributes = "hx-action," + RouteAttributeName)]
[HtmlTargetElement(Attributes = "hx-action," + RouteValuesDictionaryName)]
[HtmlTargetElement(Attributes = "hx-action," + RouteValuesPrefix + "*")]
[HtmlTargetElement(Attributes = "hx-action," + HostAttributeName)]
[HtmlTargetElement(Attributes = "hx-action," + ProtocolAttributeName)]
[HtmlTargetElement(Attributes = "hx-action," + FragmentAttributeName)]
[RequiresUnreferencedCode("Razor Page URL generation is not compatible with trimming.")]
public sealed class HtmxUrlTagHelper(IUrlHelperFactory factory, IOptions<HtmxToolkitOptions> options) : TagHelper
Expand All @@ -117,8 +105,6 @@ public sealed class HtmxUrlTagHelper(IUrlHelperFactory factory, IOptions<HtmxToo
private const string PageAttributeName = "asp-page";
private const string PageHandlerAttributeName = "asp-page-handler";
private const string FragmentAttributeName = "asp-fragment";
private const string HostAttributeName = "asp-host";
private const string ProtocolAttributeName = "asp-protocol";
private const string RouteAttributeName = "asp-route";
private const string RouteValuesDictionaryName = "asp-all-route-data";
private const string RouteValuesPrefix = "asp-route-";
Expand Down Expand Up @@ -203,18 +189,6 @@ public sealed class HtmxUrlTagHelper(IUrlHelperFactory factory, IOptions<HtmxToo
[HtmlAttributeName(PageHandlerAttributeName)]
public string? PageHandler { get; set; }

/// <summary>
/// Gets or sets the protocol for the URL, such as <c>http</c> or <c>https</c>.
/// </summary>
[HtmlAttributeName(ProtocolAttributeName)]
public string? Protocol { get; set; }

/// <summary>
/// Gets or sets the host name.
/// </summary>
[HtmlAttributeName(HostAttributeName)]
public string? Host { get; set; }

/// <summary>
/// Gets or sets the URL fragment name.
/// </summary>
Expand Down Expand Up @@ -272,17 +246,17 @@ public override Task ProcessAsync(TagHelperContext context, TagHelperOutput outp
pageName: Page,
pageHandler: PageHandler,
values: routeValues,
protocol: Protocol,
host: Host,
protocol: null,
host: null,
fragment: Fragment);
}
else if (routeLink)
{
url = generator.RouteUrl(
routeName: Route,
values: routeValues,
protocol: Protocol,
host: Host,
protocol: null,
host: null,
fragment: Fragment);
}
else
Expand All @@ -291,8 +265,8 @@ public override Task ProcessAsync(TagHelperContext context, TagHelperOutput outp
action: Action,
controller: Controller,
values: routeValues,
protocol: Protocol,
host: Host,
protocol: null,
host: null,
fragment: Fragment);
}

Expand Down
Loading