Skip to content

Attempted to focus unregistered tree when disposing the workspace with focused block. #9601

@alexcui03

Description

@alexcui03

Check for duplicates

  • I have searched for similar issues before opening a new one.

Description

When disposing a workspace with a focused block, Blockly will raise the following error:

focus_manager.ts:232
Uncaught Error: Attempted to focus unregistered tree: [object Object].
    at FocusManager$$module$build$src$core$focus_manager.focusTree (focus_manager.ts:232:1)
    at eval (block_svg.ts:885:1)

I think it is caused by the following code in core/block_svg.ts:

override dispose(healStack?: boolean, animate?: boolean) {
  // ...

  const focusManager = getFocusManager();
  if (
    this.getSvgRoot().contains(
      focusManager.getFocusedNode()?.getFocusableElement() ?? null,
    )
  ) {
    let parent: BlockSvg | undefined | null = this.getParent();
    // ...
    if (parent) {
      focusManager.focusNode(parent);
    } else {
      setTimeout(() => focusManager.focusTree(this.workspace), 0);
    }
  }

Since top blocks does not have any parent, then it will finally execute setTimeout when disposing. But this.workspace will be unregistered before focusManager.focusTree is excuted.

Reproduction steps

  1. Create a workspace with any block.
  2. Click any input of that block to focus on it.
  3. Dispose the workspace.

Priority

No response

Stack trace

focus_manager.ts:232 Uncaught Error: Attempted to focus unregistered tree: [object Object].
    at FocusManager$$module$build$src$core$focus_manager.focusTree (focus_manager.ts:232:1)
    at eval (block_svg.ts:885:1)
focusTree @ focus_manager.ts:232
eval @ block_svg.ts:885
setTimeout
dispose @ block_svg.ts:885
clear @ workspace.ts:368
clear @ workspace_svg.ts:2324
dispose @ workspace.ts:144
dispose @ workspace_svg.ts:893

Screenshots

No response

Browsers

No response

Metadata

Metadata

Assignees

Labels

issue: bugDescribes why the code or behaviour is wrong

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions