Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix: resolve chat sidebar UI bugs for hover panel and dropdown menu (#25813)

lyzno1e93bfe3d41e3
diff --git a/.gitignore b/.gitignore
index cbb7b4dac0c..22a2c425663 100644
--- a/.gitignore
+++ b/.gitignore
@@ -230,4 +230,8 @@ api/.env.backup
# Benchmark
scripts/stress-test/setup/config/
-scripts/stress-test/reports/
\ No newline at end of file
+scripts/stress-test/reports/
+
+# mcp
+.playwright-mcp/
+.serena/
\ No newline at end of file
diff --git a/web/app/components/base/chat/chat-with-history/hooks.tsx b/web/app/components/base/chat/chat-with-history/hooks.tsx
index 0e8da0d26d4..fb3e1bb8f37 100644
--- a/web/app/components/base/chat/chat-with-history/hooks.tsx
+++ b/web/app/components/base/chat/chat-with-history/hooks.tsx
@@ -122,19 +122,31 @@ export const useChatWithHistory = (installedAppInfo?: InstalledApp) => {
setLocaleFromProps()
}, [appData])
- const [sidebarCollapseState, setSidebarCollapseState] = useState<boolean>(false)
+ const [sidebarCollapseState, setSidebarCollapseState] = useState<boolean>(() => {
+ if (typeof window !== 'undefined') {
+ try {
+ const localState = localStorage.getItem('webappSidebarCollapse')
+ return localState === 'collapsed'
+ }
+ catch (e) {
+ // localStorage may be disabled in private browsing mode or by security settings
+ // fallback to default value
+ return false
+ }
+ }
+ return false
+ })
const handleSidebarCollapse = useCallback((state: boolean) => {
if (appId) {
setSidebarCollapseState(state)
- localStorage.setItem('webappSidebarCollapse', state ? 'collapsed' : 'expanded')
+ try {
+ localStorage.setItem('webappSidebarCollapse', state ? 'collapsed' : 'expanded')
+ }
+ catch (e) {
+ // localStorage may be disabled, continue without persisting state
+ }
}
}, [appId, setSidebarCollapseState])
- useEffect(() => {
- if (appId) {
- const localState = localStorage.getItem('webappSidebarCollapse')
- setSidebarCollapseState(localState === 'collapsed')
- }
- }, [appId])
const [conversationIdInfo, setConversationIdInfo] = useLocalStorageState<Record<string, Record<string, string>>>(CONVERSATION_ID_INFO, {
defaultValue: {},
})
diff --git a/web/app/components/base/chat/chat-with-history/index.tsx b/web/app/components/base/chat/chat-with-history/index.tsx
index cfde517a61e..464e30a821f 100644
--- a/web/app/components/base/chat/chat-with-history/index.tsx
+++ b/web/app/components/base/chat/chat-with-history/index.tsx
@@ -47,6 +47,11 @@ const ChatWithHistory: FC<ChatWithHistoryProps> = ({
themeBuilder?.buildTheme(site?.chat_color_theme, site?.chat_color_theme_inverted)
}, [site, customConfig, themeBuilder])
+ useEffect(() => {
+ if (!isSidebarCollapsed)
+ setShowSidePanel(false)
+ }, [isSidebarCollapsed])
+
useDocumentTitle(site?.title || 'Chat')
return (
@@ -76,7 +81,7 @@ const ChatWithHistory: FC<ChatWithHistoryProps> = ({
onMouseEnter={() => setShowSidePanel(true)}
onMouseLeave={() => setShowSidePanel(false)}
>
- <Sidebar isPanel />
+ <Sidebar isPanel panelVisible={showSidePanel} />
</div>
)}
<div className={cn('flex h-full flex-col overflow-hidden border-[0,5px] border-components-panel-border-subtle bg-chatbot-bg', isMobile ? 'rounded-t-2xl' : 'rounded-2xl')}>
diff --git a/web/app/components/base/chat/chat-with-history/sidebar/index.tsx b/web/app/components/base/chat/chat-with-history/sidebar/index.tsx
index 4e50c1cb794..c6a7063d802 100644
--- a/web/app/components/base/chat/chat-with-history/sidebar/index.tsx
+++ b/web/app/components/base/chat/chat-with-history/sidebar/index.tsx
@@ -23,9 +23,10 @@ import { useGlobalPublicStore } from '@/context/global-public-context'
type Props = {
isPanel?: boolean
+ panelVisible?: boolean
}
-const Sidebar = ({ isPanel }: Props) => {
+const Sidebar = ({ isPanel, panelVisible }: Props) => {
const { t } = useTranslation()
const {
isInstalledApp,
@@ -138,7 +139,12 @@ const Sidebar = ({ isPanel }: Props) => {
)}
</div>
<div className='flex shrink-0 items-center justify-between p-3'>
- <MenuDropdown hideLogout={isInstalledApp} placement='top-start' data={appData?.site} />
+ <MenuDropdown
+ hideLogout={isInstalledApp}
+ placement='top-start'
+ data={appData?.site}
+ forceClose={isPanel && !panelVisible}
+ />
{/* powered by */}
<div className='shrink-0'>
{!appData?.custom_config?.remove_webapp_brand && (
diff --git a/web/app/components/share/text-generation/menu-dropdown.tsx b/web/app/components/share/text-generation/menu-dropdown.tsx
index 1c1b6adfe8d..373e3b86990 100644
--- a/web/app/components/share/text-generation/menu-dropdown.tsx
+++ b/web/app/components/share/text-generation/menu-dropdown.tsx
@@ -1,6 +1,6 @@
'use client'
import type { FC } from 'react'
-import React, { useCallback, useRef, useState } from 'react'
+import React, { useCallback, useEffect, useRef, useState } from 'react'
import { useTranslation } from 'react-i18next'
import type { Placement } from '@floating-ui/react'
import {
@@ -25,12 +25,14 @@ type Props = {
data?: SiteInfo
placement?: Placement
hideLogout?: boolean
+ forceClose?: boolean
}
const MenuDropdown: FC<Props> = ({
data,
placement,
hideLogout,
+ forceClose,
}) => {
const webAppAccessMode = useWebAppStore(s => s.webAppAccessMode)
const router = useRouter()
@@ -55,6 +57,11 @@ const MenuDropdown: FC<Props> = ({
const [show, setShow] = useState(false)
+ useEffect(() => {
+ if (forceClose)
+ setOpen(false)
+ }, [forceClose, setOpen])
+
return (
<>
<PortalToFollowElem