Skip to content

Commit d3c6c5a

Browse files
vegedclaude
andcommitted
fix(i-bem-dom): prevent BEM event bubbling to parent of same block type (#1525)
Skip BEM events that bubbled up from nested blocks of the same type when handling instance-level subscriptions. Previously, destructing a child block would incorrectly trigger the parent's destruct handler if both were the same block type. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 5ea1bd5 commit d3c6c5a

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

common.blocks/i-bem-dom/__events/_type/i-bem-dom__events_type_bem.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ const EVENT_PREFIX = '__bem__',
6161
instanceDomElem.length && (instance = instanceDomElem.bem(ctx));
6262
}
6363

64+
// Skip events that bubbled up from nested blocks of the same type (#1525)
65+
if(!params.bindSelector &&
66+
params.bindDomElem.index(e.target) < 0) return
67+
6468
if(instance &&
6569
(!flags.propagationStoppedDomNode ||
6670
!$.contains(instanceDomElem[0], flags.propagationStoppedDomNode))) {

common.blocks/i-bem-dom/__events/_type/i-bem-dom__events_type_bem.spec.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,41 @@ describe('BEM events', function() {
969969
});
970970
});
971971

972+
describe('same-type nested blocks destruct (#1525)', function() {
973+
var ParentBlock, rootNode;
974+
975+
beforeEach(function() {
976+
ParentBlock = bemDom.declBlock('nested-same', {
977+
onInit : function() {
978+
this._events().on({ modName : 'js', modVal : '' }, this._onDestruct);
979+
},
980+
_onDestruct : function() {}
981+
});
982+
983+
rootNode = createDomNode({
984+
block : 'nested-same',
985+
js : true,
986+
content : {
987+
block : 'nested-same',
988+
js : true
989+
}
990+
});
991+
});
992+
993+
afterEach(function() {
994+
bemDom.destruct(rootNode);
995+
});
996+
997+
it('should not fire parent destruct handler when child of same type is destructed', function() {
998+
var parent = rootNode.bem(ParentBlock),
999+
child = parent.findChildBlock(ParentBlock),
1000+
spy = sinon.spy(parent, '_onDestruct');
1001+
1002+
bemDom.destruct(child.domElem);
1003+
spy.should.not.have.been.called;
1004+
});
1005+
});
1006+
9721007
provide();
9731008

9741009
function createDomNode(bemjson) {

0 commit comments

Comments
 (0)