fix(modular): fix CoordinatorModular edgecase cascading dispose and prevent duplicate definitions.#91
Conversation
… prevent duplicate definitions.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #91 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 16 16
Lines 610 610
=========================================
Hits 610 610
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR targets nested CoordinatorModular edge cases in zenrouter_core, aiming to (1) avoid double execution of module setup when coordinators are nested as modules, (2) enable retrieving nested modules via getModule, and (3) cascade disposal to child coordinators.
Changes:
- Bump
zenrouter_coreversion from2.0.0to2.0.1. - Add recursive module lookup via
_allModulesand updategetModuleto support nested modules. - Add disposal cascading + adjust layout/converter delegation to avoid double execution for nested coordinator-modules, with new/updated tests covering these cases.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
packages/zenrouter_core/pubspec.yaml |
Patch version bump for the core package. |
packages/zenrouter_core/lib/src/coordinator/modular.dart |
Implements recursive module registry, cascaded dispose, and avoids double-calling define hooks for nested coordinator-modules. |
packages/zenrouter/test/mixin/layout_test.dart |
Adds assertions ensuring CoordinatorModular.dispose() cascades to child coordinators. |
packages/zenrouter/test/coordinator/nested_modular_test.dart |
New regression test ensuring nested modular coordinators don’t double-include paths or re-run define hooks. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| for (final module in _modules.values.whereType<CoordinatorCore>()) { | ||
| module.dispose(); | ||
| } | ||
| _modules.clear(); | ||
| _allModules.clear(); | ||
| super.dispose(); |
There was a problem hiding this comment.
In dispose(), _modules is cleared before calling super.dispose(). Since CoordinatorModular.paths depends on _modules, clearing it first means CoordinatorCore.dispose() will no longer see module paths and therefore won’t remove listeners / dispose those paths. Fix by calling super.dispose() before clearing _modules/_allModules, or by snapshotting the current paths/module paths before clearing and disposing them explicitly.
| for (final module in _modules.values.whereType<CoordinatorCore>()) { | |
| module.dispose(); | |
| } | |
| _modules.clear(); | |
| _allModules.clear(); | |
| super.dispose(); | |
| // Ensure CoordinatorCore.dispose() can still see all module paths via `paths`. | |
| super.dispose(); | |
| // Then dispose any modules that are also CoordinatorCore instances. | |
| for (final module in _modules.values.whereType<CoordinatorCore>()) { | |
| module.dispose(); | |
| } | |
| // Finally, clear module registries to release references. | |
| _modules.clear(); | |
| _allModules.clear(); |
No description provided.