From 769a25f4badffd2409ce19535344c98f5d8b01c9 Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Thu, 6 Jan 2022 10:42:32 -0800 Subject: [PATCH] fix: Don't throw if drag surface is empty. (#5695) Observed this error in Blockly Games Bird 6 (Chrome OS): Uncaught TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'. It has only shown up once, and I can't reproduce, but it looks like the drag surface was being cleared while empty. Maybe some weird multi-touch operation? Open question: Leave the code as is so that the error is thown and visible, or supress it? --- core/block_drag_surface.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/core/block_drag_surface.js b/core/block_drag_surface.js index 2ff685cde8e..ff619d390b0 100644 --- a/core/block_drag_surface.js +++ b/core/block_drag_surface.js @@ -252,11 +252,14 @@ BlockDragSurfaceSvg.prototype.getWsTranslation = function() { * being moved to a different surface. */ BlockDragSurfaceSvg.prototype.clearAndHide = function(opt_newSurface) { - if (opt_newSurface) { - // appendChild removes the node from this.dragGroup_ - opt_newSurface.appendChild(this.getCurrentBlock()); - } else { - this.dragGroup_.removeChild(this.getCurrentBlock()); + const currentBlockElement = this.getCurrentBlock(); + if (currentBlockElement) { + if (opt_newSurface) { + // appendChild removes the node from this.dragGroup_ + opt_newSurface.appendChild(currentBlockElement); + } else { + this.dragGroup_.removeChild(currentBlockElement); + } } this.SVG_.style.display = 'none'; if (this.dragGroup_.childNodes.length) {