-
-
Notifications
You must be signed in to change notification settings - Fork 10k
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
Jekyll 4.0 gets confused about page variables #7811
Comments
Hi. We recently upgraded our site to Jekyll 4.0 and just noticed a new behaviour that seems to match what is described here. Very roughly, we have a "project" attribute for all pages except the home, that gets |
Thank you reporting this guys. I think it'll be easier to debug if one of you provided a sample repository that I could just clone and run.. (and hopefully it being light-weight as well..) |
Our repo is quite huge at the moment, but if @kvz's one is also big I'll try to reproduce the problem in a small subset of it. Thanks for looking at this. |
i wonder who wins? :) |
@kvz it could be just a bunch of big JPEGs :P |
I'll try to create a small version of our repo over the coming days... |
@ashmaroli I created a small repo reproducing this issue. The repo (dcabo/jekyll-4-issue-7811) is private because the original one was so, although I think I got rid of most of the private stuff. You should have got an invitation. If it being private is a nuisance let me know, I can probably take a closer look and make it public. The steps to reproduce the issue are detailed in Any question, please let me know. |
@dcabo Thank you very much for providing the test repo. The source of this issue is at: jekyll/lib/jekyll/liquid_renderer/file.rb Line 13 in 9f389e0
If you're building your site locally and are comfortable with the Gem environment in your system, then you may make the following change within your gem itself. Otherwise, the best alternative is to make the change in a temporary branch on your fork of the Jekyll repo and point your site's Gemfile to that branch. - @renderer.cache[@filename] ||= Liquid::Template.parse(content, :line_numbers => true)
+ @renderer.cache[@filename] = Liquid::Template.parse(content, :line_numbers => true) # Gemfile
gem "jekyll", github: "dcabo/jekyll", branch: "patch-7811" Once I can come up with a solution to disable the Liquid cache via the config file and open a PR, you (and others affected) can elect to point to that PR's branch until v4.1 ships. Wish this issue had surfaced while we were still in the beta phase.. The inconvenience caused is deeply regretted. |
@ashmaroli happy to help, and no worries, bugs happen. 🤷♂ I have a workaround working where I set the variable in all cases, just as you proposed in my repo, but thanks for the suggestion on how to fix the gem. |
Seeing as how this bug might be silently breaking a lot of sites, and has apparently such a simple fix, wouldn't it be good to ship the fix in a 4.0.1 patch release? 4.1 seems ambitious, so I'm guessing it might still take a while. I already followed @ashmaroli's advice and implemented the fix in a fork of Jekyll:
The problem with that solution is that Netlify won't cache the Jekyll version, so it has to build from source for every deploy — negating any of Jekyll 4's performance improvements and eating up precious build minutes. |
@letrastudio We can't ship the workaround immediately because if Liquid templates are no longer cached, the build times will increase significantly. |
Ah, gotcha. So this isn't a real fix, just a temporary workaround with a performance tradeoff?
|
Yep. It is a workaround for those who can't adjust their layouts / includes within to get around the issue... |
I have slightly different example of this issue causing a problem in case it helps anyone else. I am writing a custom plugin and the plugin loops through some data creating instances of one of two Ruby classes that inherit from
(The above is based on the second example given in the documentation here: https://jekyllrb.com/docs/plugins/generators/) However, when the plugin runs, the second set of pages will use the _layout file specified in the Class that was instantiated first in the code even though a different _layout file is specified in the initialize function of the second class. If I comment out the code that creates the first set of pages then the layout for the second set is used correctly. This issue is also fixed by making the temporary change @ashmaroli suggested in Sept. |
@kierenpitts Is your plugin open-source? If yes, I'd like to take a look at it. |
@ashmaroli It's very much a work in progress (and somewhat niche for a site I'm working on) but I can try and create a small example of the issue for you. Basically the _layout specified in one Class seems to be leaking into the second even though it is declared a second time. It could be I'm doing something daft but making the change you suggested in Sept does fix the issue too. |
That would be great. I just need to see how caching Liquid is affecting data from front matter.. |
Hi @ashmaroli I've created a small Jekyll site with a custom plugin that demonstrates the problem: I've put some info in the README but there's more in the /index.html that the site generates. I'm fairly new to Jekyll (and Ruby; I generally write Python) so this could easily be something that I'm doing wrong. However, I can't immediately see why the two different page types end up using the same layout file when different ones are specified in the custom plugin - the code works fine if I make the same change as you suggested above. Hope this helps. |
@kierenpitts Thank you for providing the repository and plugin code. |
@ashmaroli Thanks for the reply. Is the cache keyed on the |
@kierenpitts Yes, the cache is keyed on the In your test-plugin's case, the content attribute of your Page subclasses are dynamically injected for the same
|
@ashmaroli Thank you for the clarification and the suggestion. As you said, adding in a unique
In terms of the cache, and thinking that this sort of key clash might be really hard for people to track down (especially if using several generator plugins that work fine in isolation but cause a clash when running together), would it be worth having the cache generate a fake but functionally unique Thank you for the help with resolving the issue in my plugin, it's much appreciated. |
Not really sure about this, but I think this could be a bug with Liquid (or just its require 'liquid'
CONTENTS = <<~TEXT
Neo: "I am just {{ title | default: 'a regular guy' }}.."
{%- if agent == ' Smith' %}{% assign title = 'A DISEASE' %}{% endif %}
{{ agent }}: "Neo, you're {{ title | default: 'The One' }}!!"
TEXT
TEMPLATE = Liquid::Template.parse(CONTENTS)
puts TEMPLATE.render("agent" => "Morpheus")
puts TEMPLATE.render("agent" => " Trinity")
puts TEMPLATE.render("agent" => " Oracle")
puts TEMPLATE.render("agent" => " Trinity")
puts TEMPLATE.render("agent" => " Smith")
puts TEMPLATE.render("agent" => " Oracle")
puts TEMPLATE.render("agent" => " Trinity")
puts TEMPLATE.render("agent" => "Morpheus") ...outputs the following:
|
Isn't |
The upgrade to Jekyll 4 introduced the caching. The caching in turn simulated the behavior of the Ruby script above (i.e. 1 |
@kvz, @dcabo I've opened a pull request that should effectively resolve this issue. # Gemfile
gem "jekyll", git: "https://github.com/jekyll/jekyll.git", ref: "refs/pull/7967/head" Thank you. |
I'm using Jekyll through a custom docker image and I've tried many times, but failed to add custom gems to it through a Gemfile so I'm afraid this is going to be too tricky to test for me 🙀 |
@ashmaroli I've tested your branch and the problem appears fixed on my end — no side effects that I could see in a diff of my _site folder. And in terms of performance, it's even faster than 4.0.0 — I'm getting build times of around 17-19 seconds instead of 25-29. I don't know whether that optimization comes from this change or some other post-4.0.0 code, but big thumbs up from me! 👍 |
@letrastudio Thank you for the feedback. Happy to know there are no discernible side-effects from the proposed change. |
@ashmaroli I rebuilt my site using your branch, and the output looks fine: no differences in So it all looks fine, thanks. Is this going into a new release soon? Because I'm tempted to use your branch in production straight away, given the performance improvements. |
Thank you for the feedback @dcabo. Hopefully, the pull request would get merged into |
I think I've found an edge case where there's still a problem. @sverrirs just released a 3.0.0 version of @ashmaroli I know this might be a bug in
The problem I'm seeing is the I've published a public repo with a trimmed-down version of my site that reproduces this bug. I hope it helps to diagnose this issue. The repo's README includes more details and a |
@letrastudio Thank you reporting the new find and for the test-repo. I shall look into this discovery in the coming days. |
@letrastudio I've looked into the issue and have come to the conclusion that the bug is indeed within Therefore, the fix for this is to simply allot a unique |
Hi, congrats on launching Jekyll 4! Very much enjoying the speed boost.
While upgrading our site, I was syncing
_site
to a local empty git repo to diff changes. One thing I noticed, was that Jekyll seems to leak variables between pages.Here's code I had in my default layout:
Now some pages would set
sidebarInclude: about
to indicate they'd like to have the 'about sidebar' included by the default layout.After upgrading to 4.0, pages that didn't want the about sidebar loaded, got one anyway, until I added these two lines at the top:
It would appear that maybe caching makes variable scope leak over to different pages(?). This is what my very limited understanding from Jekyll/Ruby would lead me to believe, but it could be something else entirely.
The text was updated successfully, but these errors were encountered: