From cdad301e7e39fd3d0258a5c5b79802d0cd768143 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 20 Feb 2024 11:52:56 +0100 Subject: [PATCH] Undefined checks for context --- packages/server/src/jsRunner/index.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/server/src/jsRunner/index.ts b/packages/server/src/jsRunner/index.ts index 3c13aef1d4..5db461e023 100644 --- a/packages/server/src/jsRunner/index.ts +++ b/packages/server/src/jsRunner/index.ts @@ -21,9 +21,9 @@ export function init() { } try { - const bbCtx = context.getCurrentContext()! + const bbCtx = context.getCurrentContext() - let { vm } = bbCtx + let vm = bbCtx?.vm if (!vm) { // Can't copy the native helpers into the isolate. We just ignore them as they are handled properly from the helpersSource const { helpers, ...ctxToPass } = ctx @@ -36,7 +36,10 @@ export function init() { .withContext(ctxToPass) .withHelpers() - bbCtx.vm = vm + if (bbCtx) { + // If we have a context, we want to persist it to reuse the isolate + bbCtx.vm = vm + } } return vm.execute(js) } catch (error: any) {