[Google Blockly] do not save ids with copied blocks#67021
Merged
Conversation
1 task
molly-moen
approved these changes
Jul 11, 2025
| addCoordinates: true, | ||
| addNextBlocks: false, | ||
| // We intentionally do not save IDs, because this can break student code | ||
| // on the hidden procedure definition workspace. |
Contributor
There was a problem hiding this comment.
can you add a link to the blockly ticket here?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A user reported an issue where copying and pasting a block between functions was causing the originally copied block to get deleted: https://codeorg.zendesk.com/agent/tickets/545093
This is reproduced below:
before.mp4
This seems to be due to a conflict between two plugins we use: cross-tab copy/paste and shareable procedures.
As a reminder, this our set up:
This is the flow:
I believe this is happening because you can't have two blocks on the same workspace with the same id, so the old one gets removed. Ordinarily, if a block id is in use, Blockly will generate another. I suspect that doesn't happen because of the way the block creation event is mirrored, which doesn't give Blockly a chance to generate a new id.
To fix this, I was able to override
BlockSvg.toCopyDataso that it explicitly doesn't save ids. This means Blockly will always generate a new id for a pasted block. The original method from Core is defined here:https://github.com/google/blockly/blob/60b7ee1325fc366d8ae6dd1699dd9fc95b208f3c/core/block_svg.ts#L956-L968
The result is that a block can now be safely copied between workspace.
after.mp4
Blockly issue filed:
Links
Testing story
Deployment strategy
Follow-up work
Privacy
Security
Caching
PR Checklist: