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

assets_include works intermittently in imported file #177

Open
rsyring opened this issue Sep 17, 2021 · 1 comment
Open

assets_include works intermittently in imported file #177

rsyring opened this issue Sep 17, 2021 · 1 comment

Comments

@rsyring
Copy link
Member

rsyring commented Sep 17, 2021

My template landing.html started like:

{% set title = space.name + ' Collaborative' %}
{% import '_resources.html' as res_macros %}
{% extends "collab-base-sidebar.html" %}
  • _resources.html had some macros that were used and assets_include at the top of it
  • _resources.css had some css that was needed by the macros

I observed that the content from _resources.css only made it into the page immediately after saving landing.html, presumably due to the process/server restart triggered by the file modification. On subsequent browser refreshes, the content was absent.

@guruofgentoo
Copy link
Member

The reason this happens is due to Jinja caching imports:

  • The first time the import is referenced, Jinja will parse the target template file.
  • Our extension turns the assets_include on that first parse into a call block that will produce the expected content
  • After that first load, Jinja caches the import and doesn't parse it again. But, I think what Jinja caches is the original template, not the version where we've patched in a call block
  • Since it's cached at that point and not parsed again, we don't get to re-insert that call block and pull in the assets files

Not sure there's a clean way around this without coming up with a way to change how Jinja caches the import, or using a different approach to assets inclusion altogether.

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

No branches or pull requests

2 participants