sketch-hq/SketchAPI

Nested symbols detach behavior change in v72

romansp opened this issue · 1 comments

In our plugin we programmatically create symbol instance duplicate with duplicate(), detach it with detachStylesAndReplaceWithGroupRecursively(true) and later remove it. Beginning from v72 detaching now creates an extra group named "Group" that we're not expecting to be there. And this group isn't present when detaching before Sketch v72.

We can possibly workaround this extra group but would like to confirm first if that's normal behavior from now on. Also detaching symbol using UI action doesn't create this extra group.

Repro steps using Sketch 72.1:

  1. Open attached sketch file.
  2. Select "Basic Rectangle Large" symbol instance
  3. Select Plugins -> Run Script... and run provided script (attached below)
  4. Check document structure

Script:

var sketch = require('sketch');
var document = sketch.getSelectedDocument();

var selectedLayers = document.selectedLayers;
var symbolInstance = selectedLayers.layers[0];

var copy = symbolInstance.sketchObject.duplicate();
copy.detachStylesAndReplaceWithGroupRecursively(true);

Expected result:
Detached copy with the following structure is created

- Basic Rectangle Large 
  - Small Rectangle
      - Rectangle
    - Background

Actual result:

- Basic Rectangle Large 
  - Group
    - Small Rectangle
      - Rectangle
    - Background

I haven't checked but pretty sure JS API will produce the same result with extra group

var copy = symbolInstance.duplicate();
copy.detach({ recursively: true });

Sketch file: https://www.dropbox.com/s/0gfv0hwcwn9cpbv/nested-symbols-extra-group-on-detach.sketch?dl=1

This issue has been resolved in Sketch v76.