fix: dont delete dev-mode text files during a one-off generate#1434
Open
Napam wants to merge 1 commit into
Open
fix: dont delete dev-mode text files during a one-off generate#1434Napam wants to merge 1 commit into
Napam wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Running a one-off
templ generatewhile atempl generate --watchdev server is up breaks every page the running dev server tries to render.--watchwrites each template's literals to a temporary_templ.txtfile; a server run withTEMPL_DEV_MODE=truerenders from those files. ButgeneratecalleddeleteWatchModeTextFiles()on every run, including non-watch ones which don't own these files. So a one-off generate deletes the.txtfiles of a separate running watch session, and every render then fails with a missing-file error. The watch session doesn't recover either. It skips rewriting files whose literals are unchanged.Repro: start a watch-mode dev server (
templ generate --watchplus an app run withTEMPL_DEV_MODE=truethat renders from the.txtfiles), then run a plaintempl generate(e.g. a CI/check step that verifies generated code is up to date). The one-off generate wipes the server's.txtfiles and every page then fails to render until the dev session is restarted.Fix
cmd.go: only rundeleteWatchModeTextFiles()in watch mode a one-off generate must not delete files it doesn't own.eventhandler.go: rewrite a_templ.txtfile if it's missing from disk, even when literals are unchanged, so a watch session self-heals.Tests
Two regression tests in
main_test.go; a non-watch generate leaves existing.txtfiles intact, and a deleted.txtfile is recreated on the next regeneration.My use case
I run a dev server while also running static checks quite regularly (especially when using AI agents). Each check runs a plain
templ generate, which was wiping the dev server's_templ.txtfiles and leaving it unable to render any page until I restarted it.AI disclaimer
I used Claude to help write the tests and suggest the fix.