Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Computed data: Cannot read property 'filter' of undefined #1098

Closed
paulrobertlloyd opened this issue Apr 14, 2020 · 2 comments
Closed

Computed data: Cannot read property 'filter' of undefined #1098

paulrobertlloyd opened this issue Apr 14, 2020 · 2 comments
Assignees
Labels

Comments

@paulrobertlloyd
Copy link
Contributor

Describe the bug
This is in relation to the change in #973, which now has my computed data throwing an error. This might by okay – maybe what I’m trying to achieve isn’t possible – but thought it was worth flagging all the same.

I have the following computed data in a directory data file, that I use to find article posts related to a given project (which I do using a category frontmatter key; if an article has a category value that is the same as a projects title, it’s deemed to be related):

module.exports = {
  layout: 'project',
  permalink: 'projects/{{ page.fileSlug }}/',
  eleventyComputed: {
    related: data => {
      const articles = data.collections.article;
      return articles.filter(article => {
        const {category} = article.data;
        if (!category) {
          return false;
        }

        return category.includes(data.title);
      });
    }
  }
};

However, I now get the following error:

Problem writing Eleventy templates: (more in DEBUG output)
> Cannot read property 'filter' of undefined

Is 11ty no longer aware of the global data object at this point in the cascade? I was getting this error intermittently before, so I guess having it be persistent is an improvement, of sorts 😉

Additional context

@zachleat
Copy link
Member

Can you retest with the new version on GitHub? I think I boggled how computed data treats arrays last weekend, hoping it’s patched now. If not I’ll dive in deeper here before 0.11 ships

@zachleat zachleat added bug and removed needs-triage labels Apr 20, 2020
@zachleat zachleat self-assigned this Apr 20, 2020
@zachleat zachleat added this to the Eleventy v0.11.0 milestone Apr 20, 2020
@paulrobertlloyd
Copy link
Contributor Author

Yep, this appears fixed. Thanks @zachleat!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants