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

**URL:** https://forums.creativeclouddeveloper.com/t/bug-22-4-layer-references-do-not-match-same-layers-from-different-arrays/3032
**Category:** UXP Plugin API
**Tags:** bug, javascript
**Created:** [June 4, 2021, 12:53pm UTC](https://forums.creativeclouddeveloper.com/t/bug-22-4-layer-references-do-not-match-same-layers-from-different-arrays/3032 "2021-06-04T12:53:37Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Karmalakas](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/karmalakas/32/1048_2.png) [@Karmalakas](https://forums.creativeclouddeveloper.com/u/Karmalakas)
#### Post date: [June 4, 2021, 12:53pm UTC](https://forums.creativeclouddeveloper.com/t/bug-22-4-layer-references-do-not-match-same-layers-from-different-arrays/3032/1 "2021-06-04T12:53:37Z")

</div>

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

Here’s a simple snippet:

```auto
    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 😕

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?

---

<div class="post-metadata">

### Author: ![kerrishotts](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/kerrishotts/32/8_2.png) [@kerrishotts](https://forums.creativeclouddeveloper.com/u/kerrishotts)
#### Post date: [June 4, 2021, 11:22pm UTC](https://forums.creativeclouddeveloper.com/t/bug-22-4-layer-references-do-not-match-same-layers-from-different-arrays/3032/2 "2021-06-04T23:22:17Z")

</div>

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):

```auto
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)

---

<div class="post-metadata">

### Author: ![Blaz](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/blaz/32/2162_2.png) [@Blaz](https://forums.creativeclouddeveloper.com/u/Blaz)
#### Post date: [May 26, 2022, 1:53am UTC](https://forums.creativeclouddeveloper.com/t/bug-22-4-layer-references-do-not-match-same-layers-from-different-arrays/3032/3 "2022-05-26T01:53:43Z")

</div>

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

```auto
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.

---

<div class="post-metadata">

### Author: ![Karmalakas](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/karmalakas/32/1048_2.png) [@Karmalakas](https://forums.creativeclouddeveloper.com/u/Karmalakas)
#### Post date: [May 26, 2022, 6:23am UTC](https://forums.creativeclouddeveloper.com/t/bug-22-4-layer-references-do-not-match-same-layers-from-different-arrays/3032/4 "2022-05-26T06:23:11Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Jarda](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/jarda/32/1909_2.png) [@Jarda](https://forums.creativeclouddeveloper.com/u/Jarda)
#### Post date: [May 26, 2022, 11:59am UTC](https://forums.creativeclouddeveloper.com/t/bug-22-4-layer-references-do-not-match-same-layers-from-different-arrays/3032/5 "2022-05-26T11:59:26Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Karmalakas](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/karmalakas/32/1048_2.png) [@Karmalakas](https://forums.creativeclouddeveloper.com/u/Karmalakas)
#### Post date: [May 26, 2022, 12:01pm UTC](https://forums.creativeclouddeveloper.com/t/bug-22-4-layer-references-do-not-match-same-layers-from-different-arrays/3032/6 "2022-05-26T12:01:10Z")

</div>

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 🙂
