Why did the Liquid array .size function stop working in my customized theme?

Topic summary

A developer encountered an issue where the .size function on Shopify Liquid metafield arrays suddenly stopped working, returning null instead of the expected count, despite the arrays containing valid data. The code had been functioning correctly for months before breaking without any changes to the theme or product metadata.

Key Points:

  • The problem appeared intermittently and seemed to resolve itself temporarily, mirroring similar issues reported as far back as 2019
  • Multiple users confirmed experiencing the same frustrating behavior where arrays visibly contain items but .size returns zero

Working Solutions:

  • Use .count instead of .size (most recommended fix)
  • Convert metafields to arrays using split filter: {% assign list = product.metafields.namespace.key | split: ',' %}
  • Manually count items by looping through and incrementing a counter variable

Community Frustration:
Users expressed significant frustration that .count works reliably but isn’t documented in Shopify’s official Liquid API documentation, while .size is documented but apparently unreliable. The issue has persisted since at least 2021 without official acknowledgment or documentation updates from Shopify.

Summarized with AI on October 26. AI used: claude-sonnet-4-5-20250929.

It happened again! I’m going totally crazy! I can see the array has multiple items by console logging it, but when using the filter SIZE or looping through the items it prints ZERO or acts as if it has ZERO items to loop through!

1 Like