From a9fc1a24a9a7da2195bf3de4017a1392aca08608 Mon Sep 17 00:00:00 2001 From: Vikhyath Mondreti Date: Wed, 25 Mar 2026 21:00:44 -0700 Subject: [PATCH] fix(guard-change): run finalize at right time --- .../[workspaceId]/home/hooks/use-chat.ts | 15 ++++++++++----- .../settings/[section]/settings.tsx | 7 +++++-- .../[workspaceId]/settings/navigation.ts | 19 +++++++++++-------- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts b/apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts index 4bc03673e9..b52923705a 100644 --- a/apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts +++ b/apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts @@ -740,13 +740,12 @@ export function useChat( return { aborted: true, error: false } } - logger.warn('Failed to attach to existing stream', { + logger.error('Failed to attach to existing stream, will throw for outer retry', { streamId, latestEventId, error: err instanceof Error ? err.message : String(err), }) - setError(err instanceof Error ? err.message : RECONNECT_TAIL_ERROR) - return { aborted: false, error: true } + throw err } finally { setIsReconnecting(false) } @@ -833,11 +832,17 @@ export function useChat( ) useEffect(() => { - if (!chatHistory || appliedChatIdRef.current === chatHistory.id) return + if (!chatHistory) return const activeStreamId = chatHistory.activeStreamId const snapshot = chatHistory.streamSnapshot - applyChatHistorySnapshot(chatHistory, { preserveActiveStreamingMessage: true }) + const isNewChat = appliedChatIdRef.current !== chatHistory.id + + if (isNewChat) { + applyChatHistorySnapshot(chatHistory, { preserveActiveStreamingMessage: true }) + } else if (!activeStreamId || sendingRef.current) { + return + } if (activeStreamId && !sendingRef.current) { const gen = ++streamGenRef.current diff --git a/apps/sim/app/workspace/[workspaceId]/settings/[section]/settings.tsx b/apps/sim/app/workspace/[workspaceId]/settings/[section]/settings.tsx index fd01097fde..df2f2fcdcd 100644 --- a/apps/sim/app/workspace/[workspaceId]/settings/[section]/settings.tsx +++ b/apps/sim/app/workspace/[workspaceId]/settings/[section]/settings.tsx @@ -20,6 +20,7 @@ import type { SettingsSection } from '@/app/workspace/[workspaceId]/settings/nav import { allNavigationItems, isBillingEnabled, + isCredentialSetsEnabled, } from '@/app/workspace/[workspaceId]/settings/navigation' /** @@ -164,9 +165,11 @@ export function SettingsPage({ section }: SettingsPageProps) { const effectiveSection = !isBillingEnabled && (section === 'subscription' || section === 'team') ? 'general' - : section === 'admin' && !sessionLoading && !isAdminRole + : section === 'credential-sets' && !isCredentialSetsEnabled ? 'general' - : section + : section === 'admin' && !sessionLoading && !isAdminRole + ? 'general' + : section const label = allNavigationItems.find((item) => item.id === effectiveSection)?.label ?? effectiveSection diff --git a/apps/sim/app/workspace/[workspaceId]/settings/navigation.ts b/apps/sim/app/workspace/[workspaceId]/settings/navigation.ts index 1e564ed059..f97e676866 100644 --- a/apps/sim/app/workspace/[workspaceId]/settings/navigation.ts +++ b/apps/sim/app/workspace/[workspaceId]/settings/navigation.ts @@ -72,6 +72,7 @@ const isAccessControlEnabled = isTruthy(getEnv('NEXT_PUBLIC_ACCESS_CONTROL_ENABL const isInboxEnabled = isTruthy(getEnv('NEXT_PUBLIC_INBOX_ENABLED')) export const isBillingEnabled = isTruthy(getEnv('NEXT_PUBLIC_BILLING_ENABLED')) +export { isCredentialSetsEnabled } export const sectionConfig: { key: NavigationSection; title: string }[] = [ { key: 'account', title: 'Account' }, @@ -141,14 +142,16 @@ export const allNavigationItems: NavigationItem[] = [ selfHostedOverride: isInboxEnabled, showWhenLocked: true, }, - { - id: 'credential-sets', - label: 'Email Polling', - icon: Mail, - section: 'system', - requiresHosted: true, - selfHostedOverride: isCredentialSetsEnabled, - }, + ...(isCredentialSetsEnabled + ? [ + { + id: 'credential-sets' as const, + label: 'Email Polling', + icon: Mail, + section: 'system' as const, + }, + ] + : []), { id: 'recently-deleted', label: 'Recently Deleted', icon: TrashOutline, section: 'system' }, { id: 'sso',