-
-
Notifications
You must be signed in to change notification settings - Fork 495
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 not computed in the necessary order #973
Comments
Howdy! This report actually resulted in a fairly large refactor of the computed data feature, The fix for this will ship with 0.11.0-beta.4 and I would really appreciate it if you retested after that was released! Thank you! |
Cool! I had been looking forward to it, thanks a lot for looking into it :D I had a quick go on the test repository with the current master branch. Unfortunately, the order is still the same. One thing I noticed is that if I add a Is there a limitation of the number of computed properties another computed property can depend on? |
Ah just to be clear and re-update here, work was done again ~3 days ago 😅 #1098 (comment) |
Argh, it looks like it didn't fix it. I did another test with the latest commit on master and the behaviour remains the same 😞 I had a look inside Eleventy and I think what's breaking could be the fact that the computed data has an eleventy/src/ComputedDataProxy.js Line 76 in 1fd4f02
if (data.locale) in my computed property would evaluate to false (as it's computed) and the code never goes through the data.key inside the if block.
If it's that, I think it'll be tricky to work around. Parsing the function code with Acorn and looking at the AST came to mind, but:
Personally, I'd be fine with declaring which other keys the data depends on if that's all that allows having computed properties derived from computed properties: //...
eleventyComputed: {
permalink: ['locale', 'key',(data) => { /* ... */}]
}
//... |
Sounds like the most pragmatic solution 😄 It's only for variables used in branches that wouldn't be run through when checking the variables dependencies anyways. Might be worth putting the debug info you showed in the screenshot under Eleventy cannot spot which computed data is used inside // _data/eleventyComputed.js
module.exports = {
permalink: function(data) {
if (data.locale) {
// Eleventy will not see computed data in this block
return `${data.locale}/{data.key}`;
}
}
locale: function(data) {
return data.page.filePathStem.split('--')[1] || data.defaultLocale;
}
key: function(data) {
return data.page.filePathStem.split('--')[0];
}
} If it looks like one of your computed data doesn't get computed after one it depends on, you can run Eleventy with DEBUG=Eleventy:computedData npx @11ty/eleventy You can then add calls to each of the missing keys before any module.exports = {
permalink: function(data) {
// This will make Eleventy pick up that `permalink`
// depends on `key`
data.key;
if (data.locale) {
return `${data.locale}/{data.key}`;
}
}
locale: function(data) {
return data.page.filePathStem.split('--')[1] || data.defaultLocale;
}
key: function(data) {
return data.page.filePathStem.split('--')[0];
}
} That would be a good enough troubleshooting experience for me, I think. |
Added a section to the docs for this https://www.11ty.dev/docs/data-computed/#declaring-your-dependencies Happy to entertain some PRs to that doc with improvements! |
Nice! The doc reads pretty clear to me. Thanks for sorting it all out 🙇 |
Describe the bug
Hello,
I'm trying to use Eleventy for a multilingual site, using file extensions to set the locale (rather than a separate folder). I need to set 3 properties in this order:
locale
read from the file pathkey
to match translated contentpermalink
derived from thekey
and thelocale
The computation of the data happens in the wrong order and the
permalink
gets computed before thekey
, leading toundefined
being set in the path.To Reproduce
I've created a repo to reproduce : https://github.com/rhumaric/eleventy-computed-property-order-issue
If you run
npx @11ty/eleventy
, you'll notice the 'generating permalink' happens before the 'Setting key test'.There's also some weird logs happening ahead of it, similar to those on #971
Expected behavior
I'd have expected Eleventy to detect that
permalink
depended on thekey
, as announced in the documentation.Environment:
The text was updated successfully, but these errors were encountered: