From e856ea5c2ed0c43b0cd3381e9f37086d21738765 Mon Sep 17 00:00:00 2001 From: Laura Sach <5183697+lawsie@users.noreply.github.com> Date: Thu, 6 Aug 2026 13:53:03 +0100 Subject: [PATCH] Fix cascade bug --- blocks/blocks.js | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/blocks/blocks.js b/blocks/blocks.js index 3fcab7fb..f1b3bf8a 100644 --- a/blocks/blocks.js +++ b/blocks/blocks.js @@ -752,17 +752,20 @@ function createFreshVariable(workspace, prefix, type, nextVariableIndexes) { function retargetDescendantsVariables(rootBlock, fromVarId, toVarId, BlocklyNS, createdIds = null) { if (!fromVarId || !toVarId || fromVarId === toVarId) return 0; - // Get descendants but ONLY through input connections, not next/previous + // Get descendants but ONLY through input connections, not the root's own next/previous const descendants = []; function collectInputDescendants(block) { for (const input of block.inputList || []) { if (input.connection && input.connection.targetBlock()) { - const childBlock = input.connection.targetBlock(); - // Only include if it was created in the same event (if createdIds is provided) - if (!createdIds || createdIds.has(childBlock.id)) { - descendants.push(childBlock); - collectInputDescendants(childBlock); + let childBlock = input.connection.targetBlock(); + while (childBlock) { + // Only include if it was created in the same event (if createdIds is provided) + if (!createdIds || createdIds.has(childBlock.id)) { + descendants.push(childBlock); + collectInputDescendants(childBlock); + } + childBlock = childBlock.getNextBlock(); } } } @@ -834,9 +837,10 @@ function adoptIsolatedDefaultVarsTo( const descendants = []; for (const input of block.inputList || []) { if (input.connection && input.connection.targetBlock()) { - const childBlock = input.connection.targetBlock(); - descendants.push(childBlock); - descendants.push(...collectInputDescendants(childBlock)); + for (let childBlock = input.connection.targetBlock(); childBlock; childBlock = childBlock.getNextBlock()) { + descendants.push(childBlock); + descendants.push(...collectInputDescendants(childBlock)); + } } } return descendants;