fix: recover orphan blocks when connecting to parent fails#9715
Closed
goughjo02 wants to merge 1 commit intoRaspberryPiFoundation:mainfrom
Closed
fix: recover orphan blocks when connecting to parent fails#9715goughjo02 wants to merge 1 commit intoRaspberryPiFoundation:mainfrom
goughjo02 wants to merge 1 commit intoRaspberryPiFoundation:mainfrom
Conversation
1 task
Contributor
|
Hi, thank you for this PR. While we appreciate your work on it, we don't think this is the correct approach for this issue. Throwing an error upon trying to load invalid serialized state is correct, and the XML system should be changed to do this rather than creating divergent behavior between the XML and JSON systems. There is more reasoning in this comment. Feel free to respond in the bug if you have more questions. Thanks! |
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.
The basics
The details
Resolves
Fixes #9266
Proposed Changes
This PR changes XML deserialization so that when a nested child block can no longer connect to its intended parent because block definitions have drifted, Blockly preserves the child block instead of leaving it uninitialized and unrendered.
When a nested XML connection fails:
domToWorkspaceThis also adds regression tests for headless and rendered workspaces.
Reason for Changes
The current XML loader can silently create a block in the workspace model but fail to initialize or render it when a saved child connection becomes invalid. This can happen when applications evolve block definitions independently of previously saved XML.
Preserving the invalid child block as a visible disabled top-level block prevents user data loss and gives users a path to repair their workspace manually.
Test Coverage
Added XML deserialization tests covering:
domToWorkspaceValidation run:
npx eslint tests/mocha/xml_test.jsnpx eslint core/xml.ts core/constants.ts core/events/utils.ts tests/mocha/xml_test.jsnpm run build -- --debugI also ran smoke tests against the built sources to verify that recovered blocks load as top-level, initialized, disabled blocks with preserved field values and returned ids.
Documentation
No documentation updates required.
Additional Information
This intentionally prefers recovery over failure for invalid nested XML connections so that applications using Blockly with drifting block schemas do not lose user-authored block data.