Skip to content

fix: suppress ghost screen events when app is in background#355

Merged
marandaneto merged 5 commits intomainfrom
fix/suppress-ghost-screen-events-in-background
Apr 8, 2026
Merged

fix: suppress ghost screen events when app is in background#355
marandaneto merged 5 commits intomainfrom
fix/suppress-ghost-screen-events-in-background

Conversation

@marandaneto
Copy link
Copy Markdown
Member

💡 Motivation and Context

When a Flutter app goes to the background (AppLifecycleState.paused or inactive), the OS or certain plugins can trigger widget tree rebuilds. This causes the router to reconstruct routes, which fires PosthogObserver callbacks (didPush, didPop, didReplace), resulting in ghost $screen events even though the user isn't looking at the app.

This was reported in #352 with an MRE. Rather than requiring users to work around this with a propertiesExtractor, this fix handles it built-in within PosthogObserver.

Fixes the issue described in #352 (comment)

💚 How did you test it?

  • Added 5 unit tests covering all observer methods (didPush, didPop, didReplace) with paused/inactive/resumed lifecycle states
  • All 98 existing tests continue to pass

📝 Checklist

  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • No breaking change or entry added to the changelog.

If releasing new changes

  • Ran pnpm changeset to generate a changeset file
  • Added the release label to the PR

@marandaneto marandaneto requested a review from a team as a code owner April 8, 2026 08:42
@marandaneto
Copy link
Copy Markdown
Member Author

@didyk i think this approach would be better?

Copy link
Copy Markdown
Contributor

@ioannisj ioannisj left a comment

Choose a reason for hiding this comment

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

Makes sense, just a couple of comments around implementation

@marandaneto marandaneto enabled auto-merge (squash) April 8, 2026 09:04
@marandaneto marandaneto merged commit b4532f5 into main Apr 8, 2026
19 checks passed
@marandaneto marandaneto deleted the fix/suppress-ghost-screen-events-in-background branch April 8, 2026 09:10
@didyk
Copy link
Copy Markdown

didyk commented Apr 8, 2026

@marandaneto thanks!

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants