From 08de4bed6f53479bf76b8482706fb3df1ae73647 Mon Sep 17 00:00:00 2001 From: Michael Bleigh Date: Thu, 8 Aug 2024 19:20:05 -0700 Subject: [PATCH] Persist Handlebars in global to keep it through HMR. Fixes #744 (#762) --- js/plugins/dotprompt/src/template.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/js/plugins/dotprompt/src/template.ts b/js/plugins/dotprompt/src/template.ts index 7ff16f78f..020f9fad9 100644 --- a/js/plugins/dotprompt/src/template.ts +++ b/js/plugins/dotprompt/src/template.ts @@ -19,7 +19,9 @@ import { DocumentData } from '@genkit-ai/ai/retriever'; import Handlebars from 'handlebars'; import { PromptMetadata } from './metadata.js'; -const Promptbars = Handlebars.create(); +const Promptbars: typeof Handlebars = + global['dotprompt.handlebars'] || Handlebars.create(); +global['dotprompt.handlebars'] = Promptbars; function jsonHelper(serializable: any, options: { hash: { indent?: number } }) { return new Promptbars.SafeString(