Fix bare else attribute emitted by every Button - #65
Open
methodofaction wants to merge 1 commit into
Open
Conversation
templ v0.3.1001 mis-generates an `if / else if` chain inside an element's
attribute list. In button.templ the chain selecting the `type` attribute
generated code that writes a literal " else" into the markup *outside* any
conditional, and demotes the else-branch to an independent `if`:
} // end of `if btn.Type != ""`
WriteString(..., " else") // unconditional
if btn.Copy != "" { ... } // no longer mutually exclusive
Two consequences: every non-anchor Button rendered a bare `else` attribute,
and a Button with both Type and Copy set would emit two `type` attributes.
Browsers ignore the unknown attribute so nothing broke at runtime, but the
markup fails validation.
Replace the chain with two independent, mutually exclusive conditions, and
note on the func doc comment why `else if` is avoided here so it doesn't get
folded back. Verified by rendering Buttons across all four Type/Copy
combinations: correct single `type` attribute, Type taking precedence over
Copy, and no bare `else`.
A sweep of the other 16 `else if` uses in .templ files found none in
attribute position — grepping the committed *_templ.go files for the
literal matched only button_templ.go.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
✅ Deploy Preview for popui-go ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
mariocnovoa
approved these changes
Aug 24, 2026
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.
What
button.templused anif / else ifchain inside the<button>element's attribute list to select thetypeattribute. The pinned templ version (v0.3.1001, pergo.mod) mis-generates this pattern.Replaced it with two independent, mutually exclusive conditions:
Why
The generated code wrote a literal
" else"into the markup outside any conditional, and demoted the else-branch to an independentif:Two consequences, both broader than a bare
Type-only issue:elseattribute — not just ones settingType.TypeandCopyset would emit twotypeattributes.Browsers ignore the unknown
elseattribute and take the firsttype, so nothing broke at runtime — but the markup fails validation. This is pre-existing atmain, not introduced by recent work.Reviewer notes
Other
else ifsites are safe. 16 exist across.templfiles. The authoritative check was grepping the ~255 committed*_templ.gofiles for the emitted literal — onlybutton_templ.gomatched. The rest are element-content position (checkbox,radio,toast,notification,filter,description_list), which templ compiles correctly; theselect.templhits are JavaScript inside a script block.Why the comment is on the func doc, not next to the code. templ rejects
//comments in attribute position outright. In element-content position it silently strips the comment text but emits the surrounding whitespace — an earlier attempt produced a strayWriteString(..., " ")before<button>. The doc-comment placement has zero output impact.Regeneration. Do not use a globally-installed
templCLI if it is newer than thego.modpin — it rewrites all*_templ.gofiles withtempl.ResolveAttributeValue, which the pinned runtime lacks. This was regenerated with:The
button_templ.godiff is the semantic change plus sequential index renumbering; noResolveAttributeValuecontamination.assets/popui.cssis unchanged (no new utility classes).Heads-up for anyone regenerating:
templ generatereportedupdates=0on runs where it did rewrite files. The counter is unreliable — verify againstgit status.Verification
Rendered Buttons through the real component and asserted the opening tag:
type=elseType: "submit"submitType: "submit", Copy: "x"submit(single attr)Copy: "x"buttongo generate ./...,go build ./...,go vet ./...,go test ./...all clean.🤖 Generated with Claude Code