Skip to content

Commit 2eff4f3

Browse files
authored
fix(paper): preserve pending update flags when cell is hidden during updateViewsBatch (#3256)
1 parent 8400dcf commit 2eff4f3

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

packages/joint-core/src/dia/Paper.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1935,11 +1935,11 @@ export const Paper = View.extend({
19351935
// The view is currently mounted. Hide the view (detach or remove it).
19361936
this.registerUnmountedView(view);
19371937
this._hideView(view);
1938-
} else {
1939-
// The view is not mounted. We can just update the unmounted list.
1940-
// We ADD the current flag to the flag that was already scheduled.
1941-
this._mergeUnmountedViewScheduledUpdates(cid, currentFlag);
19421938
}
1939+
// At this point the view is not mounted (either it was just unmounted or was already unmounted).
1940+
// Merge the current flag into any already-scheduled updates for this unmounted view.
1941+
this._mergeUnmountedViewScheduledUpdates(cid, currentFlag);
1942+
19431943
// Delete the current update as it has been processed.
19441944
delete priorityUpdates[cid];
19451945
unmountCount++;

packages/joint-core/test/jointjs/dia/Paper.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2972,6 +2972,36 @@ QUnit.module('joint.dia.Paper', function(hooks) {
29722972

29732973
paper.remove();
29742974
});
2975+
2976+
QUnit.test('propagate updates flag when the cell is hidden during the update', function(assert) {
2977+
const graph = new joint.dia.Graph({}, { cellNamespace: joint.shapes });
2978+
2979+
paper = new Paper({
2980+
el: paperEl,
2981+
model: graph,
2982+
viewManagement: true,
2983+
cellVisibility: (cell) => {
2984+
const position = cell.position();
2985+
2986+
return position.x <= 200;
2987+
},
2988+
});
2989+
2990+
const rect = new joint.shapes.standard.Rectangle({ position: { x: 0, y: 0 }, size: { width: 50, height: 50 }});
2991+
rect.addTo(graph);
2992+
2993+
const view = rect.findView(paper);
2994+
2995+
assert.ok(view.el.parentElement, 'View element mounted in the DOM');
2996+
2997+
rect.translate(300, 0);
2998+
2999+
assert.notOk(view.el.parentElement, 'View element is removed from the DOM when the cell is hidden');
3000+
3001+
paper.updateCellsVisibility({ cellVisibility: () => true });
3002+
3003+
assert.equal(view.el.getAttribute('transform'), 'translate(300,0)', 'View has correct transform attribute after visibility update');
3004+
});
29753005
});
29763006

29773007
QUnit.module('isViewMounted()', function() {

0 commit comments

Comments
 (0)