Skip to content

fix: stop rebuilding application if text-only changes have occurred in dev mode#1227

Merged
a-h merged 2 commits intomainfrom
issue_1224
Jul 26, 2025
Merged

fix: stop rebuilding application if text-only changes have occurred in dev mode#1227
a-h merged 2 commits intomainfrom
issue_1224

Conversation

@a-h
Copy link
Copy Markdown
Owner

@a-h a-h commented Jul 24, 2025

Fixes #1224, replaces #1190 and #1191.

@a-h a-h requested a review from Copilot July 24, 2025 12:05

This comment was marked as outdated.

@a-h a-h requested a review from Copilot July 24, 2025 12:20
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes issue #1224 by preventing unnecessary application rebuilds when only text literals change in templ files during development mode. The changes introduce a distinction between Go code changes (which require a full rebuild) and text-only changes (which only need browser reload).

Key changes:

  • Split the existing HasChanged function into separate HasGoChanged and HasTextChanged functions
  • Update event handling to track Go changes and text changes separately
  • Refactor the generation command structure to use errgroups for better concurrency management

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
generator/generator.go Splits HasChanged into HasGoChanged and HasTextChanged functions
cmd/templ/generatecmd/watcher/watch.go Minor cleanup removing unused variables
cmd/templ/generatecmd/eventhandler.go Updates event handling to track Go and text changes separately
cmd/templ/generatecmd/cmd.go Major refactoring to use errgroups and separate handling of different change types
Comments suppressed due to low confidence (1)

cmd/templ/generatecmd/cmd.go:180

  • The function name 'groupUntilNoMessagesReceivedFor100ms' contains a magic number. Consider using a constant or making the timeout configurable to improve maintainability.
func (cmd Generate) groupUntilNoMessagesReceivedFor100ms(postGeneration chan *GenerationEvent) (grouped *GenerationEvent, updates int, ok bool, err error) {

@a-h
Copy link
Copy Markdown
Owner Author

a-h commented Jul 24, 2025

Thanks to https://github.com/philip-peterson for triggering the effort to refactor this area.

@a-h a-h mentioned this pull request Jul 25, 2025
@a-h a-h merged commit 17484e5 into main Jul 26, 2025
9 checks passed
@a-h a-h deleted the issue_1224 branch July 26, 2025 15:35
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.

Regression: Templ CLI unnecessarily rebuilds application when text changes inside *.templ files

2 participants