diff --git a/src/addons/calendar/components/calendar/calendar.ts b/src/addons/calendar/components/calendar/calendar.ts index 1e8bf8d73..aef2a3a74 100644 --- a/src/addons/calendar/components/calendar/calendar.ts +++ b/src/addons/calendar/components/calendar/calendar.ts @@ -340,7 +340,9 @@ export class AddonCalendarCalendarComponent implements OnInit, DoCheck, OnDestro ngOnDestroy(): void { this.undeleteEventObserver?.off(); this.manager?.destroy(); - this.managerUnsubscribe && this.managerUnsubscribe(); + this.managerUnsubscribe?.(); + + delete this.manager; } } diff --git a/src/addons/calendar/pages/day/day.page.ts b/src/addons/calendar/pages/day/day.page.ts index 839a3a7d5..3c266ee85 100644 --- a/src/addons/calendar/pages/day/day.page.ts +++ b/src/addons/calendar/pages/day/day.page.ts @@ -457,7 +457,9 @@ export class AddonCalendarDayPage implements OnInit, OnDestroy { this.filterChangedObserver?.off(); this.manager?.getSource().forgetRelatedSources(); this.manager?.destroy(); - this.managerUnsubscribe && this.managerUnsubscribe(); + this.managerUnsubscribe?.(); + + delete this.manager; } } diff --git a/src/addons/mod/book/pages/contents/contents.ts b/src/addons/mod/book/pages/contents/contents.ts index fef0d3775..9c290473e 100644 --- a/src/addons/mod/book/pages/contents/contents.ts +++ b/src/addons/mod/book/pages/contents/contents.ts @@ -314,8 +314,10 @@ export class AddonModBookContentsPage implements OnInit, OnDestroy { * @inheritdoc */ ngOnDestroy(): void { - this.managerUnsubscribe && this.managerUnsubscribe(); this.manager?.destroy(); + this.managerUnsubscribe?.(); + + delete this.manager; } } diff --git a/src/core/services/tests/utils/dom.test.ts b/src/core/services/tests/utils/dom.test.ts index 3be772386..45e8499d9 100644 --- a/src/core/services/tests/utils/dom.test.ts +++ b/src/core/services/tests/utils/dom.test.ts @@ -18,6 +18,7 @@ import { AlertController, Translate } from '@singletons'; import { mock, mockSingleton, mockTranslate } from '@/testing/utils'; import { CoreSiteError } from '@classes/errors/siteerror'; import { CoreSites } from '@services/sites'; +import { OverlayEventDetail } from '@ionic/core'; describe('CoreDomUtilsProvider', () => { @@ -56,4 +57,30 @@ describe('CoreDomUtilsProvider', () => { }); }); + it('ignores alert inputs on cancel', async () => { + // Arrange. + const mockAlert = mock({ + present: () => Promise.resolve(), + onWillDismiss: () => Promise.resolve({ + data: { + values: { + 'textarea-prompt': 'Not empty!', + }, + }, + role: 'cancel', + } as OverlayEventDetail), // eslint-disable-line @typescript-eslint/no-explicit-any + }); + + mockSingleton(AlertController, mock({ create: () => Promise.resolve(mockAlert) })); + + // Act. + const result = await domUtils.showTextareaPrompt('Age', 'How old are you?', [ + { text: 'Cancel', role: 'cancel' }, + { text: 'Save' }, + ]); + + // Assert. + expect(result).toBeUndefined(); + }); + }); diff --git a/src/core/services/utils/dom.ts b/src/core/services/utils/dom.ts index 581880eeb..865a2501b 100644 --- a/src/core/services/utils/dom.ts +++ b/src/core/services/utils/dom.ts @@ -1659,6 +1659,10 @@ export class CoreDomUtilsProvider { const result = await alert.onWillDismiss(); + if (result.role === 'cancel') { + return; + } + return result.data?.values?.['textarea-prompt']; }