Skip to content

Commit

Permalink
fix: cancelling all renders on triggering queued renders (#7787)
Browse files Browse the repository at this point in the history
  • Loading branch information
BeksOmega authored Jan 16, 2024
1 parent 5ade042 commit 0d1245c
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions core/render_management.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type {WorkspaceSvg} from './workspace_svg.js';
const rootBlocks = new Set<BlockSvg>();

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

/**
* The promise which resolves after the current set of renders is completed. Or
Expand Down Expand Up @@ -81,9 +81,9 @@ export function finishQueuedRenders(): Promise<void> {
* @internal
*/
export function triggerQueuedRenders(workspace?: WorkspaceSvg) {
window.cancelAnimationFrame(animationRequestId);
if (!workspace) window.cancelAnimationFrame(animationRequestId);
doRenders(workspace);
if (afterRendersResolver) afterRendersResolver();
if (!workspace && afterRendersResolver) afterRendersResolver();
}

/**
Expand Down Expand Up @@ -134,9 +134,19 @@ function doRenders(workspace?: WorkspaceSvg) {
block.updateComponentLocations(blockOrigin);
}

rootBlocks.clear();
dirtyBlocks = new WeakSet();
afterRendersPromise = null;
for (const block of blocks) {
dequeueBlock(block);
}
if (!workspace) afterRendersPromise = null;
}

/** Removes the given block and children from the render queue. */
function dequeueBlock(block: BlockSvg) {
rootBlocks.delete(block);
dirtyBlocks.delete(block);
for (const child of block.getChildren(false)) {
dequeueBlock(child);
}
}

/**
Expand Down

0 comments on commit 0d1245c

Please sign in to comment.