From daaae16493524df4e94d6934534c17a7d2a835ef Mon Sep 17 00:00:00 2001 From: Virgil Date: Sat, 4 Apr 2026 01:52:03 +0000 Subject: [PATCH] fix(html): snapshot responsive variants Co-Authored-By: Virgil --- responsive.go | 3 +++ responsive_test.go | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/responsive.go b/responsive.go index 4a41858..01ad55d 100644 --- a/responsive.go +++ b/responsive.go @@ -189,6 +189,9 @@ func (r *Responsive) Variant(name string, layout *Layout) *Responsive { if r == nil { return nil } + if layout != nil { + layout = layout.Clone() + } r.variants = append(r.variants, responsiveVariant{name: name, layout: layout}) return r } diff --git a/responsive_test.go b/responsive_test.go index d67232b..8d3fbb2 100644 --- a/responsive_test.go +++ b/responsive_test.go @@ -84,6 +84,22 @@ func TestResponsive_CloneReturnsIndependentCopy(t *testing.T) { } } +func TestResponsive_VariantClonesLayoutInput(t *testing.T) { + layout := NewLayout("C").C(Raw("original")) + responsive := NewResponsive().Variant("desktop", layout) + + layout.C(Raw("mutated")) + + got := responsive.Render(NewContext()) + + if !strings.Contains(got, "original") { + t.Fatalf("Variant should snapshot the layout at insertion time, got:\n%s", got) + } + if strings.Contains(got, "mutated") { + t.Fatalf("Variant should not share later layout mutations, got:\n%s", got) + } +} + func TestResponsive_NestedPaths(t *testing.T) { ctx := NewContext() inner := NewLayout("HCF").H(Raw("ih")).C(Raw("ic")).F(Raw("if"))