Skip to content

feat(routing): add NavigatorObserver support to MagicRouter#34

Merged
anilcancakir merged 2 commits intomasterfrom
feat/router-observers
Apr 5, 2026
Merged

feat(routing): add NavigatorObserver support to MagicRouter#34
anilcancakir merged 2 commits intomasterfrom
feat/router-observers

Conversation

@anilcancakir
Copy link
Copy Markdown
Contributor

Closes #31

Summary

  • Add MagicRouter.instance.addObserver(NavigatorObserver) for analytics/monitoring integration (Sentry, Firebase, custom)
  • Observers passed to GoRouter's observers parameter automatically
  • Same pre-build guard pattern as routes — throws StateError if called after routerConfig is accessed
  • Read-only observers getter returns unmodifiable list
  • reset() clears observers

Test plan

  • addObserver() stores observer — verify via observers getter
  • Observers survive GoRouter build — verify after routerConfig access
  • addObserver() throws StateError after build
  • reset() clears observers on new instance
  • Full test suite: 698 tests pass
  • dart analyze: zero warnings

MagicRouter.instance.addObserver() enables Sentry, Firebase Analytics,
and custom NavigatorObserver integration. Observers are passed to GoRouter
automatically. Registration enforces same pre-build guard as routes.
Copilot AI review requested due to automatic review settings April 5, 2026 18:49
@sentry
Copy link
Copy Markdown

sentry bot commented Apr 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds first-class NavigatorObserver registration to MagicRouter so apps can plug in analytics/monitoring observers (e.g., Sentry/Firebase) through Magic’s routing abstraction, while enforcing the same “register-before-build” guard used for route definitions.

Changes:

  • Added observer registration API (addObserver), read-only accessor (observers), and reset behavior to MagicRouter.
  • Wired registered observers into GoRouter via the observers parameter during router build.
  • Documented the new capability across framework docs and added unit tests for the new API/guard behavior.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
lib/src/routing/magic_router.dart Stores observers, exposes getter, enforces pre-build guard, passes observers into GoRouter, clears on reset.
test/routing/router_test.dart Adds coverage for storing observers, post-build guard, and reset behavior.
skills/magic-framework/SKILL.md Updates reference index entry to include navigator observers in routing docs.
skills/magic-framework/references/routing-navigation.md Adds a “Navigator Observers” section and timing gotcha.
doc/basics/routing.md Adds user-facing docs section for registering observers in RouteServiceProvider.
CHANGELOG.md Notes the feature in the Unreleased section.
.claude/rules/routing.md Updates routing domain rules to mention observer support and timing constraint.

…observers (#34)

Renamed 'observers are passed to GoRouter' → 'observers persist after
router build' since GoRouter doesn't publicly expose its observer list.
@anilcancakir anilcancakir merged commit 959c653 into master Apr 5, 2026
2 checks passed
@anilcancakir anilcancakir mentioned this pull request Apr 5, 2026
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: add observer support to MagicRouter for analytics/monitoring

2 participants