about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--gomponents.go3
-rw-r--r--gomponents_test.go5
2 files changed, 8 insertions, 0 deletions
diff --git a/gomponents.go b/gomponents.go
index c0aa510..ee156b9 100644
--- a/gomponents.go
+++ b/gomponents.go
@@ -84,6 +84,9 @@ func El(name string, children ...Node) NodeFunc {
 }
 
 func renderChild(c Node, inside, outside *strings.Builder) {
+	if c == nil {
+		return
+	}
 	if g, ok := c.(group); ok {
 		for _, groupC := range g.children {
 			renderChild(groupC, inside, outside)
diff --git a/gomponents_test.go b/gomponents_test.go
index db9256c..33d32d1 100644
--- a/gomponents_test.go
+++ b/gomponents_test.go
@@ -83,6 +83,11 @@ func TestEl(t *testing.T) {
 		e := g.El("div", outsider{})
 		assert.Equal(t, `<div>outsider</div>`, e)
 	})
+
+	t.Run("does not fail on nil node", func(t *testing.T) {
+		e := g.El("div", g.El("span"), nil, g.El("span"))
+		assert.Equal(t, `<div><span /><span /></div>`, e)
+	})
 }
 
 func TestText(t *testing.T) {