-
-
Notifications
You must be signed in to change notification settings - Fork 21
Open
Description
When integrating Jinjax with an existing Jinja2 Environment (per the “Reusing an existing Jinja environment” guide), the new “defer rendering of collected assets” feature is not applied. This integration path renders templates via template.render()
, which bypasses catalog.render()
and therefore skips the asset finalization step.
Steps to Reproduce
- Set up Jinjax with an existing jinja2.Environment
- Render a template via template.render(context).
- Use components that enqueue assets expecting deferred rendering/finalization.
Expected
Deferred assets are collected and injected/finalized in the rendered HTML, as when using catalog.render().
Actual
Asset finalization doesn’t happen; the rendered HTML include a place holder "@@jinjax_assets_....@@".
Workaround
Call the private finalization helper directly on the produced HTML before returning it:
# after calling template.render(...)
html = template.render(context)
# Workaround: finalize assets manually
# NOTE: This is a private API and may change without notice.
html = catalog._finalize_assets(html)
return html
Notes
The underscore suggests `_finalize_assets` is private, so relying on it feels brittle.
There doesn’t seem to be a public way to finalize assets when using an external Jinja2 environment.
Suggestions
- Documentation: Explicitly mention that when reusing an existing Jinja2 Environment, defer rendering requires a manual finalization step because
template.render()
bypassescatalog.render()
. Provide an example using a supported/public API (see next point). - API: Expose a public method to finalize assets, e.g.
catalog.finalize_assets(html)
- Guide Update: In “Reusing an existing Jinja environment,” add a section “Defer rendering of collected assets” with a recommended pattern, for example:
template = env.get_template("page.html")
html = template.render(context)
# Recommended public API (hypothetical)
html = catalog.finalize_assets(html)
return html
Metadata
Metadata
Assignees
Labels
No labels