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

Commit db31e86

Browse files
committed
Refactor the emitting of the lifecycle event
We're only ever going to fire the newly received CDP lifecycle event so there's no need for the for loop to go over all the events that have already fired and ignore the ones that have already been emitted to internal handlers. This should lead us to refactoring out the subtreeLifecycleEvents as there's no need for it now, it's just a duplicate of lifecycleEvents.
1 parent 15a3f74 commit db31e86

File tree

2 files changed

+4
-10
lines changed

2 files changed

+4
-10
lines changed

common/frame.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,11 @@ func (f *Frame) clearLifecycle() {
186186
f.inflightRequestsMu.Unlock()
187187
}
188188

189-
func (f *Frame) recalculateLifecycle() {
189+
func (f *Frame) recalculateLifecycle(event LifecycleEvent) {
190190
f.log.Debugf("Frame:recalculateLifecycle", "fid:%s furl:%q", f.ID(), f.URL())
191191

192+
f.emit(EventFrameAddLifecycle, event)
193+
192194
// Start with triggered events.
193195
events := make(map[LifecycleEvent]bool)
194196
f.lifecycleEventsMu.RLock()
@@ -199,14 +201,6 @@ func (f *Frame) recalculateLifecycle() {
199201
}
200202
f.lifecycleEventsMu.RUnlock()
201203

202-
// Check if any of the fired events should be considered fired when looking at the entire subtree.
203-
for k := range events {
204-
if f.hasSubtreeLifecycleEventFired(k) {
205-
continue
206-
}
207-
f.emit(EventFrameAddLifecycle, k)
208-
}
209-
210204
f.lifecycleEventsMu.Lock()
211205
{
212206
f.subtreeLifecycleEvents = make(map[LifecycleEvent]bool)

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-
frame.recalculateLifecycle() // Recalculate life cycle state from the top
198+
frame.recalculateLifecycle(event)
199199
}
200200
}
201201

0 commit comments

Comments
 (0)