Rel="next" / rel="prev" missing from content_for_header when another paginate runs before the collection's

Short description of issue

On collection pages, the rel="next" / rel="prev" link tags injected in content_for_header disappear when another paginate tag (e.g. on a metaobject list) runs before the collection’s paginate. Moving it after the collection’s paginate restores them.

Reproduction steps

  1. Use a collection with more than one page of products, paginated in the main collection section:
{%- paginate collection.products by 24 -%}
  ...
{%- endpaginate -%}
  1. Check the page source: <link rel="next" href="/collections/xxx?page=2"> is present in content_for_header. :white_check_mark:

  2. In the same section, add a paginate on a metaobject list BEFORE the collection paginate:

{%- paginate metaobjects.stores.values by metaobjects.stores.values.count -%}
  {%- assign store = metaobjects.stores.values | find: 'some_field', filter_value.label -%}
{%- endpaginate -%}
  1. Reload: <link rel="next"> / <link rel="prev"> are no longer injected. :cross_mark:

  2. Move that same paginate block AFTER the collection’s {% endpaginate %}: the tags are injected again. :white_check_mark:

Additional info

Using paginate on metaobjects is the standard workaround to access more than 50 entries in Liquid. When it runs before the product grid, the collection’s pagination link tags silently disappear.

It looks like content_for_header relies on the first paginate executed during the render, not on the one wrapping the template’s main resource.

We only tested this on collections, but the same behavior probably applies to other paginated resources (blog.articles, search.results).

Expected: the pagination link tags should reflect the paginate of the template’s main resource (collection.products on a collection page), regardless of other paginate tags executed before it.

Questions:

  • Is this the intended behavior? If so, could it be documented in the paginate (Liquid tags: paginate) or content_for_header (Liquid objects: content_for_header) docs?
  • Is there a recommended way to access more than 50 metaobject entries without affecting the pagination tags?

What type of topic is this

Bug report