gitstack
closed

`textarea` / `input` / `modal` / `markdown` component elements fail code generation in pure components (no receiver)

#111
cylixlee · 2026-07-02T12:03:45Z view on GitHub

Description

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

  1. generateComponent() at internal/tuigen/generator_component.go:22 resets g.currentReceiver = "".
  2. generateFunctionComponent() never sets currentReceiver so it remains empty.
  3. When generateComponentElementWithRefs() at internal/tuigen/generator_element.go:464 emits app.MountPersistent(g.currentReceiver, ...), the empty string produces MountPersistent(, 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:

  1. Emit nil as the parent argument for pure components (if MountPersistent accepts nil), or
  2. Report a clear compile-time error telling the user that component elements require a receiver (struct components).

Environment

  • go-tui (version/commit: current main)
grindlemire grindlemire · 2026-07-01T18:36:51Z

Thanks for the report! Let me look into it

grindlemire grindlemire · 2026-07-02T11:19:18Z

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.