Skip to content

Commit

Permalink
fix(block): destroy both local and global contexts
Browse files Browse the repository at this point in the history
  • Loading branch information
nd0ut committed Dec 1, 2023
1 parent 362fea9 commit bdd4a33
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion abstract/Block.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @ts-check
import { BaseComponent } from '@symbiotejs/symbiote';
import { BaseComponent, Data } from '@symbiotejs/symbiote';
import { EventEmitter } from '../blocks/UploadCtxProvider/EventEmitter.js';
import { createWindowHeightTracker, getIsWindowHeightTracked } from '../utils/createWindowHeightTracker.js';
import { getPluralForm } from '../utils/getPluralForm.js';
Expand Down Expand Up @@ -188,8 +188,18 @@ export class Block extends BaseComponent {
}

destroyCallback() {
/** @type {Set<Block>} */
let blocksRegistry = this.$['*blocksRegistry'];
blocksRegistry.delete(this);

// Destroy local context
// TODO: this should be done inside symbiote
Data.deleteCtx(this);

if (blocksRegistry.size === 0) {
// Destroy external context if there is no any blocks left inside it
Data.deleteCtx(this.ctxName);
}
}

/**
Expand Down

0 comments on commit bdd4a33

Please sign in to comment.