Skip to content

Deleting workspace comments sometimes throws console warnings #1848

@rachel-fenichel

Description

@rachel-fenichel

Problem statement

Deleting a workspace comment by clicking on the "x" icon when it's selected deletes the comment, but throws warnings.

Expected Behavior

Comment is deleted and there are no warnings.

Steps to Reproduce

  1. Create a ws comment
  2. Select the comment for editing
  3. Click the comment's delete icon.

Stack Traces

Uncaught TypeError: Cannot read property 'blur' of null
    at workspace_comment_render_svg.js:456
(anonymous) @ workspace_comment_render_svg.js:456
setTimeout (async)
Blockly.WorkspaceCommentSvg.blurFocus @ workspace_comment_render_svg.js:455
Blockly.WorkspaceCommentSvg.removeSelect @ workspace_comment_svg.js:242
Blockly.WorkspaceCommentSvg.unselect @ workspace_comment_svg.js:221
Blockly.WorkspaceCommentSvg.dispose @ workspace_comment_svg.js:109
Blockly.WorkspaceCommentSvg.deleteMouseUp_ @ workspace_comment_render_svg.js:308
wrapFunc @ blockly.js:458

workspace_comment_render_svg.js:456 Uncaught TypeError: Cannot read property 'blur' of null
    at workspace_comment_render_svg.js:456
(anonymous) @ workspace_comment_render_svg.js:456
setTimeout (async)
Blockly.WorkspaceCommentSvg.blurFocus @ workspace_comment_render_svg.js:455
Blockly.WorkspaceCommentSvg.unselect @ workspace_comment_svg.js:222
Blockly.WorkspaceCommentSvg.dispose @ workspace_comment_svg.js:109
Blockly.WorkspaceCommentSvg.deleteMouseUp_ @ workspace_comment_render_svg.js:308
wrapFunc @ blockly.js:458

Additional Information

This is because we're deferring some style changes to the end of the frame, and the relevant svg elements have already been deleted by then. The solution is probably to explicitly track whether the comment has already been deleted.

Relevant code in workspace_comment_render_svg:

/**
 * Remove focus from the text area.
 * @package
 */
Blockly.WorkspaceCommentSvg.prototype.blurFocus = function() {
  var comment = this;
  this.focused_ = false;
  // Defer CSS changes.
  setTimeout(function() {
    comment.textarea_.blur();
    comment.removeFocus();
    Blockly.utils.removeClass(
        comment.svgRectTarget_, 'blocklyCommentTargetFocused');
    Blockly.utils.removeClass(
        comment.svgHandleTarget_, 'blocklyCommentHandleTargetFocused');
  }, 0);
};

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions