fix(web): flush active view and hover heartbeats on page hide/unload#385
Merged
Merged
Conversation
Felipe Mamud (fmamud)
requested review from
Lotfi Anwar L Arif (Lotfi-Arif),
Tim Beyer (TimBeyer) and
Charles Hudson (phobetron)
as code owners
July 23, 2026 16:00
Charles Hudson (phobetron)
previously approved these changes
Jul 23, 2026
Charles Hudson (phobetron)
left a comment
Collaborator
There was a problem hiding this comment.
Very nice!
…le heartbeat flush
Charles Hudson (phobetron)
approved these changes
Jul 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
visibilitychangehidden,pagehide, andbeforeunload, before the lifecycle Insights flush runs.flushActive()toElementViewObserverandElementHoverObserverthat reuses the existing heartbeat path (sameviewId/hoverId, existing threshold/dedupe). No new event type, noisFinalfield.flushActiveInteractions()onEntryInteractionRuntimeand invoke it from the SDK's visibility callback beforeflushQueues, preserving queue ordering.Fixes NT-3718.
Test plan
pnpm --filter @contentful/optimization-web test:unit— 280 tests pass, including new coverage: active view/hover flush past dwell, no emission before dwell, runtime dispatch to running detectors only,flushActiveInteractionsrunning beforesendBatchEventsonpagehide.pnpm --filter @contentful/optimization-web typecheckpnpm lintpnpm format:checkemits a final hover heartbeat when the page becomes hidden while still hoveredinlib e2e-web/e2e/tracking.spec.ts— hovers past dwell, flipsdocument.visibilityStatetohiddenand dispatchesvisibilitychange, assertsdata-hover-duration-msadvances beyond the pre-hidden snapshot. Verified locally againstreact-web-sdkon chromium; runs across all supported CSR implementations via CI matrix.