`textarea` / `input` / `modal` / `markdown` component elements fail code generation in pure components (no receiver)
#111Description
Using a component element (<textarea />, <input />, <modal />, <markdown />) inside a pure component (one without a receiver) produces invalid Go code that fails to compile. Struct components (with receiver) work fine.
Steps to Reproduce
Create a .gsx file with:
package main
import tui "github.com/grindlemire/go-tui"
templ MyForm() {
<textarea placeholder="Type here..." />
}
Run tui generate — the generated _gsx.go file contains:
__tui_0 := app.MountPersistent(, 0, func() tui.Component {
return tui.NewTextArea(
tui.WithTextAreaPlaceholder("Type here..."),
)
})
The Go compiler then reports expected operand, found ',' because the first argument to MountPersistent (the parent Component) is missing.
Root Cause
generateComponent()atinternal/tuigen/generator_component.go:22resetsg.currentReceiver = "".generateFunctionComponent()never setscurrentReceiverso it remains empty.- When
generateComponentElementWithRefs()atinternal/tuigen/generator_element.go:464emitsapp.MountPersistent(g.currentReceiver, ...), the empty string producesMountPersistent(, 0, ...)— a syntax error.
The same issue exists in generateStructMount() at internal/tuigen/generator_children.go:233 for @Component() calls inside pure components.
Affected Elements
All component elements as defined in isComponentElement() at internal/tuigen/generator_element.go:17-19:
<textarea /><input /><modal /><markdown />
Expected Behavior
Either:
- Emit
nilas the parent argument for pure components (ifMountPersistentacceptsnil), or - Report a clear compile-time error telling the user that component elements require a receiver (struct components).
Environment
- go-tui (version/commit: current main)
Thanks for the report! Let me look into it
Ok so after some investigation I don't think this is something I can support. Fundamentally these components require app state to work and by definition the pure templ functions do not have an app in them. That said it shouldn't just happily generate broken code so I'll add an error during the codegen step with a clear guidance for what to do instead.