From 8c79db0e362de5be445425150c0de1fbc5040e45 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 30 Mar 2026 15:39:55 -0700 Subject: [PATCH] fix!: Fix types on `BlockSvg` connections --- packages/blockly/blocks/text.ts | 6 ++++-- packages/blockly/core/block_svg.ts | 9 +++------ .../blockly/core/dragging/block_drag_strategy.ts | 16 +++++++++++----- packages/blockly/core/renderers/common/drawer.ts | 2 +- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/packages/blockly/blocks/text.ts b/packages/blockly/blocks/text.ts index a7ad5374ac4..8ab961ee5bc 100644 --- a/packages/blockly/blocks/text.ts +++ b/packages/blockly/blocks/text.ts @@ -757,13 +757,15 @@ const JOIN_MUTATOR_MIXIN = { 'text_create_join_container', ) as BlockSvg; containerBlock.initSvg(); - let connection = containerBlock.getInput('STACK')!.connection!; + let connection = containerBlock.getInput('STACK')?.connection; for (let i = 0; i < this.itemCount_; i++) { const itemBlock = workspace.newBlock( 'text_create_join_item', ) as JoinItemBlock; itemBlock.initSvg(); - connection.connect(itemBlock.previousConnection); + if (itemBlock.previousConnection) { + connection?.connect(itemBlock.previousConnection); + } connection = itemBlock.nextConnection; } return containerBlock; diff --git a/packages/blockly/core/block_svg.ts b/packages/blockly/core/block_svg.ts index 0bdb726b8c0..63b3dd14866 100644 --- a/packages/blockly/core/block_svg.ts +++ b/packages/blockly/core/block_svg.ts @@ -160,12 +160,9 @@ export class BlockSvg private visuallyDisabled = false; override workspace: WorkspaceSvg; - // TODO(b/109816955): remove '!', see go/strict-prop-init-fix. - override outputConnection!: RenderedConnection; - // TODO(b/109816955): remove '!', see go/strict-prop-init-fix. - override nextConnection!: RenderedConnection; - // TODO(b/109816955): remove '!', see go/strict-prop-init-fix. - override previousConnection!: RenderedConnection; + override outputConnection: RenderedConnection | null = null; + override nextConnection: RenderedConnection | null = null; + override previousConnection: RenderedConnection | null = null; private translation = ''; diff --git a/packages/blockly/core/dragging/block_drag_strategy.ts b/packages/blockly/core/dragging/block_drag_strategy.ts index f4578a9410b..c521e8b115e 100644 --- a/packages/blockly/core/dragging/block_drag_strategy.ts +++ b/packages/blockly/core/dragging/block_drag_strategy.ts @@ -366,7 +366,7 @@ export class BlockDragStrategy implements IDragStrategy { }; } - this.startChildConn = nextTargetConn; + this.startChildConn = nextTargetConn ?? null; } } } @@ -627,7 +627,7 @@ export class BlockDragStrategy implements IDragStrategy { draggingBlock.outputConnection, draggingBlock.previousConnection, draggingBlock.nextConnection, - ].filter(Boolean); // Removes falsy (null) values. + ].filter((c) => !!c); // Removes falsy (null) values. const inputConnections: RenderedConnection[] = []; for (const conn of available) { @@ -727,14 +727,20 @@ export class BlockDragStrategy implements IDragStrategy { this.connectionPreviewer?.hidePreview(); this.connectionCandidate = null; - this.startChildConn?.connect(this.block.nextConnection); + if (this.block.nextConnection) { + this.startChildConn?.connect(this.block.nextConnection); + } if (this.startParentConn) { switch (this.startParentConn.type) { case ConnectionType.INPUT_VALUE: - this.startParentConn.connect(this.block.outputConnection); + if (this.block.outputConnection) { + this.startParentConn.connect(this.block.outputConnection); + } break; case ConnectionType.NEXT_STATEMENT: - this.startParentConn.connect(this.block.previousConnection); + if (this.block.previousConnection) { + this.startParentConn.connect(this.block.previousConnection); + } } } else { this.block.moveTo(this.startLoc!, ['drag']); diff --git a/packages/blockly/core/renderers/common/drawer.ts b/packages/blockly/core/renderers/common/drawer.ts index c474bc8c339..f70462fa23a 100644 --- a/packages/blockly/core/renderers/common/drawer.ts +++ b/packages/blockly/core/renderers/common/drawer.ts @@ -422,7 +422,7 @@ export class Drawer { const x = this.info_.startX + this.info_.outputConnection.connectionOffsetX; const connX = this.info_.RTL ? -x : x; - this.block_.outputConnection.setOffsetInBlock( + this.block_.outputConnection?.setOffsetInBlock( connX, this.info_.outputConnection.connectionOffsetY, );