Skip to content

Commit dccedbf

Browse files
BeksOmegamaribethb
authored andcommitted
fix: cancelling all renders on triggering queued renders (#7787)
(cherry picked from commit 0d1245c)
1 parent f027b82 commit dccedbf

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

core/render_management.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import type {WorkspaceSvg} from './workspace_svg.js';
1212
const rootBlocks = new Set<BlockSvg>();
1313

1414
/** The set of all blocks in need of rendering. */
15-
let dirtyBlocks = new WeakSet<BlockSvg>();
15+
const dirtyBlocks = new WeakSet<BlockSvg>();
1616

1717
/**
1818
* The promise which resolves after the current set of renders is completed. Or
@@ -81,9 +81,9 @@ export function finishQueuedRenders(): Promise<void> {
8181
* @internal
8282
*/
8383
export function triggerQueuedRenders(workspace?: WorkspaceSvg) {
84-
window.cancelAnimationFrame(animationRequestId);
84+
if (!workspace) window.cancelAnimationFrame(animationRequestId);
8585
doRenders(workspace);
86-
if (afterRendersResolver) afterRendersResolver();
86+
if (!workspace && afterRendersResolver) afterRendersResolver();
8787
}
8888

8989
/**
@@ -134,9 +134,19 @@ function doRenders(workspace?: WorkspaceSvg) {
134134
block.updateComponentLocations(blockOrigin);
135135
}
136136

137-
rootBlocks.clear();
138-
dirtyBlocks = new WeakSet();
139-
afterRendersPromise = null;
137+
for (const block of blocks) {
138+
dequeueBlock(block);
139+
}
140+
if (!workspace) afterRendersPromise = null;
141+
}
142+
143+
/** Removes the given block and children from the render queue. */
144+
function dequeueBlock(block: BlockSvg) {
145+
rootBlocks.delete(block);
146+
dirtyBlocks.delete(block);
147+
for (const child of block.getChildren(false)) {
148+
dequeueBlock(child);
149+
}
140150
}
141151

142152
/**

0 commit comments

Comments
 (0)