Skip to content
This repository was archived by the owner on Jan 30, 2025. It is now read-only.

Commit 15a3f74

Browse files
committed
Remove the need to recalcLifecycle for sub frame
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.
1 parent d4be79d commit 15a3f74

File tree

2 files changed

+1
-20
lines changed

2 files changed

+1
-20
lines changed

common/frame.go

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -199,25 +199,6 @@ func (f *Frame) recalculateLifecycle() {
199199
}
200200
f.lifecycleEventsMu.RUnlock()
201201

202-
// Only consider a life cycle event as fired if it has triggered for all of subtree.
203-
f.childFramesMu.RLock()
204-
{
205-
for child := range f.childFrames {
206-
cf := child.(*Frame)
207-
// a precaution for preventing a deadlock in *Frame.childFramesMu
208-
if cf == f {
209-
continue
210-
}
211-
cf.recalculateLifecycle()
212-
for k := range events {
213-
if !cf.hasSubtreeLifecycleEventFired(k) {
214-
delete(events, k)
215-
}
216-
}
217-
}
218-
}
219-
f.childFramesMu.RUnlock()
220-
221202
// Check if any of the fired events should be considered fired when looking at the entire subtree.
222203
for k := range events {
223204
if f.hasSubtreeLifecycleEventFired(k) {

common/frame_manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ func (m *FrameManager) frameLifecycleEvent(frameID cdp.FrameID, event LifecycleE
195195
frame := m.getFrameByID(frameID)
196196
if frame != nil {
197197
frame.onLifecycleEvent(event)
198-
m.MainFrame().recalculateLifecycle() // Recalculate life cycle state from the top
198+
frame.recalculateLifecycle() // Recalculate life cycle state from the top
199199
}
200200
}
201201

0 commit comments

Comments
 (0)