Skip to content

feat: don't insert proxy reload script on datastar initiated requests#1235

Merged
a-h merged 2 commits intomainfrom
datastar_proxy_reload
Aug 15, 2025
Merged

feat: don't insert proxy reload script on datastar initiated requests#1235
a-h merged 2 commits intomainfrom
datastar_proxy_reload

Conversation

@a-h
Copy link
Copy Markdown
Owner

@a-h a-h commented Aug 5, 2025

No description provided.

@a-h
Copy link
Copy Markdown
Owner Author

a-h commented Aug 5, 2025

@delaneyj - can you verify this is correct please? My understanding is that there's no need to insert a reload script for live reload (during watch mode) for datastar initiated requests, especially since they're likely to be fragments.

This came up in a conversation in Slack.

@delaneyj
Copy link
Copy Markdown
Contributor

delaneyj commented Aug 5, 2025

I have no idea, I never use the templ proxy as I don't have the need.

I use a Taskfile task

  templ:
    env:
      TEMPL_EXPERIMENT: rawgo
    # deps:
    #   - library
    generates:
      - "**/*_templ.go"
    sources:
      - "**/*.templ"
    cmds:
      - templ generate .

a shared page setup...

<body>
	if site.Env.IsDev {
		<div id="hotreload" data-on-load="@get('/hotreload', {retryMaxCount: 1000,retryInterval:20, retryMaxWaitMs:200})"></div>
	}
	{ children... }
	if site.Env.IsDev {
		<datastar-inspector></datastar-inspector>
	}
</body>

and a Go route...

        var hotReloadOnlyOnce sync.Once
	router.Get("/hotreload", func(w http.ResponseWriter, r *http.Request) {
		sse := datastar.NewSSE(w, r)
		hotReloadOnlyOnce.Do(func() {
			sse.ExecuteScript("window.location.reload()")
		})
		<-r.Context().Done()
	})

That way I get auto loading of anything from css, images, go, etc so my frontend and backend are always in sync. If there is something specific you need please let me know but I don't think Datastar needs the proxy at all given the builtin SSE support with auto reconnect.

@a-h
Copy link
Copy Markdown
Owner Author

a-h commented Aug 6, 2025

Thanks @delaneyj - hope all is well with you and family by the way!

@delaneyj
Copy link
Copy Markdown
Contributor

delaneyj commented Aug 6, 2025

Thanks @delaneyj - hope all is well with you and family by the way!

You as well! Would be nice to catch up when you have time!

@a-h a-h merged commit 40be321 into main Aug 15, 2025
9 checks passed
@a-h a-h deleted the datastar_proxy_reload branch August 15, 2025 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants