diff --git a/document.go b/document.go index 45a4407..76db4d1 100644 --- a/document.go +++ b/document.go @@ -185,6 +185,9 @@ func (d *Document) RenderFrame() { // Setup our root node root := d.r.LayoutRoot() + if root == nil { + return + } // Build our render tree tree(ctx, root, Fragment(d.els...), false) diff --git a/document_test.go b/document_test.go index 81300f3..22bf9b5 100644 --- a/document_test.go +++ b/document_test.go @@ -1,6 +1,7 @@ package glint import ( + "bytes" "context" "sync/atomic" "testing" @@ -69,6 +70,23 @@ func TestDocument_unmountClose(t *testing.T) { require.Equal(uint32(1), atomic.LoadUint32(&c.unmount)) } +func TestDocument_renderingWithoutLayout(t *testing.T) { + var buf bytes.Buffer + + d := New() + d.SetRenderer(&TerminalRenderer{ + Output: &buf, + }) + + var c testMount + d.Append(&c) + + // Render once + d.RenderFrame() + require.Empty(t, buf.String()) + require.Zero(t, atomic.LoadUint32(&c.mount)) +} + type testMount struct { terminalComponent