From 43be0edf5d2836ded59d083138674a4fd8b3aa7d Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 2 Apr 2026 11:01:29 -0700 Subject: [PATCH] fix!: Fix types on `BlockSvg` connections (#9669) --- 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 a7ad5374a..8ab961ee5 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 666436c1e..051d7ace5 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 f4578a941..c521e8b11 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 c474bc8c3..f70462fa2 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, );