Skip to content

Commit

Permalink
Remove the need to recalcLifecycle for sub frame
Browse files Browse the repository at this point in the history
Each frame (main and the subs) receive their own lifecycle events in
the correct order (so the sub frames first, and then the root/main
frame). The reason for having this code in the first place I believe
is due to out of order CDP event, which has now been fixed in PR #555.

After extensive stress testing I can confirm that we no longer need to
perform the recalculateLifecycle in a recursive way. So each frame
should be in charge of recalculating its own lifecycle.

There maybe a need to do this in the future if the browser changes its
behaviour on how it deals with lifecycle events, but at this point we
should not consider adding such a recursive call.
  • Loading branch information
ankur22 committed Nov 11, 2022
1 parent d4be79d commit 15a3f74
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 20 deletions.
19 changes: 0 additions & 19 deletions common/frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,25 +199,6 @@ func (f *Frame) recalculateLifecycle() {
}
f.lifecycleEventsMu.RUnlock()

// Only consider a life cycle event as fired if it has triggered for all of subtree.
f.childFramesMu.RLock()
{
for child := range f.childFrames {
cf := child.(*Frame)
// a precaution for preventing a deadlock in *Frame.childFramesMu
if cf == f {
continue
}
cf.recalculateLifecycle()
for k := range events {
if !cf.hasSubtreeLifecycleEventFired(k) {
delete(events, k)
}
}
}
}
f.childFramesMu.RUnlock()

// Check if any of the fired events should be considered fired when looking at the entire subtree.
for k := range events {
if f.hasSubtreeLifecycleEventFired(k) {
Expand Down
2 changes: 1 addition & 1 deletion common/frame_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func (m *FrameManager) frameLifecycleEvent(frameID cdp.FrameID, event LifecycleE
frame := m.getFrameByID(frameID)
if frame != nil {
frame.onLifecycleEvent(event)
m.MainFrame().recalculateLifecycle() // Recalculate life cycle state from the top
frame.recalculateLifecycle() // Recalculate life cycle state from the top
}
}

Expand Down

0 comments on commit 15a3f74

Please sign in to comment.