-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Calling a.setParent(b) without connecting blocks a and b can cause major rendering issues and errors #4989
Comments
|
* Error now thrown when calling `a.setParent(b)` on non-null b if the output/previous connection of a is not connected to an input/next connection of b without removing block from old parent's child list. * Commented out error for when calling `a.setParent(null)` if a is connected to superior block. * Adjusted comment to reflect that blocks were no longer being disconnected in this method. * Also changed == to === per google#4924 (`newParent` and `this.parentBlock_` must both be instances of `Blockly.Block`).
* Error now thrown when calling `a.setParent(b)` on non-null b if the output/previous connection of a is not connected to an input/next connection of b without removing block from old parent's child list. * Error now thrown when calling `a.setParent(null)` if a is connected to a superior block. * Adjusted comment to reflect that blocks were no longer being disconnected in this method. * Also changed == to === per google#4924 (`newParent` and `this.parentBlock_` must both be instances of `Blockly.Block`).
* Error now thrown when calling `a.setParent(b)` on non-null b if the output/previous connection of a is not connected to an input/next connection of b without removing block from old parent's child list. * Commented out error for when calling `a.setParent(null)` if a is connected to superior block. * Adjusted comment to reflect that blocks were no longer being disconnected in this method. * Also changed == to === per google#4924 (`newParent` and `this.parentBlock_` must both be instances of `Blockly.Block`). * Fixed lint errors.
I browsed the history of the block.js file because I had the following questions:
The answer to question 2 and perhaps 1 can be traced back to the commit here where disconnection calls were replaced with thrown errors during refactoring: 2a1ffa1#diff-9b5800799b33a83e7ff338b52ff14964b5ab04f1a6e1834523b121f2ea070aeaR419. It seems to me then that for future stability, this method should be changed even though it's being declared as |
* Error now thrown when calling `a.setParent(b)` on non-null b if the output/previous connection of a is not connected to an input/next connection of b without removing block from old parent's child list. * Commented out error for when calling `a.setParent(null)` if a is connected to superior block. * Adjusted comment to reflect that blocks were no longer being disconnected in this method. * Also changed == to === per google#4924 (`newParent` and `this.parentBlock_` must both be instances of `Blockly.Block`). * Fixed lint errors. * Adjusted comment.
* Fix error conditions for setParent #4989 * Error now thrown when calling `a.setParent(b)` on non-null b if the output/previous connection of a is not connected to an input/next connection of b without removing block from old parent's child list. * Commented out error for when calling `a.setParent(null)` if a is connected to superior block. * Adjusted comment to reflect that blocks were no longer being disconnected in this method. * Also changed == to === per #4924 (`newParent` and `this.parentBlock_` must both be instances of `Blockly.Block`). * Fix error conditions for setParent #4989 * Error now thrown when calling `a.setParent(b)` on non-null b if the output/previous connection of a is not connected to an input/next connection of b without removing block from old parent's child list. * Error now thrown when calling `a.setParent(null)` if a is connected to a superior block. * Adjusted comment to reflect that blocks were no longer being disconnected in this method. * Also changed == to === per #4924 (`newParent` and `this.parentBlock_` must both be instances of `Blockly.Block`). * Fix error conditions for setParent #4989 * Error now thrown when calling `a.setParent(b)` on non-null b if the output/previous connection of a is not connected to an input/next connection of b without removing block from old parent's child list. * Commented out error for when calling `a.setParent(null)` if a is connected to superior block. * Adjusted comment to reflect that blocks were no longer being disconnected in this method. * Also changed == to === per #4924 (`newParent` and `this.parentBlock_` must both be instances of `Blockly.Block`). * Fixed lint errors. * Fix error conditions for setParent #4989 * Error now thrown when calling `a.setParent(b)` on non-null b if the output/previous connection of a is not connected to an input/next connection of b without removing block from old parent's child list. * Commented out error for when calling `a.setParent(null)` if a is connected to superior block. * Adjusted comment to reflect that blocks were no longer being disconnected in this method. * Also changed == to === per #4924 (`newParent` and `this.parentBlock_` must both be instances of `Blockly.Block`). * Fixed lint errors. * Adjusted comment. * Removed unnecessary set to null/added tests * One is failing (commented out), will investigate later * Lint fix * Removed failing test that correctly fails * Update comments to conform to style guide Capitalize first letter, period at end
Describe the bug
Calling
a.setParent(b)
on blocks a and b without connecting them can cause rendering issues where the parent and unconnected child block can move together with varying degrees of space in between them. Ifa
had no parent originally, then attempting to deleteb
results in an unmovableb
and error messages on any event.To Reproduce (2 possibilities)
Steps to reproduce the behavior (two different types):
3a. Enter the following in the Developer console:
workspace.getAllBlocks().find(block => block.type === "text").setParent(workspace.getAllBlocks().find(block => block.type === "text_print"))
4a. There will be a "Still connected to parent block error." Move the
text_join
block around the workspace and watch the text block jump all around.OR...
3b. Disconnect the text block and then enter the code from 3a in the console.
4b. No error this time, but if you move the print block, you will notice that the disconnected text block moves together with the print block. Attempt to delete the print block and the errors ensue.
Expected behavior
Should
setParent
be apackage
method? I'm not sure why it should be called for any other purpose than connecting/disconnecting blocks. In this case (outside ofBlockly.Block
andBlockly.BlockSvg
), it should not be needed outside of theConnection
class. The only other places I could find it being called were in testing to set the parent tonull
here:blockly/tests/mocha/event_test.js
Line 975 in 64188ae
and (indirectly) here:
blockly/tests/mocha/event_test.js
Line 977 in 64188ae
The text was updated successfully, but these errors were encountered: