Skip to content

fix(gsx): scope := binding names to their templ - #161

Merged
grindlemire merged 2 commits into
mainfrom
fix/binding-scope
Sep 16, 2026
Merged

grindlemire merged 2 commits into
mainfrom
fix/binding-scope

Conversation

@grindlemire

Copy link
Copy Markdown
Owner

The analyzer collected := element binding names for every templ in a file before rewriting {name} references, so a binding declared in one templ rewrote same-named references in every other templ. A sibling templ with a label string parameter was generated as AddChild(label) instead of a text element, and the generated package failed to build.

templ A() {
	label := <span>bound</span>
	<div>{label}</div>
}

templ B(label string) {
	<div>{label}</div>
}

The binding registry is now rebuilt for each templ, and references are rewritten right after that templ's bindings are collected, so a name only resolves to a bound element inside the templ that declares it. Bindings nested in if and for bodies still resolve within their own templ, and two templs binding the same name each keep their own element.

Fixes #155

The analyzer collected := binding names for every templ in a file before
rewriting {name} references, so a binding in one templ rewrote a
same-named string parameter in a sibling templ into AddChild and the
generated package failed to build. Rebuild the registry per templ and
rewrite references right after collecting that templ's bindings.

Fixes #155
@greptile-apps

greptile-apps Bot commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The PR appears safe to merge and correctly fixes cross-templ binding leakage with appropriate regression coverage.

Summary

This PR fixes cross-templ leakage of GSX := element bindings by rebuilding the analyzer’s binding registry for each component and transforming references immediately after collection.

  • Keeps element-binding reference rewriting local to the declaring templ.
  • Preserves bindings nested within conditional and loop bodies.
  • Adds table-driven regression coverage for sibling parameters, declaration order, nested bindings, and repeated binding names.

Reviews (1) · Last reviewed commit: "fix(gsx): scope := binding names to thei..."

@codecov

codecov Bot commented Sep 16, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.51%. Comparing base (64e001a) to head (67e4a14).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #161      +/-   ##
==========================================
+ Coverage   84.49%   84.51%   +0.01%     
==========================================
  Files         169      169              
  Lines       21535    21524      -11     
==========================================
- Hits        18197    18190       -7     
+ Misses       2669     2667       -2     
+ Partials      669      667       -2     

☔ 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

letBindings only feeds the per-templ {name} rewrite; the "used" values
were never read. Make it a set and delete the no-op check loop and the
marking blocks in analyzeGoExpr, analyzeGoCode, and analyzeLetBinding.
@grindlemire
grindlemire merged commit 204bc6e into main Sep 16, 2026
9 checks passed
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.

gsx: := binding names leak across templs in the same file

1 participant