8000 Deleting a variable throws an exception · Issue #8994 · google/blockly · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Deleting a variable throws an exception #8994

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 task done
BenHenning opened this issue May 6, 2025 · 3 comments · Fixed by #8997
Closed
1 task done

Deleting a variable throws an exception #8994

BenHenning opened this issue May 6, 2025 · 3 comments · Fixed by #8997
Assignees
Labels
injection issue: bug Describes why the code or behaviour is wrong

Comments

@BenHenning
Copy link
Contributor

Check for duplicates

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

Description

When deleting a variable, a console error is thrown.

Reproduction steps

  1. Create new variable from the toolbox.
  2. Add the variable to the workspace.
  3. Right click on the variable and click to delete it.
  4. Open the developer console to see the stack trace thrown.

Stack trace

Uncaught Error: Attempting to focus node which isn't recognized by its parent tree: ???.
    at FocusManager.focusNode (focus_manager.ts:254:13)
    at focus_manager.ts:347:18

Screenshots

No response

Browsers

Chrome desktop

@BenHenning BenHenning added issue: bug Describes why the code or behaviour is wrong issue: triage Issues awaiting triage by a Blockly team member labels May 6, 2025
@rachel-fenichel rachel-fenichel moved this to In Progress in Blockly Accessibility May 6, 2025
@BenHenning
Copy link
Contributor Author

This was caused by the attempt at making ephemeral focus more robust in #8981.

I'm happy to revert that portion to fix the issue, but it actually speaks to a larger problem that both ephemeral focus and broader Blockly can sometimes run into problems where it's try to focus a node that is invalid to focus. As I see it, there are a number of issues trying to fix this:

  • Remove the check and treat trying to focus an invalid node as essentially a "de-focus" situation. This would be the most robust, but is likely to run into unintended side effects of focus being on a blockly element that's no longer attached. We could try to leverage the tree's default fallback instead of leaving focus arbitrarily on that element, though this will result in those cases turning into a default thing being focused. This may be okay.
  • Try to improve robustness detection. This isn't easy. I tried adding a simple "is this element still valid" check to fix this issue, and it doesn't because the element actually still is in the DOM but the node (in this case a created variable) is no longer in the block structure. I'm not sure if this is a timing thing or the DOM just isn't being cleaned up fully.

I think I actually lean toward the second solution in option (1) above, that is, fall back to a reasonable default when focus manager is given an invalid node to focus rather than throwing. I think this system is so central to Blockly now that we should try our best to recover rather than throwing (except when things are really obviously broken). I worry otherwise that we're just going to keep hitting failures with this exception in unexpected ways as we've seen versions of it come up repeatedly.

One note on that last sentence, though: it has actually helped detect a number of real logical failures that needed fixing elsewhere.

@rachel-fenichel
Copy link
Collaborator

I agree with falling back to a reasonable default if possible and treating it as a defocus if not possible--it matches Blockly's behaviour of trying to fail into a usable state.

@BenHenning BenHenning self-assigned this May 6, 2025
@BenHenning BenHenning linked a pull request May 6, 2025 that will close this issue
1 task
BenHenning added a commit that referenced this issue May 6, 2025
## The basics

- [x] I [validated my changes](https://developers.google.com/blockly/guides/contribute/core#making_and_verifying_a_change)

## The details
### Resolves

Fixes #8994

### Proposed Changes

This removes an error that was previously thrown by `FocusManager` when attempting to focus an invalid node (such as one that's been removed from its parent).

### Reason for Changes

#8994 (comment) goes into more detail. While this error did cover legitimately wrong cases to try and focus things (and helped to catch some real problems), fixing this 'properly' may become a leaky boat problem where we have to track down every possible asynchronous scenario that could produce such a case. One class of this is ephemeral focus which had robustness improvements itself in #8981 that, by effect, caused this issue in the first place. Holistically fixing this with enforced API contracts alone isn't simple due to the nature of how these components interact.

This change ensures that there's a sane default to fall back on if an invalid node is passed in. Note that `FocusManager` was designed specifically to disallow defocusing a node (since fallbacks can get messy and introduce unpredictable user experiences), and this sort of allows that now. However, this seems like a reasonable approach as it defaults to the behavior when focusing a tree explicitly which allows the tree to fallback to a more suitable default (such as the first item to select in the toolbox for that particular tree). In many cases this will default back to the tree's root node (such as the workspace root group) since sometimes the removed node is still the "last focused node" of the tree (and is considered valid for the purpose of determining a fallback; tree implementations could further specialize by checking whether that node is still valid).

### Test Coverage

Some new tests were added to cover this case, but more may be useful to add as part of #8910.

### Documentation

No documentation needs to be added or updated as part of this (beyond code documentation changes).

### Additional Information

This original issue was found by @RoboErikG when testing #8995. I also verified this against the keyboard navigation plugin repository.
@BenHenning
Copy link
Contributor Author

Fixed in #8997.

@github-project-automation github-project-automation bot moved this from In Progress to Done in Blockly Accessibility May 6, 2025
@sappm01 sappm01 added injection and removed issue: triage Issues awaiting triage by a Blockly team member labels May 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
injection issue: bug Describes why the code or behaviour is wrong
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants
0