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

Fix live reload when both CSS and HTML changes #12601

Merged
merged 1 commit into from
Jun 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions commands/hugobuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,29 @@ func (c *hugoBuilder) handleEvents(watcher *watcher.Batcher,
livereload.RefreshPath(pathToRefresh)
} else {
livereload.ForceRefresh()
// See https://github.com/gohugoio/hugo/issues/12600.
// If this change set also contains one or more CSS files, we need to
// refresh these as well.
var cssChanges []string
var otherChanges []string

for _, ev := range changed {
if strings.HasSuffix(ev, ".css") {
cssChanges = append(cssChanges, ev)
} else {
otherChanges = append(otherChanges, ev)
}
}

if len(otherChanges) > 0 {
livereload.ForceRefresh()
// Allow some time for the live reload script to get reconnected.
time.Sleep(100 * time.Millisecond)
}

for _, ev := range cssChanges {
livereload.RefreshPath(h.PathSpec.RelURL(paths.ToSlashTrimLeading(ev), false))
}
}
}

Expand Down
Loading