Skip to content

fix(dia.Paper): fix autoFreeze=true with frozen=true options #3030

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update
  • Loading branch information
kumilingus committed Aug 5, 2025
commit 9d8de3f2fe5a3f60b8fde622e7eef9289cd7eb7c
2 changes: 1 addition & 1 deletion packages/joint-core/demo/performance/async.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
</span>
<span>
<label for="autofreeze">Auto Freeze</label>
<input id="autofreeze" type="checkbox"/>
<input id="autofreeze" type="checkbox" checked="true"/>
</span>
<span>
<label for="leave-rendered-in-viewport">Keep rendered in viewport</label>
Expand Down
1 change: 1 addition & 0 deletions packages/joint-core/demo/performance/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ var paper = new Paper({
model: graph,
async: true,
frozen: true,
autoFreeze: true,
viewManagement: {
lazyInitialize: true,
disposeHidden: true,
Expand Down
26 changes: 20 additions & 6 deletions packages/joint-core/src/dia/Paper.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1153,7 +1153,12 @@ export const Paper = View.extend({

updateViewsAsync: function(opt, data) {
opt || (opt = {});
data || (data = { processed: 0, priority: MIN_PRIORITY });
data || (data = {
processed: 0,
priority: MIN_PRIORITY,
checkedUnmounted: 0,
checkedMounted: 0,
});
const { _updates: updates, options } = this;
const id = updates.id;
if (id) {
Expand Down Expand Up @@ -1187,15 +1192,24 @@ export const Paper = View.extend({
} else {
data.processed = processed;
}
data.checkedUnmounted = 0;
data.checkedMounted = 0;
} else {
data.checkedUnmounted += Math.max(passingOpt.mountBatchSize, 0);
data.checkedMounted += Math.max(passingOpt.unmountBatchSize, 0);
// The `checkViewport` could have scheduled some insertions
// (note that removals are currently done synchronously).
if (options.autoFreeze && !this.hasScheduledUpdates()) {
// If there are no updates scheduled, freeze the paper.
// Notify the idle state.
this.freeze();
updates.idle = true;
this.trigger('render:idle', opt);
// If there are no updates scheduled and we checked all unmounted views,
if (
data.checkedUnmounted >= updates.unmountedList.length &&
data.checkedMounted >= updates.mountedList.length
) {
// We freeze the paper and notify the idle state.
this.freeze();
updates.idle = true;
this.trigger('render:idle', opt);
}
}
}
// Progress callback
Expand Down
74 changes: 74 additions & 0 deletions packages/joint-core/test/jointjs/dia/Paper.js
Original file line number Diff line number Diff line change
Expand Up @@ -1910,6 +1910,80 @@ QUnit.module('joint.dia.Paper', function(hooks) {

testPaper.remove();
});

QUnit.test('idle after all mount && updates', async function(assert) {

const done = assert.async();

const testPaper = new Paper({
el: paperEl,
model: graph,
async: true,
autoFreeze: true,
sorting: Paper.sorting.APPROX,
viewManagement: {
lazyInitialize: true,
disposeHidden: true,
},
cellVisibility: (cell) => cell.get('visible')
});

const count = 10;
const rects = Array.from({ length: count }, () => new joint.shapes.standard.Rectangle());
graph.resetCells(rects);

await OnIdle(testPaper);

assert.equal(cellNodesCount(testPaper), 0);

rects.at(-1).set('visible', true);

testPaper.unfreeze({ mountBatchSize: 1 });

await OnIdle(testPaper);

assert.equal(cellNodesCount(testPaper), 1, 'All cells rendered after unfreeze() and idle');

done();
});

QUnit.test('idle after all unmount && updates', async function(assert) {

const done = assert.async();

const testPaper = new Paper({
el: paperEl,
model: graph,
async: true,
autoFreeze: true,
sorting: Paper.sorting.APPROX,
viewManagement: {
lazyInitialize: true,
disposeHidden: true,
},
cellVisibility: (cell) => cell.get('visible')
});

const count = 10;
const rects = Array.from({ length: count }, () => new joint.shapes.standard.Rectangle({
visible: true
}));
graph.resetCells(rects);

await OnIdle(testPaper);

assert.equal(cellNodesCount(testPaper), 10);

rects.at(-1).set('visible', false);

testPaper.unfreeze({ unmountBatchSize: 1 });

await OnIdle(testPaper);

assert.equal(cellNodesCount(testPaper), 9, 'All cells rendered after unfreeze() and idle');

done();
});
});

QUnit.module('async = TRUE, frozen = TRUE', function(hooks) {
Expand Down
Loading