Sketch MeaXure Plugin breaked in v 97.2

I did a quick research about this error and it seems to be actually coming from the official Sketch JS API rather than the plugin itself.

Pretty easy to reproduce too – run the following commands in the Plugins > Run Script panel:

var sketch = require('sketch/dom')

let style = new sketch.Style()
// now try to assign any text-specific attributes
style.alignment = sketch.Text.Alignment.center;
🤖 A bunch of technical details for developers

The culprit is that most Style class setters are using the following code to re-create an underlying native text style if it doesn’t exists yet in the current style instance:

  let textStyle = _object.textStyle()

  if (!textStyle) {
    textStyle = MSTextStyle.styleWithAttributes(
      MSDefaultTextStyle.defaultTextStyle()
    )
    [...]
  }

(SketchAPI/Source/dom/style/Text.js:58)

and MSTextStyle.styleWithAttributes(...) doesn’t exist anymore since Sketch 97.

A workaround (for plugin developers, that is) is to specify a target layer type when creating Style objects. For instance, in the sample code above:

var sketch = require('sketch/dom')

-let style = new sketch.Style()
+let style = new sketch.Style({}, sketch.Types.Text);
style.alignment = sketch.Text.Alignment.center;

Now, @yeb would you please try the fixed version of the plugin? I’ve applied the aforementioned workaround and also fixed a few other compatibility issues with modern Sketch versions (around Spec Export > Export layer influence rect option, altough I don’t fully understand what the output of this should be, so let me know).

@jonne given that it seems to be a bug in the official Sketch JS API, it makes sense to file a bug report for the dev team. I usually email productsupport@, but I I guess this post would do?

2 Likes