Fix pagination and eleventy computed for .njk
engine
#3120
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
closes #2512, #2837, #3013
Introduction
Hi, I hope you are well.
There is a problem where if you use a Nunjucks and a template file like
All
eleventyComputed
variables are blank. See #2512, #2837, #3013 for discussion.This problem was introduced by c6158b0, a commit between
2.0.0-canary.8
and2.0.0-canary.9
.New test
I have added a test which fails:
https://github.com/alifeee/eleventy/blob/301d2c09d76a6bc717a0a8ceda37a1bdb7cdbb42/test/PaginationTest.js#L833-L863
here is a simplification (in the actual test, it tests all templating languages)
Result
This test failed
The fix
I spent some time commiting c6158b0 bit-by-bit and the fix i discovered was this:
I am not fully sure why this is the fix, but I think it is to do with being able to set the
data.eleventyComputed
on a Proxy object.If you re-add this removed code from c6158b0, then, compiling a template complains as the object cannot be assigned unless
set
exists as a property above. Thus, this is the fix I implemented with alifeee@301d2c0And now the test passes
Thank you for your time. I hope this is the correct branch to target with this change.