From 15c6de26401c9b6c9a3695b3445061a3d92fb146 Mon Sep 17 00:00:00 2001 From: Khaleel Al-Adhami Date: Wed, 6 Nov 2024 13:26:35 -0800 Subject: [PATCH] fix call_function events sent from backend --- reflex/.templates/web/utils/state.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/reflex/.templates/web/utils/state.js b/reflex/.templates/web/utils/state.js index 66df09ee11..3899ddc893 100644 --- a/reflex/.templates/web/utils/state.js +++ b/reflex/.templates/web/utils/state.js @@ -238,7 +238,10 @@ export const applyEvent = async (event, socket) => { return false; } - if (event.name == "_call_function") { + if ( + event.name == "_call_function" && + typeof event.payload.function !== "string" + ) { try { const eval_result = event.payload.function(); if (event.payload.callback) { @@ -257,9 +260,13 @@ export const applyEvent = async (event, socket) => { return false; } - if (event.name == "_call_script") { + if (event.name == "_call_script" || event.name == "_call_function") { try { - const eval_result = eval(event.payload.javascript_code); + const eval_result = + event.name == "_call_script" + ? eval(event.payload.javascript_code) + : eval(event.payload.function)(); + if (event.payload.callback) { if (!!eval_result && typeof eval_result.then === "function") { eval(event.payload.callback)(await eval_result);