Skip to content

Commit

Permalink
Merge pull request #4 from notnoop/b-nil-layout
Browse files Browse the repository at this point in the history
Protect against nil LayoutRoots
  • Loading branch information
mitchellh authored Jul 22, 2021
2 parents b492b54 + 766072e commit 6515ceb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions document.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 18 additions & 0 deletions document_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package glint

import (
"bytes"
"context"
"sync/atomic"
"testing"
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 6515ceb

Please sign in to comment.