handlebars-lang / handlebars-lang/handlebars.js

Retain compilation runtime when registering precompiled partials

Open
#2,095 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
18.7k
Forks
2.1k
PR merge metrics
No merged PRs in 30d

Description

I am trying to write template modules, where a javascript module exports a template function. Ideally, each template module would be isolated so as to neither affect, nor be affected by the other handlebars runtimes (`handlebars.noConflict().create()`). Different templates could depend on different versions of a helper with the same name without stepping on each other. Each template module should also handle registering any helpers/partials it needs.

For simple templates, this can be done with no modification to how handlebars currently works. However, if a template requires a partial, and that partial requires other resources such as a helper, it stops working. I compile the partial template in its own runtime, with needed helpers already registered to that runtime. But when that partial template is registered in a second runtime, templates created in that runtime fail when they try to use the partial due to missing helpers.

I suspect that the runtime of the template being executed overwrites the runtime of the compiled partial and that is why it fails with helper not found.

Is it possible that partials could be tweaked to retain their compilation runtime? Or that an option could be added to allow that to happen?

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the failure with handlebars.noConflict().create(), isolated runtimes, a precompiled partial, and a helper dependency. Trace partial registration and execution to determine how the compilation runtime is replaced. Done means the intended runtime isolation works and helpers required by a precompiled partial remain available when it is used.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
web-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.