[BUG] 22.4 Layer references do not match same layers from different arrays

Apparently 22.4 broke a lot of things. One of them is how layers are referenced (I guess)

Here’s a simple snippet:

    const doc = app.activeDocument;
    const activeLayers = doc.activeLayers.filter(l => doc.layerTree.includes(l));

Exact same situation and doc.layerTree.includes(l) on 22.3.1 still returns true if selected layer is on a top level tree, but 22.4.0 and 22.4.1 return false. My whole (payed) plugin is based on that selection and it doesn’t work anymore. Not cool at all :confused:

Any advice what would be the best approach to fix this? Or simply loop both arrays and check for layers IDs?

Thanks

P. S. Is this the best place to report such bugs?

Best I can tell, it’s a bug.

To work around the problem until it’s fixed, you could match the _id field instead (AFAIK, this should continue to work after it’s fixed too):

const activeLayers = doc.activeLayers.filter(l => doc.layerTree.some(c => c._id === l._id));

FYI @Barkin / @heewoo / @samgannaway – Looks like a bug in the layer map cache. AFAICT, a new Layer object is always being created, rather than the old one being re-used if it exists. (Check src/dom/Layer.ts#PSLayer’s history – there’s a change around 3mo ago that may be involved – Pull #118)

1 Like

Not sure if related, but I feel like I’m getting cached active layer results.

const app = require('photoshop').app;
const photoshop = require('photoshop');
const currentDocument = app.activeDocument
const layers = currentDocument.layers;
const currentLayer = layers[0];

document.getElementById("gritEffectsBtn").addEventListener("click", showlayerkind);

function showlayerkind() {
    app.showAlert(currentLayer.kind);
}

Always returns the same result as first time this is run with the button click.

So if active layer is a smartObject the next time the function is run, it will continue to return smartObject, even tho it’s a pixel layer.

I believe it’s not related at all. Your function always returns the kind of the first layer and not the active layer

1 Like

I wouldn’t trust such a way of comparison. I would rather always use id or create some designed methods to compare.

Yeah, I don’t think I still have such comparisons on my plugins. It was a year ago when I just started digging into UXP :slight_smile: