Skip to content

fix(desktop): flush inbox report-closed on pagehide - #90031

Draft
posthog[bot] wants to merge 1 commit into
masterfrom
posthog-self-driving/fixinbox-flush-the-report-closed-event-acaadd
Draft

fix(desktop): flush inbox report-closed on pagehide#90031
posthog[bot] wants to merge 1 commit into
masterfrom
posthog-self-driving/fixinbox-flush-the-report-closed-event-acaadd

Conversation

@posthog

@posthog posthog Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Problem

  • A PostHog teammate who closes an inbox report by closing the tab or window loses that close: on desktop and web the Inbox report closed event never fires, so dwell time undercounts.
  • The close runs from a React effect cleanup in useReportOpenTracker. A tab or window close never unmounts the detail route, so the cleanup never runs.
  • The cloud inbox already fixed the same gap with a pagehide flush; the desktop and web hosts did not have one.
  • Every desktop and web close was also labeled close_method: navigated_away, a value the cloud surface never emits, so the same event name could not be compared across surfaces.

Changes

  • A tab or window close now records the report close. A pagehide listener flushes Inbox report closed with send_instantly so the event leaves before the page goes.
  • A single close per open is guaranteed. The pagehide flush and the effect cleanup share one guarded emitter, so whichever fires first wins and the other is a no-op.
  • Close reasons now match the cloud surface: page_unload for a tab or window close, unmount for in-app teardown, next_report for a report-to-report switch. The desktop-only navigated_away value is gone.
  • Mechanical: track gains an optional TrackOptions argument that forwards send_instantly to posthog.capture. No other call site passes it.
  • No visible UI change. This is instrumentation only, so there is nothing to screenshot.

How did you test this code?

  • Added useReportOpenTracker.test.tsx with three cases:
    • a pagehide flush fires one Inbox report closed with close_method: page_unload and send_instantly, and a following unmount does not fire it again (guards the dropped-close and double-close regressions);
    • an in-app unmount labels the close unmount;
    • a report-to-report switch labels the close next_report and resets the default for the next teardown.
  • Updated two posthogAnalyticsImpl assertions that pinned capture to two arguments; track now forwards the options slot.
  • Ran the @posthog/ui inbox-hook and shell suites and typechecked @posthog/shared, @posthog/ui, @posthog/web, and code.
  • Not run: the desktop app end to end, and the database-backed suites; this sandbox has no running stack.

Automatic notifications

  • Publish to changelog?

Docs update

None.

🤖 Agent context

Autonomy: Fully autonomous

  • Authored by PostHog Desktop (Claude) from an inbox report. No human drove the work, so the PR is left unassigned for the owning team to triage.
  • Skills invoked: /writing-tests, /writing-pr-descriptions, /writing-simplified-technical-english.
  • The cloud inbox (products/signals/frontend/inbox/inboxSceneLogic.ts) was the reference: its pagehide flush and close-method vocabulary were mirrored onto the desktop hook so a close_method breakdown reads consistently across surfaces.
  • Alert tuning (excluding staff from the population, or breaking the insight down by 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.

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
@trunk-io

trunk-io Bot commented Aug 27, 2026

Copy link
Copy Markdown

Merging to master in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

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

@posthog

posthog Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor Author

🦔 PostHog Review reviewed this pull request

Nothing worth raising this time, so here's a calming picture instead:

A panda relaxing and waving

@github-actions github-actions Bot added the feature/desktop Feature Tag: Desktop label Aug 27, 2026
@github-actions

Copy link
Copy Markdown
Contributor

React Doctor found no issues in the changed files. 🎉

Reviewed by React Doctor for commit 5756322.

@github-actions

Copy link
Copy Markdown
Contributor

🤖 CI report

Trunk lane — non-backend lane

This 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.

@stamphog stamphog Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

hosthog Bot commented Aug 27, 2026

Copy link
Copy Markdown

HostHog preview — posthog-desktop-web

Latest build (5756322): https://33af4fca6ed84584ad3d3a4a15ff3a58.hosthog.dev

Employee-gated; every push gets a fresh URL whose content never changes. All previews stop serving when the PR closes.

@trunk-io

trunk-io Bot commented Aug 27, 2026

Copy link
Copy Markdown

Static BadgeStatic BadgeStatic Badge

View Full Report ↗︎Docs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature/desktop Feature Tag: Desktop

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants