Re: Collection List Metafields unexpected behavior - output in the wrong order.

Collection List Metafields unexpected behavior - output in the wrong order.

Shopify Partner
13 0 7

Hi everyone, I found a strange issue to do with metafields. My code is very simple so I think it's an actual Shopify bug. 

If any experienced devs can have a look, especially anyone from Shopify, I'd greatly appreciate it! 


Context: I want to create some 'fake' breadcrumbs on product pages by outputting a list of collections.


I have a product Metafield of the type "Collection (list)". 




I use a simple for loop to output each collection: 



{% assign parentsArray = product.metafields.custom.parent_collections.value %}

{% for coll in parentsArray %}
    {{ coll.title }}  
{% endfor %}



This works fine most of the time. The correct order of the output would be: 
1. All products
2. Winter
3. Snowboards



The bug:

The bug occurs when visiting a product through a collection-aware URL. 


A collection-aware URL is a product URL that has the collections/collection-title part of the URL.


For example /collections/snowboards/products/the-collection-snowboard-liquid


Dawn does not use collection-aware URLs anymore, but many other themes do.
To test in Dawn you need to add the collection part to the URL manually. 

When visiting through a collection-aware URL, the order of the list is changed. It puts the collection I'm currently visiting at the beginning. 


demo store.jpg


The bug is inconsistent. Sometimes it doesn't happen, and it can be fixed by refreshing enough times. You need to use an incognito window to replicate it again.




Demo store (pass: 123)

Reply 1 (1)

Shopify Partner
1 0 0

It's the same when using a collection metafield of the type "Collection (list)," which is even more problematic because you can't avoid having the collection in the URL. It consistently occurs only on the first load that the collection in the URL appears first in the list. After refreshing, the order corrects itself. Could someone from Shopify please look into this?