"[object Promise]" output when Handlebars helper returns a Promise
0 reputation · 19 Sept 2021, 20:29 UTC
Handlebars synchronous rendering limitation
The goal is to allow a host application to cancel or time‑out a Handlebars template render without producing incomplete or corrupted output.
Handlebars compiles and executes templates synchronously; helpers must return a value immediately. If a helper returns a Promise, the rendered output contains the literal string "[object Promise]". Throwing an error inside a helper propagates the exception, but there is no built‑in abort signal or timeout parameter to stop the rendering of remaining template parts.
Because the library exposes no cancellation token and treats synchronous execution as a feature, it is unclear whether future versions should add async‑aware rendering or a mechanism to abort long‑running helpers.
- What mechanisms could be added to Handlebars to support cancellation tokens or timeouts?
- How could a timeout be enforced without leaving partial or "
[object Promise]" output? - Should helpers be permitted to return Promises that Handlebars awaits, and if so, how would error handling change?