From a07f04857c20ddd0a3f11cfed9b5c5462f90fa61 Mon Sep 17 00:00:00 2001 From: Hetu Nandu Date: Mon, 31 Mar 2025 12:55:29 +0530 Subject: [PATCH] fix: Avoid update of empty code from chat bot (#39974) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description Checks each field from the chat bot and only update that field instead of a bulk update. This should avoid scenarios where a bad bulk update could while the current user code in custom widget ## Automation /ok-to-test tags="@tag.Sanity" ### :mag: Cypress test results > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: > Commit: ec98ea0f3036f1950c978f5d475aed500167f60d > Cypress dashboard. > Tags: `@tag.Sanity` > Spec: >
Mon, 31 Mar 2025 07:16:11 UTC ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [ ] No ## Summary by CodeRabbit - **Refactor** - Streamlined the chatbot update process by switching from a bulk mechanism to individual, content-specific updates. - Ensured that each code segment (HTML, CSS, JS) is only updated when valid content is provided, enhancing overall reliability. --- .../Editor/ChatBot/ChatBot.tsx | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/app/client/src/pages/Editor/CustomWidgetBuilder/Editor/ChatBot/ChatBot.tsx b/app/client/src/pages/Editor/CustomWidgetBuilder/Editor/ChatBot/ChatBot.tsx index ae3c98e9c8..2e7ddec601 100644 --- a/app/client/src/pages/Editor/CustomWidgetBuilder/Editor/ChatBot/ChatBot.tsx +++ b/app/client/src/pages/Editor/CustomWidgetBuilder/Editor/ChatBot/ChatBot.tsx @@ -18,7 +18,7 @@ import { isObject } from "lodash"; export const ChatBot = (props: ContentProps) => { const ref = useRef(null); const lastUpdateFromBot = useRef(0); - const { bulkUpdate, parentEntityId, uncompiledSrcDoc, widgetId } = useContext( + const { parentEntityId, uncompiledSrcDoc, update, widgetId } = useContext( CustomWidgetBuilderContext, ); @@ -63,19 +63,20 @@ export const ChatBot = (props: ContentProps) => { return; } - if (!bulkUpdate) return; + if (!update) return; if (isObject(event.data)) { lastUpdateFromBot.current = Date.now(); + const { css_code, html_code, js_code } = event.data; - bulkUpdate({ - html: event.data.html_code || "", - css: event.data.css_code || "", - js: event.data.js_code || "", - }); + if (html_code && html_code !== "") update("html", html_code); + + if (css_code && css_code !== "") update("css", css_code); + + if (js_code && js_code !== "") update("js", js_code); } }, - [bulkUpdate, handleSrcDocUpdates], + [handleSrcDocUpdates, update], ); useEffect(