From 65a97d6bb93eba41efa2702a07651f58da40fe40 Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Fri, 7 Aug 2020 14:09:16 +0200 Subject: [PATCH] Avoid infinite recursion in Firefox on component drag. Fixes #2911 --- src/utils/Sorter.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/utils/Sorter.js b/src/utils/Sorter.js index 31893ec1c..e9f5df8d0 100644 --- a/src/utils/Sorter.js +++ b/src/utils/Sorter.js @@ -397,11 +397,15 @@ export default Backbone.View.extend({ * Highlight target * @param {Model|null} model */ - selectTargetModel(model) { + selectTargetModel(model, source) { if (model instanceof Backbone.Collection) { return; } + // Prevents loops in Firefox + // https://github.com/artf/grapesjs/issues/2911 + if (source && source === model) return; + const { targetModel } = this; // Reset the previous model but not if it's the same as the source @@ -453,7 +457,7 @@ export default Backbone.View.extend({ const dims = this.dimsFromTarget(e.target, rX, rY); const target = this.target; const targetModel = target && this.getTargetModel(target); - this.selectTargetModel(targetModel); + this.selectTargetModel(targetModel, sourceModel); if (!targetModel) plh.style.display = 'none'; if (!target) return; @@ -474,7 +478,7 @@ export default Backbone.View.extend({ // If there is a significant changes with the pointer if ( !this.lastPos || - (this.lastPos.index != pos.index || this.lastPos.method != pos.method) + this.lastPos.index != pos.index || this.lastPos.method != pos.method ) { this.movePlaceholder(this.plh, dims, pos, this.prevTargetDim); if (!this.$plh) this.$plh = $(this.plh);