Skip to content
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

Comments not recorded in delete event #1960

Closed
NeilFraser opened this issue Jun 29, 2018 · 8 comments · Fixed by #2027
Closed

Comments not recorded in delete event #1960

NeilFraser opened this issue Jun 29, 2018 · 8 comments · Fixed by #2027
Labels

Comments

@NeilFraser
Copy link
Contributor

In the playground, turn on event logging and open the console.
Create any block (I'll use 'not' in this example) and place it on the workspace.
Add a 'hello world' comment to this block. Note that a Change event is correctly created.
Delete the block. Note that the Delete event's oldXML.outerHTML lacks the comment:

<block type="logic_negate" id="TDR|)+6F]?Id!;Pl9GcJ" x="137" y="212"></block>

Then if undo is executed, the block reappears without the comment.

This is not a regression.

@rachel-fenichel
Copy link
Collaborator

@kchadha FYI

@RoboErikG
Copy link
Contributor

Investigated some. The problem is that BlockSVG.dispose disposes of the icons before super.dispose which is where the delete event gets recorded. Since the icon owns the comment the comment gets destroyed before we can save it.

Short term I'll investigate if we can just destroy the icons after calling super, but long term the icon probably shouldn't own the comment like that.

RoboErikG added a commit to RoboErikG/blockly that referenced this issue Jul 12, 2018
RoboErikG added a commit to RoboErikG/blockly that referenced this issue Jul 12, 2018
The icons in rendered Blockly currently own the comment text. When
a block was deleted the icons were being disposed of before the block
info was recorded in the event, which meant the comment was lost. This
adds some additional logic to block_svg to make sure the event is
captured before the icons are removed.
RoboErikG added a commit that referenced this issue Jul 12, 2018
The icons in rendered Blockly currently own the comment text. When
a block was deleted the icons were being disposed of before the block
info was recorded in the event, which meant the comment was lost. This
adds some additional logic to block_svg to make sure the event is
captured before the icons are removed.
RoboErikG added a commit that referenced this issue Jul 16, 2018
#1973)

* Revert "Localisation updates from https://translatewiki.net."

This reverts commit c4a0b64.

* Revert "Fix #1960 by collecting block info before icons are destroyed (#1970)"

This reverts commit 9a3bd45.
@RoboErikG RoboErikG reopened this Jul 16, 2018
RoboErikG added a commit to RoboErikG/blockly that referenced this issue Jul 23, 2018
RoboErikG added a commit to RoboErikG/blockly that referenced this issue Jul 23, 2018
RoboErikG added a commit that referenced this issue Jul 23, 2018
@RoboErikG RoboErikG reopened this Sep 5, 2018
@RoboErikG
Copy link
Contributor

The fix was rolled back as it broke other things.

@BeksOmega
Copy link
Collaborator

BeksOmega commented Dec 26, 2018

I ran into this when I was testing the trashcan contents, and I was wondering, is there any reason why we couldn't just dispose of the block before disposing of the icons? i.e.:

  Blockly.BlockSvg.superClass_.dispose.call(this, healStack);
  Blockly.Events.disable();
  try {
    var icons = this.getIcons();
    for (var i = 0; i < icons.length; i++) {
      icons[i].dispose();
    }
  } finally {
    Blockly.Events.enable();
  }

instead of:

Blockly.Events.disable();
try {
  var icons = this.getIcons();
  for (var i = 0; i < icons.length; i++) {
    icons[i].dispose();
  }
} finally {
  Blockly.Events.enable();
}
Blockly.BlockSvg.superClass_.dispose.call(this, healStack);

I did a quick test and I think it would work. I couldn't replicate the error found in #1970, and I don't believe any of the functions following the superClass_.dispose() call would access the block, but it does seem like it would be a bit of a silly thing to do.

Here's the link to the relevant .dispose() function.

Edit: I went back and looked at #1970 & #1972 and I believe the only problem is that it needs to call this.unplug(healStack) before creating the delete event. I did a quick check and there were no more errors.

@rachel-fenichel
Copy link
Collaborator

@RoboErikG you were looking at this earlier. Does this fix make sense to you?

@RoboErikG
Copy link
Contributor

As far as I can tell it would work, but I'm really hesitant to call the super's dispose before the specific dispose. It's typically an implied part of the API that more general cleanup code gets called after the specific cleanup code.

I'd be okay with making this as a temporary fix with a TODO to move the super's dispose down again once we separate out the comment's model and UI.

@BeksOmega
Copy link
Collaborator

BeksOmega commented Jan 7, 2019

We could also use the old fix, and just add this.unplug(healStack) before creating the delete event. If we were to add that, the blocks wouldn't be connected anymore so we wouldn't get the error from #1972. (Tested and confirmed) You can see how block.js does this inside it's dispose function.

If we were to do that it would preserve the cleanup order, as well as fix the issue.

@RoboErikG
Copy link
Contributor

I like that solution more, and there shouldn't be any issues with unplug being called twice. =)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants