-
Notifications
You must be signed in to change notification settings - Fork 6
fix(modular): fix CoordinatorModular edgecase cascading dispose and prevent duplicate definitions.
#91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
fix(modular): fix CoordinatorModular edgecase cascading dispose and prevent duplicate definitions.
#91
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
packages/zenrouter/test/coordinator/nested_modular_test.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| import 'dart:async'; | ||
|
|
||
| import 'package:flutter/widgets.dart'; | ||
| import 'package:flutter_test/flutter_test.dart'; | ||
| import 'package:zenrouter/zenrouter.dart'; | ||
|
|
||
| abstract class AppRoute extends RouteTarget with RouteUnique { | ||
| @override | ||
| Uri toUri(); | ||
|
|
||
| @override | ||
| Widget build(covariant Coordinator coordinator, BuildContext context) { | ||
| return const SizedBox(); | ||
| } | ||
|
|
||
| @override | ||
| List<Object?> get props => []; | ||
| } | ||
|
|
||
| class LeafRoute extends AppRoute { | ||
| @override | ||
| Uri toUri() => Uri.parse('/leaf'); | ||
| } | ||
|
|
||
| class LeafModule extends RouteModule<AppRoute> { | ||
| LeafModule(super.coordinator); | ||
|
|
||
| int layoutCount = 0; | ||
| int converterCount = 0; | ||
|
|
||
| @override | ||
| void defineLayout() { | ||
| layoutCount++; | ||
| super.defineLayout(); | ||
| } | ||
|
|
||
| @override | ||
| void defineConverter() { | ||
| converterCount++; | ||
| super.defineConverter(); | ||
| } | ||
|
|
||
| late final NavigationPath<AppRoute> leafPath = NavigationPath.createWith( | ||
| label: 'leaf', | ||
| coordinator: coordinator as Coordinator<AppRoute>, | ||
| ); | ||
|
|
||
| @override | ||
| List<StackPath> get paths => [leafPath]; | ||
|
|
||
| @override | ||
| FutureOr<AppRoute?> parseRouteFromUri(Uri uri) { | ||
| if (uri.path == '/leaf') return LeafRoute(); | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| class SubCoordinator extends Coordinator<AppRoute> | ||
| with CoordinatorModular<AppRoute> { | ||
| SubCoordinator(this.coordinator); | ||
|
|
||
| @override | ||
| final CoordinatorModular<AppRoute> coordinator; | ||
|
|
||
| @override | ||
| Set<RouteModule<AppRoute>> defineModules() => {LeafModule(this)}; | ||
|
|
||
| @override | ||
| AppRoute notFoundRoute(Uri uri) => throw UnimplementedError(); | ||
| } | ||
|
|
||
| class RootCoordinator extends Coordinator<AppRoute> | ||
| with CoordinatorModular<AppRoute> { | ||
| @override | ||
| Set<RouteModule<AppRoute>> defineModules() => {SubCoordinator(this)}; | ||
|
|
||
| @override | ||
| AppRoute notFoundRoute(Uri uri) => throw UnimplementedError(); | ||
| } | ||
|
|
||
| void main() { | ||
| test('Nested CoordinatorModular double inclusion/execution', () { | ||
| final root = RootCoordinator(); | ||
|
|
||
| final leaf = root.getModule<LeafModule>(); | ||
|
|
||
| final paths = root.paths; | ||
| final leafPaths = paths.where((p) => p == leaf.leafPath).toList(); | ||
|
|
||
| expect(paths.length, 2); | ||
| expect( | ||
| leafPaths.length, | ||
| 1, | ||
| reason: 'Leaf path was included multiple times in root paths', | ||
| ); | ||
| expect( | ||
| leaf.layoutCount, | ||
| 1, | ||
| reason: 'defineLayout was called multiple times on leaf module', | ||
| ); | ||
| expect( | ||
| leaf.converterCount, | ||
| 1, | ||
| reason: 'defineConverter was called multiple times on leaf module', | ||
| ); | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| ## 2.0.1 | ||
|
|
||
| - Fix `CoordinatorModular` edge case cascading dispose and prevent duplicate definitions. | ||
|
|
||
| ## 2.0.0 | ||
|
|
||
| - Extract core function from `zenrouter` package |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In dispose(),
_modulesis cleared before callingsuper.dispose(). SinceCoordinatorModular.pathsdepends on_modules, clearing it first meansCoordinatorCore.dispose()will no longer see module paths and therefore won’t remove listeners / dispose those paths. Fix by callingsuper.dispose()before clearing_modules/_allModules, or by snapshotting the currentpaths/module paths before clearing and disposing them explicitly.