Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: templ generate --watch --proxy triggers 2 browser reload events #891

Open
atipugin opened this issue Aug 19, 2024 · 1 comment
Open
Labels
bug Something isn't working

Comments

@atipugin
Copy link

atipugin commented Aug 19, 2024

Before you begin

Please make sure you're using the latest version of the templ CLI (go install github.com/a-h/templ/cmd/templ@latest), and have upgraded your project to use the latest version of the templ runtime (go get -u github.com/a-h/templ@latest)

Done.

Describe the bug
For some reason templ generate --watch processes same file multiple times on a single save. As result, it triggers several page reloads per change. I disabled all formatters to ensure there's nothing to emit another fs event, but it didn't help.

I've tried to reproduce it inside devcontainer (used mcr.microsoft.com/devcontainers/go:1-1.22-bookworm) and everything works just fine. So I guess the issue is with macOS FS events stuff.

To Reproduce

  1. Start templ generate --watch -v --proxy="http://localhost:8080" --cmd="go run cmd/myapp/main.go"
  2. Change .templ file

Expected behavior
It should emit only one reload event.

Screenshots
SCR-20240819-opao

Untitled.mov

Logs
None.

templ info output

usage: templ <command> [<args>...]

templ - build HTML UIs with Go

See docs at https://templ.guide

commands:
  generate   Generates Go code from templ files
  fmt        Formats templ files
  lsp        Starts a language server for templ files
  version    Prints the version

Desktop (please complete the following information):

  • OS: macOS Sonoma 14.6.1
  • templ CLI version: v0.2.747
  • Go version (go version): go1.23.0 darwin/arm64
  • gopls version (gopls version): v0.16.1

Additional context
None.

@joerdav joerdav changed the title templ generate --watch --proxy triggers 2 browser reload events bug: templ generate --watch --proxy triggers 2 browser reload events Aug 19, 2024
@joerdav joerdav added bug Something isn't working cmd NeedsInvestigation Issue needs some investigation before being fixed labels Aug 19, 2024
@joerdav
Copy link
Collaborator

joerdav commented Aug 19, 2024

I think the issue here is that templ updates the .txt file, but also is has a file watcher on that dir. And then triggers a reload as textUpdated is set to true: https://github.com/a-h/templ/blob/main/cmd/templ/generatecmd/eventhandler.go#L115

The only reason I can see that we would do this is if we were expecting that processes outside of templ to be able to update the dev mode files. @a-h My suggestion is that we do not return updated in this case so that text changes don't result in a double reload?

@linear linear bot removed cmd NeedsInvestigation Issue needs some investigation before being fixed labels Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants