fix(desktop): flush inbox report-closed on pagehide - #90031
Conversation
The desktop and web inbox fire `Inbox report closed` from a React effect cleanup that never runs on a tab or window close, so those closes are lost and dwell time undercounts. Every close was also labeled `navigated_away`, a desktop-only value that cannot be compared with the cloud surface. Add a `pagehide` listener that flushes the close with `send_instantly`, mirroring the cloud inbox logic, and guard it so a later unmount cannot fire the close twice. Relabel the in-app teardown close `unmount` and the unload close `page_unload`, aligning the desktop close-method vocabulary with the cloud surface. Generated-By: PostHog Desktop Task-Id: 1eeb74ad-6ce4-4ec9-9907-cfebede9bada
|
Merging to
After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here |
|
React Doctor found no issues in the changed files. 🎉 Reviewed by React Doctor for commit |
🤖 CI report✅ Trunk lane — non-backend laneThis PR is assigned to the non-backend lane. It does not run backend Python tests and may merge in parallel with PRs in other lanes. |
There was a problem hiding this comment.
Contained analytics-instrumentation fix (pagehide flush + reason vocabulary alignment) with no changes to auth, billing, data models, APIs, dependencies, or CI; well covered by new and updated unit tests.
Gate mechanics and policy version
| Gate | Result | |
|---|---|---|
| prerequisites | ✓ | all clear |
| deny-list | ✓ | no deny categories matched |
| size | ✓ | 84L, 4F substantive, 180L/6F incl. docs/generated/snapshots — within ceiling |
| tier | ✓ | T1-agent / T1c-medium (180L, 6F, single-area, fix) |
| stamphog 2.0.0b4 | .stamphog/policy.yml @ 5756322 · reviewed head 5756322 |
HostHog preview —
|

Problem
Inbox report closedevent never fires, so dwell time undercounts.useReportOpenTracker. A tab or window close never unmounts the detail route, so the cleanup never runs.pagehideflush; the desktop and web hosts did not have one.close_method: navigated_away, a value the cloud surface never emits, so the same event name could not be compared across surfaces.Changes
pagehidelistener flushesInbox report closedwithsend_instantlyso the event leaves before the page goes.pagehideflush and the effect cleanup share one guarded emitter, so whichever fires first wins and the other is a no-op.page_unloadfor a tab or window close,unmountfor in-app teardown,next_reportfor a report-to-report switch. The desktop-onlynavigated_awayvalue is gone.trackgains an optionalTrackOptionsargument that forwardssend_instantlytoposthog.capture. No other call site passes it.How did you test this code?
useReportOpenTracker.test.tsxwith three cases:pagehideflush fires oneInbox report closedwithclose_method: page_unloadandsend_instantly, and a following unmount does not fire it again (guards the dropped-close and double-close regressions);unmount;next_reportand resets the default for the next teardown.posthogAnalyticsImplassertions that pinnedcaptureto two arguments;tracknow forwards the options slot.@posthog/uiinbox-hook and shell suites and typechecked@posthog/shared,@posthog/ui,@posthog/web, andcode.Automatic notifications
Docs update
None.
🤖 Agent context
Autonomy: Fully autonomous
/writing-tests,/writing-pr-descriptions,/writing-simplified-technical-english.products/signals/frontend/inbox/inboxSceneLogic.ts) was the reference: itspagehideflush and close-method vocabulary were mirrored onto the desktop hook so aclose_methodbreakdown reads consistently across surfaces.close_method) is a project-config change outside this repo and is not part of this PR.Created with PostHog Desktop from this inbox report.