8000 fix: Ensure BlockSvg is uniquely focusable on the page by BenHenning · Pull Request #9045 · google/blockly · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: Ensure BlockSvg is uniquely focusable on the page #9045

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

Merged

Conversation

BenHenning
Copy link
Contributor
@BenHenning BenHenning commented May 13, 2025

The basics

The details

Resolves

Fixes #9043
Fixes google/blockly-samples#2512

Proposed Changes

This replaces using BlockSvg's own ID for focus management since that's not guaranteed to be unique across all workspaces on the page.

Reason for Changes

Both google/blockly-samples#2512 covers the user-facing issue in more detail, but from a technical perspective it's possible for blocks to share IDs across workspaces. One easy demonstration of this is the flyout: the first block created from the flyout to the main workspace will share an ID. The workspace minimap plugin just makes the underlying problem more obvious.

The reason this introduces a breakage is due to the inherent ordering that FocusManager uses when trying to find a matching tree for a given DOM element that has received focus. These trees are iterated in the order of their registration, so it's quite possible for some cases (like main workspace vs. flyout) to resolve such that the behavior looks correct to users, vs. others (such as the workspace minimap) not behaving as expected.

Guaranteeing ID uniqueness across all workspaces fixes the problem entirely.

Test Coverage

This has been manually tested in core Blockly's simple test playground and in Blockly samples' workspace minimap plugin test environment (linked against this change). See the new behavior for the minimap plugin:

Screen.recording.2025-05-13.4.31.31.PM.webm

Note that this is a regression to v11 behavior in that the blocks in the minimap now show as selected.

This has been verified as working with the latest version of the keyboard navigation plugin (tip-of-tree). Keyboard-based block operations and movement seem to work as expected.

For automated testing this is expected to largely be covered by future tests added as part of resolving #8915.

Documentation

No public documentation changes should be needed, though IFocusableNode's documentation has been refined to be clearer on the uniqueness property for focusable element IDs.

Additional Information

There's a separate open design question here about whether BlockSvg's descendants should use the new focus ID vs. the block ID. Here is what I consider to be the trade-off analysis in this decision:

Pros Cons
Use BlockSvg.id Can use fast WorkspaceSvg.getBlockById. WorkspaceSvg.lookUpFocusableNode now uses 2 different IDs.
Use BlockSvg.focusId Consistency in IDs use for block-related focus. Requires more expensive block look-up in WorkspaceSvg.lookUpFocusableNode.

This replaces using BlockSvg's own ID since that's not guaranteed to be
unique across all workspaces on the page.
@github-actions github-actions bot added PR: fix Fixes a bug and removed PR: fix Fixes a bug labels May 13, 2025
@BenHenning BenHenning marked this pull request as ready for review May 13, 2025 23:32
@BenHenning BenHenning requested a review from a team as a code owner May 13, 2025 23:32
@BenHenning BenHenning requested a review from maribethb May 13, 2025 23:32
@BenHenning
Copy link
Contributor Author

PTAL @maribethb though be aware that there's an open design question that I'd like input on, and additional testing to do once google/blockly-keyboard-experimentation#520 is merged.

@github-actions github-actions bot added PR: fix Fixes a bug and removed PR: fix Fixes a bug labels May 13, 2025
Copy link
Contributor
@maribethb maribethb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I would use the first option in your design question. The reason being that it might be possible to have globally unique block IDs in the future and then we could just revert this change.

We actually tried to have globally unique block ids in a previous release, but code.org was relying on the current behavior in their tests so it became a blocking/breaking change for them. I think Mike said he was working on their tests such that that would no longer be a blocker. See #7432 for historic context

As an aside, I think the correct behavior for the minimap would be to select the block in the main workspace when a block in the minimap is selected and I wonder if that's now possible with navigation policies?

@BenHenning
Copy link
Contributor Author

I think I would use the first option in your design question. The reason being that it might be possible to have globally unique block IDs in the future and then we could just revert this change.

We actually tried to have globally unique block ids in a previous release, but code.org was relying on the current behavior in their tests so it became a blocking/breaking change for them. I think Mike said he was working on their tests such that that would no longer be a blocker. See #7432 for historic context

As an aside, I think the correct behavior for the minimap would be to select the block in the main workspace when a block in the minimap is selected and I wonder if that's now possible with navigation policies?

Ah, that's very helpful. In that case things stay as-is since the first option is the current status quo. And completely agree on the possibilities to simplify this in the future if truly global IDs can be reintroduced.

As for the selection bit, do you want me to file a bug on that? It should be possible purely with focus manager actually, but it would need to be a change in the plugin (and I'm uncertain the extent of the changes without digging into the plugin code more, but it might not be too complicated).

@github-actions github-actions bot added PR: fix Fixes a bug and removed PR: fix Fixes a bug labels May 14, 2025
@BenHenning
Copy link
Contributor Author

Confirming that this works well against the keyboard navigation plugin tip-of-tree.

@BenHenning BenHenning merged commit 2b9d06a into google:rc/v12.0.0 May 14, 2025
17 checks passed
@BenHenning BenHenning deleted the use-unique-focus-ids-for-blocks branch May 14, 2025 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: fix Fixes a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0