Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ensure unmounted components are not kept in updates #553

Merged
Merged
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
1 change: 0 additions & 1 deletion pkg/app/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,6 @@ func (c *Compo) updateRoot() error {
Wrap(err)
}

c.dispatcher().componentUpdated(c.self().(Composer))
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/app/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ type Dispatcher interface {
sessionStorage() BrowserStorage
runsInServer() bool
resolveStaticResource(string) string
componentUpdated(Composer)
removeFromUpdates(Composer)
}

// ClientDispatcher is the interface that describes a dispatcher that emulates a
Expand Down
55 changes: 28 additions & 27 deletions pkg/app/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,36 +370,19 @@ func (e *engine) scheduleComponentUpdate(n UI) {
return
}

var compo Composer
var depth int

for {
if c, isCompo := n.(Composer); compo == nil && isCompo {
if _, isScheduled := e.updates[c]; isScheduled {
return
}
compo = c
}

parent := n.parent()
if parent == nil {
break
}

if compo != nil {
depth++
}
n = parent
c := nearestCompo(n)
if c == nil {
return
}

if compo == nil {
if _, isScheduled := e.updates[c]; isScheduled {
return
}

e.updates[compo] = struct{}{}
e.updates[c] = struct{}{}
e.updateQueue = append(e.updateQueue, updateDescriptor{
compo: compo,
priority: depth + 1,
compo: c,
priority: compoPriority(c),
})
}

Expand All @@ -412,23 +395,24 @@ func (e *engine) updateComponents() {
for _, ud := range e.updateQueue {
compo := ud.compo
if !compo.Mounted() {
e.removeFromUpdates(compo)
continue
}

if _, isNotUpdated := e.updates[compo]; !isNotUpdated {
if _, requiresUpdate := e.updates[compo]; !requiresUpdate {
continue
}

if err := compo.updateRoot(); err != nil {
panic(err)
}
e.componentUpdated(compo)
e.removeFromUpdates(compo)
}

e.updateQueue = e.updateQueue[:0]
}

func (e *engine) componentUpdated(c Composer) {
func (e *engine) removeFromUpdates(c Composer) {
delete(e.updates, c)
}

Expand Down Expand Up @@ -478,6 +462,23 @@ func sortUpdateDescriptors(d []updateDescriptor) {
})
}

func nearestCompo(n UI) Composer {
for node := n; node != nil; node = node.parent() {
if c, isCompo := node.(Composer); isCompo {
return c
}
}
return nil
}

func compoPriority(c Composer) int {
depth := 1
for parent := c.parent(); parent != nil; parent = parent.parent() {
depth++
}
return depth
}

type msgHandler struct {
src UI
function MsgHandler
Expand Down