Skip to content

Collections API seems to be broken in Eleventy 3.1.0 or later #4182

@sentience

Description

@sentience

Operating system

macOS Tahoe 26.1

Eleventy

3.1.2

Describe the bug

I use the Collections API in my Eleventy config to create a primaryNav collection that contains all pages of my site with the primary tag set:

  // Sort nav bar collections
  console.log("Adding collection 'primaryNav' for tag 'primary'");
  eleventyConfig.addCollection("primaryNav", (collectionsApi) =>
    collectionsApi
      .getFilteredByTag("primary")
      .sort((pageA, pageB) => pageA.data.order - pageB.data.order);
  );

This works fine up to Eleventy 3.0.0, but in 3.1.x collectionsApi.getFilteredByTag("primary") always returns an empty array. In my debugging, I have also confirmed that collectionsApi.getAll() likewise always returns an empty array.

Reproduction Source Code URL

https://github.com/sentience/eleventy-collections-api-issue

Contains this version of the code with debug output (see below):

  // Sort nav bar collections
  console.log("Adding collection 'primaryNav' for tag 'primary'");
  eleventyConfig.addCollection("primaryNav", (collectionsApi) => {
    console.log(
      "DEBUG collectionsApi.getAll().length: ",
      collectionsApi.getAll().length,
    );
    return collectionsApi
      .getFilteredByTag("primary")
      .sort((pageA, pageB) => pageA.data.order - pageB.data.order);
  });

Screenshots

Build output with Eleventy 3.0.0:

Adding collection 'primaryNav' for tag 'primary'
DEBUG collectionsApi.getAll().length:  0
DEBUG collectionsApi.getAll().length:  2
[11ty] Writing ./_site/index.html from ./index.liquid
[11ty] Writing ./_site/about/index.html from ./about.liquid
[11ty] Copied 11 Wrote 2 files in 0.10 seconds (v3.0.0)

Build output with Eleventy 3.1.2:

Adding collection 'primaryNav' for tag 'primary'
DEBUG collectionsApi.getAll().length:  0
[11ty] Writing ./_site/about/index.html from ./about.liquid
[11ty] Writing ./_site/index.html from ./index.liquid
[11ty] Copied 11 Wrote 2 files in 0.11 seconds (v3.1.2)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions