gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
74.74k stars 7.45k forks source link

`--watch` not working with helix-editor #12677

Open urbantrout opened 1 month ago

urbantrout commented 1 month ago

What version of Hugo are you using (hugo version)?

$ hugo version
hugo v0.129.0+extended darwin/amd64 BuildDate=2024-07-17T13:29:16Z VendorInfo=brew

Steps to reproduce:

  1. Run hugo server or hugo --watch
  2. Change files in Helix

Expected result

Hugo reacts to file changes and rebuilds pages

Actual result

Hugo reacts to file changes and builds pages, but not all of them and the output is the same as the one without the changes.

This only happens in Helix editor. In vim everything works as expected.

bep commented 1 month ago

Could you try to run

hugo server --logLevel info

And note the lines with livereload in them when you change something.

You could also try hugo server --poll 1s. If that works, the Helix must doing some non-standard way of saving files that does not trigger the expected fs events.

urbantrout commented 1 month ago

This is the output with --logLevel info

Change detected, rebuilding site (#1).
2024-07-25 16:35:34.441 +0200
Template added /_default/baseof.htmlc3gzwd.bck
Template added /_default/baseof.html
INFO  build:  step process substep resolve content adapter change set changes 2 checked 2 matches 0 duration 36.901µs
INFO  build:  step process substep resolve page output change set changes 2 checked 448 matches 0 duration 3.843363ms
INFO  build:  step process substep gc dynacache duration 196.695µs
INFO  build:  step process substep rebuild templates duration 8.210313ms
INFO  build:  step process duration 13.327644ms
INFO  build:  step assemble duration 777ns
INFO  build:  step render substep pages site de outputFormat html duration 20.021809ms
INFO  build:  step render pages 0 content 0 duration 20.075914ms
INFO  build:  step render deferred count 0 duration 917ns
INFO  build:  step postProcess duration 9.17µs
INFO  build:  duration 33.51625ms
Web Server is available at http://localhost:1313/ (bind address 0.0.0.0)
Total in 33 ms
INFO  livereload: build changed 0 files
urbantrout commented 1 month ago

adding --poll 1s fixes the issue.

urbantrout commented 1 month ago

This is not a hugo issue but a helix issue.

bep commented 1 month ago

This is not a hugo issue but a helix issue.

Well, that's debatable.

Looking at these 2 lines:

Template added /_default/baseof.htmlc3gzwd.bck
Template added /_default/baseof.html

I'm guessing that the above is hinting at the problem; I suspect that Helix saves to a temp file and then renames it, not sure.

urbantrout commented 1 month ago

Looks like it: https://github.com/helix-editor/helix/blob/f34dca797cf696a19466ab2b3f7e1ca6ffa2bcb7/helix-view/src/document.rs#L946

urbantrout commented 1 month ago

Well, that's debatable.

David-Else commented 3 weeks ago

adding --poll 1s fixes the issue.

I just spent the day tearing my hair out trying to solve this problem, and this solved it! Maybe there is some better way to deal with this long term than adding --poll 1s?

kirawi commented 3 weeks ago

This is not a hugo issue but a helix issue.

Well, that's debatable.

Looking at these 2 lines:

Template added /_default/baseof.htmlc3gzwd.bck
Template added /_default/baseof.html

I'm guessing that the above is hinting at the problem; I suspect that Helix saves to a temp file and then renames it, not sure.

I'd be surprised if this was the issue. Vim also writes to a temporary file and renames it.

jmooring commented 3 weeks ago

@kirawi We have a few exclusions related to vim, but nothing for .bck files.

https://github.com/gohugoio/hugo/blob/e1becf1dfe31bec65eca585ac66a2d10f1651e42/commands/hugobuilder.go#L779-L794