Skip to content

Fix non-compiling Button examples in LLMs.md - #337

Open
maragubot wants to merge 2 commits into
maragudk:mainfrom
maragubot:garden/fix-button-examples-in-llms-doc
Open

Fix non-compiling Button examples in LLMs.md#337
maragubot wants to merge 2 commits into
maragudk:mainfrom
maragubot:garden/fix-button-examples-in-llms-doc

Conversation

@maragubot

Copy link
Copy Markdown
Contributor

What was found

Two Go examples in LLMs.md under "Best Practices" don't compile.

The "Type Safety" example declared func Button(variant ButtonVariant, text string) Node in a file that dot-imports maragu.dev/gomponents/html, which already exports Button:

Button already declared through dot-import of package html ("maragu.dev/gomponents/html")
	html/elements.go:64:6: other declaration of Button

Its body also called Button(...) recursively rather than the element. The "Testing" example then called Button("Click me"), passing a string to html.Button(children ...g.Node), and asserted the output <button>Click me</button>.

This matters more here than in ordinary docs: LLMs.md exists so language models can learn the library, so a broken example is copied forward into generated code rather than caught by a reader.

What was fixed

Renamed the component to VariantButton in both examples so it no longer collides with the element, and added a note explaining the collision and how to avoid it. Rewrote the testing example to render VariantButton, check the Render error, and assert the output the component actually produces:

<button class="btn-primary" type="button">Click me</button>

I verified this by extracting the two code blocks straight out of the committed LLMs.md and compiling them against this branch, so the doc itself is what was tested rather than a retyping of it. The note's two claims were checked the same way: declaring Button in a different file of the package with aliased imports still fails, and dropping the dot-import lets it build.

Only prose and example code changed; no library code is touched.

Review notes

Two competing reviewers confirmed the new examples compile and that the asserted HTML is byte-exact. Both independently found that LLMs.md contains further broken examples of the same kind, which this PR deliberately leaves alone to stay a single-issue change:

  • Thead / Tbody in the Tables example are undefined; the real names are THead and TBody. Both reviewers called this the most damaging one left, since those are exactly the names a model would guess.
  • The second example in the document (the Nav snippet) has a syntax error from a missing trailing comma.
  • Page("Welcome!") is called against a Page() defined with no parameters earlier in the file.
  • The ServeHTTP performance example declares a method on Handler, which is a func type and so cannot take a receiver.
  • Two blocks import packages they never use.

One reviewer also noted that the Layout example calls Header(), Main() and Footer() expecting user components, but under its dot-import those bind to the HTML elements and render empty tags. That is the silent version of the bug fixed here and deserves its own change.

Worth noting the root cause: nothing compiles these snippets, so the class recurs. A check that extracts and builds the go blocks in LLMs.md would catch all of the above.

Both examples collided with `html.Button`: the type safety one redeclared it
under a dot-import, and the testing one passed it a string. They now use a
`VariantButton` component that compiles and renders what the test asserts.
The collision applies package-wide, not just in the file with the
dot-import, and an aliased import avoids it.
@codecov

codecov Bot commented Jul 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (76f04c0) to head (cae2faf).

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #337   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            6         6           
  Lines          639       639           
=========================================
  Hits           639       639           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant