This is an automated email from the ASF dual-hosted git repository. EnxDev pushed a commit to branch test/chatbot-local in repository https://gitbox.apache.org/repos/asf/superset.git
commit 22d9332794bc3c63c081fa518380ce9a10cdfca6 Author: Enzo Martellucci <[email protected]> AuthorDate: Wed May 27 23:02:36 2026 +0200 fix(extensions): push settings payload through pub/sub to eliminate re-fetch delay on toggle Co-Authored-By: Claude Sonnet 4.6 <[email protected]> --- .../src/components/ChatbotMount/index.tsx | 21 ++++++++++++--------- superset-frontend/src/core/extensions/index.ts | 15 +++++++++++---- superset-frontend/src/extensions/ExtensionsList.tsx | 2 +- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/superset-frontend/src/components/ChatbotMount/index.tsx b/superset-frontend/src/components/ChatbotMount/index.tsx index 116e6743bfd..3eaec221741 100644 --- a/superset-frontend/src/components/ChatbotMount/index.tsx +++ b/superset-frontend/src/components/ChatbotMount/index.tsx @@ -39,15 +39,20 @@ const ChatbotMount = () => { const [adminSelectedId, setAdminSelectedId] = useState<string | null | undefined>(undefined); const [enabledMap, setEnabledMap] = useState<Record<string, boolean>>({}); - const fetchSettings = useCallback(() => { + const applySettings = useCallback( + (settings: { active_chatbot_id: string | null; enabled: Record<string, boolean> }) => { + setAdminSelectedId(settings.active_chatbot_id ?? null); + setEnabledMap(settings.enabled ?? {}); + }, + [], + ); + + useEffect(() => { let cancelled = false; SupersetClient.get({ endpoint: '/api/v1/extensions/settings' }) .then(({ json }) => { if (cancelled) return; - const id = json.result?.active_chatbot_id ?? null; - const enabled: Record<string, boolean> = json.result?.enabled ?? {}; - setAdminSelectedId(id); - setEnabledMap(enabled); + applySettings(json.result); }) .catch(() => { // Settings fetch failure is non-fatal — fall back to first-to-register. @@ -56,11 +61,9 @@ const ChatbotMount = () => { return () => { cancelled = true; }; - }, []); - - useEffect(() => fetchSettings(), [fetchSettings]); + }, [applySettings]); - useEffect(() => subscribeToExtensionSettings(fetchSettings), [fetchSettings]); + useEffect(() => subscribeToExtensionSettings(applySettings), [applySettings]); const registryVersion = useSyncExternalStore( subscribeToRegistry, diff --git a/superset-frontend/src/core/extensions/index.ts b/superset-frontend/src/core/extensions/index.ts index 72cfd450fce..7ca3e7e7d6c 100644 --- a/superset-frontend/src/core/extensions/index.ts +++ b/superset-frontend/src/core/extensions/index.ts @@ -30,14 +30,21 @@ export const extensions: typeof extensionsApi = { getAllExtensions, }; -const settingsListeners = new Set<() => void>(); +type ExtensionSettings = { + active_chatbot_id: string | null; + enabled: Record<string, boolean>; +}; + +const settingsListeners = new Set<(settings: ExtensionSettings) => void>(); -export const notifyExtensionSettingsChanged = (): void => { - settingsListeners.forEach(fn => fn()); +export const notifyExtensionSettingsChanged = ( + settings: ExtensionSettings, +): void => { + settingsListeners.forEach(fn => fn(settings)); }; export const subscribeToExtensionSettings = ( - listener: () => void, + listener: (settings: ExtensionSettings) => void, ): (() => void) => { settingsListeners.add(listener); return () => settingsListeners.delete(listener); diff --git a/superset-frontend/src/extensions/ExtensionsList.tsx b/superset-frontend/src/extensions/ExtensionsList.tsx index 9e8df4c43f8..9660ab5b867 100644 --- a/superset-frontend/src/extensions/ExtensionsList.tsx +++ b/superset-frontend/src/extensions/ExtensionsList.tsx @@ -110,7 +110,7 @@ const ExtensionsList: FunctionComponent<ExtensionsListProps> = ({ }) .then(({ json }) => { setSettings(json.result); - notifyExtensionSettingsChanged(); + notifyExtensionSettingsChanged(json.result); addSuccessToast(t('Settings saved.')); }) .catch(() => addDangerToast(t('Failed to save extension settings.')));
