Skip to content

Commit

Permalink
fix handle multiple identical instances in memory
Browse files Browse the repository at this point in the history
This is done by avoid removing instance
from cached _instances map on dispose.

The bug happened when there were two identical pages
in memory and one of them was disposed,
thus removing the cached instance also for the
other page instance and leaving
a circular progress indicator spinning forever.
  • Loading branch information
sstasi95 committed Dec 20, 2023
1 parent 941d0aa commit 19c4c11
Show file tree
Hide file tree
Showing 11 changed files with 12 additions and 22 deletions.
3 changes: 1 addition & 2 deletions lib/src/screens/commit_detail/controller_commit_detail.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class _CommitDetailController with ShareMixin {
}

if (instance != null && args.commitId != instance!.args.commitId) {
instance = _CommitDetailController._(args, apiService);
instance = null;
}

instance ??= _CommitDetailController._(args, apiService);
Expand Down Expand Up @@ -46,7 +46,6 @@ class _CommitDetailController with ShareMixin {

void dispose() {
instance = null;
_instances.remove(args.hashCode);
}

Future<void> init() async {
Expand Down
3 changes: 1 addition & 2 deletions lib/src/screens/commits/controller_commits.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class _CommitsController with FilterMixin {
}

if (instance != null && args != instance!.args) {
instance = _CommitsController._(apiService, storageService, args);
instance = null;
}

instance ??= _CommitsController._(apiService, storageService, args);
Expand Down Expand Up @@ -40,7 +40,6 @@ class _CommitsController with FilterMixin {

void dispose() {
instance = null;
_instances.remove(args);
}

Future<void> init() async {
Expand Down
3 changes: 1 addition & 2 deletions lib/src/screens/member_detail/controller_member_detail.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class _MemberDetailController {
}

if (instance != null && instance!.userDescriptor != userDescriptor) {
instance = _MemberDetailController._(userDescriptor, apiService);
instance = null;
}

instance ??= _MemberDetailController._(userDescriptor, apiService);
Expand All @@ -31,7 +31,6 @@ class _MemberDetailController {

void dispose() {
instance = null;
_instances.remove(userDescriptor);
}

Future<void> init() async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class _PipelineDetailController with ShareMixin {
}

if (instance != null && args.id != instance!.args.id) {
instance = _PipelineDetailController._(args, apiService);
instance = null;
}

instance ??= _PipelineDetailController._(args, apiService);
Expand Down Expand Up @@ -39,7 +39,6 @@ class _PipelineDetailController with ShareMixin {
_stopTimer();

instance = null;
_instances.remove(args.hashCode);
}

void _stopTimer() {
Expand Down
3 changes: 1 addition & 2 deletions lib/src/screens/pipelines/controller_pipelines.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class _PipelinesController with FilterMixin {
}

if (instance != null && args != instance!.args) {
instance = _PipelinesController._(apiService, storageService, args);
instance = null;
}

instance ??= _PipelinesController._(apiService, storageService, args);
Expand Down Expand Up @@ -53,7 +53,6 @@ class _PipelinesController with FilterMixin {
_stopTimer();

instance = null;
_instances.remove(args.hashCode);
}

void _stopTimer() {
Expand Down
4 changes: 2 additions & 2 deletions lib/src/screens/project_detail/controller_project_detail.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ class _ProjectDetailController {
}

if (instance != null && instance!.projectName != projectName) {
instance = _ProjectDetailController._(apiService, projectName);
instance = null;
}

instance ??= _ProjectDetailController._(apiService, projectName);
return _instances.putIfAbsent(projectName, () => instance!);
}
Expand Down Expand Up @@ -37,7 +38,6 @@ class _ProjectDetailController {

void dispose() {
instance = null;
_instances.remove(projectName);
}

Future<void> init() async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class _PullRequestDetailController with ShareMixin, AppLogger, PullRequestHelper
}

if (instance != null && instance!.args != args) {
instance = _PullRequestDetailController._(args, apiService);
instance = null;
}

instance ??= _PullRequestDetailController._(args, apiService);
Expand Down Expand Up @@ -65,7 +65,6 @@ class _PullRequestDetailController with ShareMixin, AppLogger, PullRequestHelper

void dispose() {
instance = null;
_instances.remove(args.hashCode);
}

Future<void> init() async {
Expand Down
3 changes: 1 addition & 2 deletions lib/src/screens/pull_requests/controller_pull_requests.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class _PullRequestsController with FilterMixin {
}

if (instance != null && project?.id != instance!.project?.id) {
instance = _PullRequestsController._(apiService, storageService, project);
instance = null;
}

instance ??= _PullRequestsController._(apiService, storageService, project);
Expand Down Expand Up @@ -47,7 +47,6 @@ class _PullRequestsController with FilterMixin {

void dispose() {
instance = null;
_instances.remove(project.hashCode);
}

Future<void> init() async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class _RepositoryDetailController {
}

if (instance != null && instance!.args != args) {
instance = _RepositoryDetailController._(apiService, args);
instance = null;
}

instance ??= _RepositoryDetailController._(apiService, args);
Expand All @@ -33,7 +33,6 @@ class _RepositoryDetailController {

void dispose() {
instance = null;
_instances.remove(args.hashCode);
}

Future<void> init() async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class _WorkItemDetailController with ShareMixin, FilterMixin, AppLogger {
}

if (instance != null && instance!.args != args) {
instance = _WorkItemDetailController._(args, apiService, storageService);
instance = null;
}

instance ??= _WorkItemDetailController._(args, apiService, storageService);
Expand Down Expand Up @@ -49,7 +49,6 @@ class _WorkItemDetailController with ShareMixin, FilterMixin, AppLogger {

void dispose() {
instance = null;
_instances.remove(args.hashCode);
}

Future<void> init() async {
Expand Down
3 changes: 1 addition & 2 deletions lib/src/screens/work_items/controller_work_items.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class _WorkItemsController with FilterMixin {
}

if (instance != null && project?.id != instance!.project?.id) {
instance = _WorkItemsController._(apiService, storageService, project);
instance = null;
}

instance ??= _WorkItemsController._(apiService, storageService, project);
Expand Down Expand Up @@ -58,7 +58,6 @@ class _WorkItemsController with FilterMixin {

void dispose() {
instance = null;
_instances.remove(project.hashCode);
}

Future<void> init() async {
Expand Down

0 comments on commit 19c4c11

Please sign in to comment.