From 42e501a85d089b4863950482fd89d240102aeb7d Mon Sep 17 00:00:00 2001 From: nd0ut Date: Thu, 7 Dec 2023 14:34:12 +0800 Subject: [PATCH 1/3] fix: destroy upload collection when the last block in context is being destroyed --- abstract/Block.js | 8 ++++++-- abstract/CTX.js | 1 + abstract/UploaderBlock.js | 18 +++++++++++------- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/abstract/Block.js b/abstract/Block.js index 915e1ce7a..62f98307e 100644 --- a/abstract/Block.js +++ b/abstract/Block.js @@ -196,11 +196,15 @@ export class Block extends BaseComponent { Data.deleteCtx(this); if (blocksRegistry.size === 0) { - // Destroy external context if there is no any blocks left inside it - Data.deleteCtx(this.ctxName); + this.destroyCtxCallback(); } } + destroyCtxCallback() { + // Destroy external context if there is no any blocks left inside it + Data.deleteCtx(this.ctxName); + } + /** * @param {Number} bytes * @param {Number} [decimals] diff --git a/abstract/CTX.js b/abstract/CTX.js index 80a92632f..9c3111f7a 100644 --- a/abstract/CTX.js +++ b/abstract/CTX.js @@ -32,4 +32,5 @@ export const uploaderBlockCtx = (fnCtx) => ({ '*focusedEntry': null, '*uploadMetadata': null, '*uploadQueue': new Queue(1), + '*uploadCollection': null, }); diff --git a/abstract/UploaderBlock.js b/abstract/UploaderBlock.js index 3b181a0bc..efe63ee0f 100644 --- a/abstract/UploaderBlock.js +++ b/abstract/UploaderBlock.js @@ -70,7 +70,7 @@ export class UploaderBlock extends ActivityBlock { initCallback() { super.initCallback(); - if (!this.has('*uploadCollection')) { + if (!this.$['*uploadCollection']) { let uploadCollection = new TypedCollection({ typedSchema: uploadEntrySchema, watchList: [ @@ -82,7 +82,7 @@ export class UploaderBlock extends ActivityBlock { 'cdnUrlModifiers', ], }); - this.add('*uploadCollection', uploadCollection); + this.$['*uploadCollection'] = uploadCollection; } if (!this.hasCtxOwner && this.couldBeCtxOwner) { @@ -92,11 +92,15 @@ export class UploaderBlock extends ActivityBlock { destroyCallback() { super.destroyCallback(); - if (this.isCtxOwner) { - this._unobserveCollectionProperties?.(); - this._unobserveCollection?.(); - this.uploadCollection.destroy(); - } + } + + destroyCtxCallback() { + this._unobserveCollectionProperties?.(); + this._unobserveCollection?.(); + this.uploadCollection.destroy(); + this.$['*uploadCollection'] = null; + + super.destroyCtxCallback(); } initCtxOwner() { From 0e50b4f6dc2664eea7a7f12742660385a50610fd Mon Sep 17 00:00:00 2001 From: nd0ut Date: Thu, 7 Dec 2023 14:34:41 +0800 Subject: [PATCH 2/3] fix(activity-block): check for the `*modalActive` key presence in state before subscribing it --- abstract/ActivityBlock.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/abstract/ActivityBlock.js b/abstract/ActivityBlock.js index c84fcf405..5935a08d8 100644 --- a/abstract/ActivityBlock.js +++ b/abstract/ActivityBlock.js @@ -60,11 +60,14 @@ export class ActivityBlock extends Block { this.$['*history'] = []; } }); - this.sub('*modalActive', (modalActive) => { - if (!modalActive && this.activityType === this.$['*currentActivity']) { - this.$['*currentActivity'] = null; - } - }); + + if (this.has('*modalActive')) { + this.sub('*modalActive', (modalActive) => { + if (!modalActive && this.activityType === this.$['*currentActivity']) { + this.$['*currentActivity'] = null; + } + }); + } } } From 34dd6c6f8e14becc5843945c0f6df404cedc2c18 Mon Sep 17 00:00:00 2001 From: nd0ut Date: Thu, 7 Dec 2023 14:37:48 +0800 Subject: [PATCH 3/3] chore: add comment --- abstract/Block.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/abstract/Block.js b/abstract/Block.js index 62f98307e..fe977f6f1 100644 --- a/abstract/Block.js +++ b/abstract/Block.js @@ -200,8 +200,12 @@ export class Block extends BaseComponent { } } + /** + * Called when the last block is removed from the context. Note that inheritors must run their callback before that. + * + * @protected + */ destroyCtxCallback() { - // Destroy external context if there is no any blocks left inside it Data.deleteCtx(this.ctxName); }