/gsx:templ-to-gsx-migrationfrom gsx
Guides migration from templ components to gsx, covering declarations, children, generics, cross-package calls, and build coexistence.
Ships in gsx. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
REQUIRED: use the gsx skill for the target idioms. A migration that only
changes syntax carries templ habits over — class helpers, string-built JS and
CSS, Props structs, { Comp(...) } calls — and the gsx skill's rewrite table
is what to convert them to.
| templ | gsx |
|---|---|
templ Foo(args) { } | component Foo(args) { } |
templ (p P) M(args) { } | component (p P) M(args) { } |
@Foo(a, b) | <Foo x={a} y={b}/> |
@p.M(props) | <p.M props={props}/> |
{ children... } | {children}, with a declared children gsx.Node parameter |
@Child(args) { <span>…</span> } | <Child …><span>…</span></Child> |
gsx emits the authored parameter list unchanged; there is no generated
<Name>Props struct. Markup binds parameters by exact name
(<Card title="Hi" featured/>); Go callers use the positional signature
(Card("Hi", true)). children and attrs are ordinary declared parameters:
component Panel(children gsx.Node, attrs gsx.Attrs) {
<section { attrs... }>{children}</section>
}
Use gsx generics directly. Do not keep templ-era wrappers whose only job is to pin a type parameter and delegate.
component Select[T ~string](name string, options []T, selected T, attrs gsx.Attrs) {
<select name={name} { attrs... }>
{ for _, o := range options {
<option selected={o == selected}>{ o }</option>
} }
</select>
}
<Select name="size" options={sizes} selected={current}/>
T ~string fits typed string enums; a type parameter renders directly only
when its constraint is one kind. Element calls infer the type argument, same
package or imported
(<field.Select …/>). A Go caller instantiates explicitly and passes
positionally: field.Select[string]("size", sizes, current, nil).
The tag prefix is the package alias: <ui.Button variant="primary">Save</ui.Button>.
Lowercase names resolve to package-local components too (<entityMeta …/>), so
helpers need not be exported just to get tag syntax.
Write caller attributes directly on the tag; they land in the component's
declared attrs bag, and class merges through the configured class merger:
<card.Panel class="md:col-span-2" data-id={id} hx-get={u}>…</card.Panel>
Don't port templ's templ.Attributes{…} / hand-built gsx.Attrs{{Key: …}}
props. When one call site must pass a whole ordered bag, use
attrs={{ "data-a": "1", "data-b": "2" }} or attrs={bag}.
A semantic wrapper whose only API is forwarded attributes can be an attrs-only value returning the element directly:
func named(name string) func(attrs ...gsx.Attr) gsx.Node {
return func(attrs ...gsx.Attr) gsx.Node {
return <svg viewBox="0 0 24 24" class="size-5" { attrs... }>{ iconPath(name) }</svg>
}
}
var Search = named("search") // <icon.Search class="size-4"/>
templ threads ctx by hand: href={ URLFor(ctx, Page{}, id) }. In gsx,
register the helper as a pipeline filter in gsx.toml; a leading
context.Context parameter is injected and a (string, error) result
unwraps in the attribute hole, propagating the error from Render:
[filters]
url = "example.com/app/routes.URLFor" # func(ctx, page any, args ...any) (string, error)
<a href={ Page{} |> url(id) }>…</a>
Delete thin wrappers that only forward to the real helper.
must() — put the fallible call in the holetempl code wraps fallible helpers in must(...). gsx unwraps a (T, error)
result when the call is the whole hole — text, native attributes, component
inputs, f/js/css holes, pipeline stages — hoisting the call ahead of the
write and returning the error from Render. Delete must() and pass the call
straight through. Inside a struct literal or another call it stays plain Go:
use f`@{call}` for a string field, else a {{ v, err := … }} block.
<form action={formAction(ctx, p)} method="post">
<Inner id={lookupID(ctx, key)}/>
<a href=f`/items/@{lookupID(ctx, key)}`>…</a>
Don't pre-compute into a {{ }} block with if err != nil { return err } for
a value used once; the hole already does that. Reach for the block only when
one result feeds several holes and must be computed once, or when the error
needs wrapping. A helper called with ctx across many templates is better
registered as a filter (the leading context.Context is injected):
{ key |> lookupID }. To handle an error locally instead of returning it, use
an if init: { if id, err := lookupID(ctx, key); err == nil { … } }.
context (templ.WithChildren /
templ.GetChildren).children gsx.Node parameter.So a component that takes children cannot be called across the boundary:
the caller and the child-accepting component must be on the same side.
Childless components cross freely both ways, because gsx.Node and
templ.Component are the same interface (Render(ctx, w) error) — no adapter.
Migrate bottom-up by subtree. Leaves first. A parent moves to gsx only once every child-accepting component it calls is gsx.
templ Page
└── templ Layout (takes children) ← must migrate first
└── gsx Button ← already gsx; childless, crosses freely
A thin templ page wrapper doing @Layout() { @p.Content(props) } can stay
templ until Layout is gsx: the gsx Content embeds as a childless node.
| Generator | Output |
|---|---|
gsx generate | *.x.go |
templ generate | *_templ.go |
templ generate → gsx generate ./... → templ generate (templ now sees the gsx functions) → go build..gsx sources that others reference, not
just the one you edited..templ file: delete its <name>_templ.go too. templ
won't remove it, and the duplicate symbols break the package.gsx may collide with Ghostscript on PATH. Use go tool gsx (tool
directive) or go run github.com/gsxhq/gsx/cmd/gsx.Committing generated .x.go (so go run . works from a clone) needs:
pre-commit hooks that skip *.x.go (a gofmt -w hook is hand-editing
generated code), generation pinned to the module's own gsx version, and a CI
drift gate using git status --porcelain (it also catches new files).
templ kept a newline between inline elements as a space; gsx drops a line
break next to an element or {expr} (the rule is in the gsx skill). Migrated
token-per-line markup renders cramped: Active:true→false. Put the space
inside an element (<span> → </span>) or on one line.
DOM-equivalence tests that normalize whitespace and substring assertions both miss this. Check inline text spacing visually.
.gsx. The x.go + x.templ split
existed for templ's tooling; gsx passes top-level Go through verbatim and its
LSP handles it. Keep main.go, route wiring, and data/auth layers as .go..templ. Linters and scripts that glob
*.templ or use templ's parser silently lose coverage. Port them or record
the gap; a green run can hide vanished checks.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
2 skills in this plugin
npx claudepluginhub gsxhq/gsx --plugin gsxOther plugins' skills for the same job