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

eleventyComputed property with pagination is computed with empty data #2837

Closed
souserge opened this issue Mar 2, 2023 · 7 comments
Closed
Labels
bug feature: 🧮 computed data Related to Eleventy’s Computed Data feature

Comments

@souserge
Copy link

souserge commented Mar 2, 2023

Operating system

Fedora Linux 37 (Workstation edition)

Eleventy

2.0.0

Describe the bug

I stumbled across a weird issue that occurred only in one of the computed properties I defined in an 11data.js directory data file. That property depended on another computed property. I have a few such dependencies, but in this particular one, the function received an empty data property and thus it would fail to compute a transormation of another computed property and the build would fail.

After a bit of debugging, I discovered that it occurs when the permalink is set dynamically and reading the debug output, I saw that there is a "ghost" render of the template:

Eleventy:Template Rendering permalink for './test/index.njk': (((11ty(((permalink)))11ty))) becomes '(((11ty(((permalink)))11ty)))'

I ended up creating (what I think is) a minimal test case project where the same problem occurs. It's available here:
https://github.com/souserge/11ty-permalink-issue-example

The issue occurs in the test/test.11tydata.js file. The relevant bit is pasted below:

// pageData comes from pagination in the nunjucks template (test/index.njk)
module.exports = {
  eleventyComputed: {
    permalink: (data) => `/${data.pageData.name}/`,
    nestedDoubleName: (data) => ({ name: data.pageData.name + data.pageData.name }),
    computedProp: (data) => {
      const { nestedDoubleName } = data;
      return nestedDoubleName.name.toUpperCase(); // Error occurs here
    }
  }
}

Reproduction steps

  1. Clone the project
  2. Install dependencies
  3. Run DEBUG="Eleventy*" npx @11ty/eleventy

Expected behavior

The page isn't rendered without the data being available for computed properties

Reproduction URL

https://github.com/souserge/11ty-permalink-issue-example

Screenshots

image

@zachleat zachleat added the feature: 🧮 computed data Related to Eleventy’s Computed Data feature label Mar 21, 2023
@AleksandrHovhannisyan
Copy link
Contributor

Could this be related to #2240?

@souserge
Copy link
Author

@AleksandrHovhannisyan yes, I think that's what happens here too.

@Anemolo
Copy link

Anemolo commented Jul 20, 2023

Stumbuled into this issue after updating to 2.0.1. This used to work on "2.0.0-canary.8", so I'm staying on that version. In my case, I've noticed it happens when using pagination + Permalink:

_data/renders.js

module.exports = [
	{
		title: "one",
	},
	{
		title: "two",
	},
	{
		title: "three",
	}
]

And then content/key.njk won't work in this case

---
key: My Key
pagination:
  data: renders
  alias: issueData
  size: 1
permalink: "/key/{{issueData.title}}"
eleventyComputed:
  key: "This Is {{key}}"
---

{{key}}

But it will work with this setup `content/key.njk``:

---
key: My Key
eleventyComputed:
  key: "This Is {{key}}"
---
{{key}}

@alifeee
Copy link
Contributor

alifeee commented Dec 10, 2023

Hi all, this is specifically a problem with nunjucks. If you change your templates to liquid, md, handlebars, etc... it will work properly and eleventyComputed values will be computed

more info -> #3120

@AleksandrHovhannisyan
Copy link
Contributor

@alifeee OP's example is a JavaScript data file, as are the examples in #2240. So I think it's an issue in the data pipeline and not necessarily with the templating languages themselves.

@alifeee
Copy link
Contributor

alifeee commented Dec 10, 2023

@alifeee OP's example is a JavaScript data file, as are the examples in #2240. So I think it's an issue in the data pipeline and not necessarily with the templating languages themselves.

Ah, you're right. I was perhaps a bit brash thinking "pagination" and "eleventyComputed" would be the same issue as mine.

for this case, the error is raised when eleventy tries to figure out what variables you use in your function (here), so it does some weird proxy stuff (here) which fails because as you say, on the first pass the data object is empty. I hope this can be figured out. Thanks.

@zachleat zachleat added bug and removed needs-triage labels Jun 10, 2024
@zachleat
Copy link
Member

Let’s group up over at #2240!

For the Nunjucks issue, note that #3120 was merged and shipping with 3.0.0-alpha.11. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug feature: 🧮 computed data Related to Eleventy’s Computed Data feature
Projects
None yet
Development

No branches or pull requests

5 participants