Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@

## Unreleased

### Fixed

- The `{% cycle %}` tag no longer assigns to an error variable shared by every
render of a parsed template, so a template containing `{% cycle %}` can be
rendered concurrently from multiple goroutines.

## 1.9.2 (2026-08-16)

### Performance
Expand Down
2 changes: 1 addition & 1 deletion tags/iteration_tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func cycleTag(args string) (func(io.Writer, render.Context) error, error) {
n := cycleMap[group]
cycleMap[group] = n + 1
// The parser guarantees that there will be at least one item.
_, err = io.WriteString(w, values[n%len(values)])
_, err := io.WriteString(w, values[n%len(values)])

return err
}, nil
Expand Down
29 changes: 29 additions & 0 deletions template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,35 @@ func TestTemplate_Render_race(t *testing.T) {
wg2.Wait()
}

func TestTemplate_Render_cycle_race(t *testing.T) {
engine := NewEngine()
tpl, err := engine.ParseString(`{% for a in (1..4) %}{% cycle 'a', 'b' %}{% endfor %}`)
require.NoError(t, err)

const (
goroutines = 16
renders = 50
)

var wg sync.WaitGroup

for range goroutines {
wg.Add(1)

go func() {
defer wg.Done()

for range renders {
out, err := tpl.RenderString(Bindings{})
assert.NoError(t, err)
assert.Equal(t, "abab", out)
}
}()
}

wg.Wait()
}

func BenchmarkTemplate_Render(b *testing.B) {
engine := NewEngine()
bindings := Bindings{"a": "string value"}
Expand Down