bigskysoftware / bigskysoftware/htmx

Base path handling in HTMX 4 differs from HTMX 2

Open
#4,007 2 comments 1 reaction 0 assignees View on GitHub
Dominant language
JavaScript
Stars
49.4k
Forks
1.7k
Avg merge
3d 22h
Merged PRs (30d)
30

Description

I don't know if the following is intended behaviour or a regression. I've found that HTMX 4 differs in its handling of `` to HTMX 2 (and it's a bit annoying, tbh).

When I add `hx-post=""` to an element HTMX 2 will send the request to the current URL, HTMX 4 will only send it to the current URL if there is no `` defined. If there is, then HTMX 4 will send the request instead to the base path.

Here's a minimal reproducible example:

- index.html

```html




HTMX test

click me

```

- main.go

```go
package main

import (
"html/template"
"io"
"log"
"net/http"
)

func main() {
http.HandleFunc("GET /test", index)
http.HandleFunc("POST /", post)
log.Fatal(http.ListenAndServe(":8765", nil))
}

func index(w http.ResponseWriter, r *http.Request) {
tmpl := template.Must(template.ParseFiles("index.html"))
err := tmpl.Execute(w, nil)
if err != nil {
log.Print(err)
}
}

func post(w http.ResponseWriter, r *http.Request) {
_, err := io.WriteString(w, r.URL.Path)
if err != nil {
log.Print(err)
}
}
```

Navigating to `http://localhost:8765/test` and clicking on the `

` will replace its contents with `/test` when using HTMX 2 and with `/` with using HTMX 4.

I didn't find this documented anywhere, so I'm not sure if that's a bug or intended.

Contributor guide

Open the contributing guide

Research direction

Run the minimal reproduction using index.html and main.go, switching between the HTMX 2.0.10 and 4.0.0 script URLs. Compare the request target and decide whether the base-path behavior is intended; done means the behavior is resolved or documented and verified against this example.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.