wails icon indicating copy to clipboard operation
wails copied to clipboard

MacOS HTMX polling fails

Open difof opened this issue 1 year ago • 0 comments

Description

Whenever I use HTMX polling, only the first request is received by Go and the rest won't even show up in inspector's network. This works on all major browsers using wails exposed http interface though. Enabling HTMX logs via htmx.logAll() shows the XHR and other HTMX events caused by the polling, yet only one network request is made.

To Reproduce

  1. On MacOS, create a basic wails project wails init -n htmx-test -t vanilla
  2. Import HTMX script in frontend/index.html
<script src="https://unpkg.com/[email protected]"></script>
  1. Add an HTMX element with polling:
<div hx-get="/now" hx-trigger="load, every 1s"></div>
  1. Use an HTTP middleware for wails asset server. I used echo:
func main() {
	app := NewApp()
        e := echo.New()
	
	e.GET("/now", func(c echo.Context) error {
		return c.String(http.StatusOK, time.Now().Format(time.TimeOnly))
	})

	err := wails.Run(&options.App{
		Title:  "test",
		Width:  1024,
		Height: 768,
		AssetServer: &assetserver.Options{
			Assets: assets,
			Middleware: func(next http.Handler) http.Handler {
				return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
					for _, route := range e.Routes() {
						if route.Path == r.URL.Path {
							e.ServeHTTP(w, r)
							return
						}
					}

					next.ServeHTTP(w, r)
				})
			},
		},
	})

	if err != nil {
		println("Error:", err.Error())
	}
}
  1. Run wails dev and you will get single request to /now

Expected behaviour

HTMX polling to successfully send requests

Screenshots

No response

Attempted Fixes

No response

System Details

MBP M1 2020 16GB
MacOS 14 Sonoma

Additional context

No response

difof avatar Dec 23 '23 17:12 difof