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.
Python agentagentic-aiagentic-frameworkagentic-workflowaiautomationclaudedeepseekgenaigptllmlow-codemcpnextjsno-codeopenaipythonskillsworkflow
fix(web): preserve detail sidebar state during SSR (#42936)
yyh2d813b2a8741
diff --git a/web/app/components/app/configuration/hooks/__tests__/use-configuration.spec.tsx b/web/app/components/app/configuration/hooks/__tests__/use-configuration.spec.tsxindex 776b6c8a1c6..1829afb93a9 100644--- a/web/app/components/app/configuration/hooks/__tests__/use-configuration.spec.tsx+++ b/web/app/components/app/configuration/hooks/__tests__/use-configuration.spec.tsx@@ -1,4 +1,6 @@import { act, waitFor } from '@testing-library/react'+import Cookies from 'js-cookie'+import { DETAIL_SIDEBAR_COOKIE_NAME } from '@/app/components/detail-sidebar/cookie'import { updateAppModelConfig } from '@/service/apps'import { consoleQuery } from '@/service/console'import { seedAccountProfileQuery } from '@/test/console/account-profile'@@ -23,7 +25,6 @@ const renderHook = (callback: () => ReturnType<typeof useConfiguration>) => {const mockSetSettingsDestination = vi.fn()const mockSetShowAppConfigureFeaturesModal = vi.fn()-const mockSetDetailSidebarMode = vi.fn()const mockHandleMultipleModelConfigsChange = vi.fn()const mockFetchCollectionList = vi.fn()const mockFetchAppDetailDirect = vi.fn()@@ -100,10 +101,6 @@ vi.mock('@/app/components/app/store', () => ({}),}))-vi.mock('@/app/components/detail-sidebar/storage', () => ({- useSetDetailSidebarMode: () => mockSetDetailSidebarMode,-}))-vi.mock('@/service/use-common', () => ({useFileUploadConfig: () => ({data: undefined,@@ -194,6 +191,7 @@ vi.mock('@/utils/completion-params', () => ({describe('useConfiguration', () => {beforeEach(() => {vi.clearAllMocks()+ Cookies.remove(DETAIL_SIDEBAR_COOKIE_NAME)latestAdvancedPromptConfigOptions = undefinedmockTempStopState = []mockCurrentModelFeatures = ['vision']@@ -675,7 +673,7 @@ describe('useConfiguration', () => {expect(mockSetShowAppConfigureFeaturesModal).toHaveBeenCalledWith(true)expect(mockFormattingChangedDispatcher).toHaveBeenCalled()expect(mockHandleMultipleModelConfigsChange).toHaveBeenCalled()- expect(mockSetDetailSidebarMode).toHaveBeenCalledWith('collapse')+ expect(Cookies.get(DETAIL_SIDEBAR_COOKIE_NAME)).toBe('collapse')expect(mockSetSettingsDestination).toHaveBeenCalledWith('provider')expect(mockSetConversationHistoriesRole).toHaveBeenCalledWith({assistant_prefix: 'bot',diff --git a/web/app/components/app/configuration/hooks/configuration-lifecycle/use-multiple-model-debug.ts b/web/app/components/app/configuration/hooks/configuration-lifecycle/use-multiple-model-debug.tsindex 8e820b9ee09..eb7d6e1a7e7 100644--- a/web/app/components/app/configuration/hooks/configuration-lifecycle/use-multiple-model-debug.ts+++ b/web/app/components/app/configuration/hooks/configuration-lifecycle/use-multiple-model-debug.ts@@ -1,8 +1,9 @@import type { FormValue } from '@/app/components/header/account-setting/model-provider-page/declarations'import type { ModelConfig } from '@/models/debug'+import { useSetAtom } from 'jotai'import { useCallback } from 'react'import { useDebugWithSingleOrMultipleModel } from '@/app/components/app/configuration/debug/hooks'-import { useSetDetailSidebarMode } from '@/app/components/detail-sidebar/storage'+import { setDetailSidebarModeAtom } from '@/app/components/detail-sidebar/state'export function useMultipleModelDebug({appId,@@ -13,7 +14,7 @@ export function useMultipleModelDebug({completionParams: FormValuemodelConfig: ModelConfig}) {- const setDetailSidebarMode = useSetDetailSidebarMode()+ const setDetailSidebarMode = useSetAtom(setDetailSidebarModeAtom)const { debugWithMultipleModel, multipleModelConfigs, handleMultipleModelConfigsChange } =useDebugWithSingleOrMultipleModel(appId)const enableMultipleModelDebug = useCallback(() => {diff --git a/web/app/components/detail-sidebar/__tests__/cookie.spec.ts b/web/app/components/detail-sidebar/__tests__/cookie.spec.tsnew file mode 100644index 00000000000..04e6b2e453d--- /dev/null+++ b/web/app/components/detail-sidebar/__tests__/cookie.spec.ts@@ -0,0 +1,12 @@+import { parseDetailSidebarMode } from '../cookie'++describe('detail sidebar cookie', () => {+ it.each([+ ['collapse', 'collapse'],+ ['expand', 'expand'],+ ['unexpected', 'expand'],+ [undefined, 'expand'],+ ] as const)('parses %s as %s', (value, expected) => {+ expect(parseDetailSidebarMode(value)).toBe(expected)+ })+})diff --git a/web/app/components/detail-sidebar/__tests__/index.spec.tsx b/web/app/components/detail-sidebar/__tests__/index.spec.tsxindex 8ed88e2e713..9a30571c36d 100644--- a/web/app/components/detail-sidebar/__tests__/index.spec.tsx+++ b/web/app/components/detail-sidebar/__tests__/index.spec.tsx@@ -1,9 +1,15 @@+import type { ReactNode } from 'react'+import type { DetailSidebarMode } from '../cookie'import { HotkeysProvider } from '@tanstack/react-hotkeys'import { fireEvent, screen } from '@testing-library/react'import userEvent from '@testing-library/user-event'+import { Provider } from 'jotai'+import { useHydrateAtoms } from 'jotai/utils'+import Cookies from 'js-cookie'import { renderWithConsoleQuery } from '@/test/console/query-data'import { DetailSidebarFrame } from '..'-import { DETAIL_SIDEBAR_STORAGE_KEY } from '../storage'+import { DETAIL_SIDEBAR_COOKIE_NAME } from '../cookie'+import { detailSidebarModeAtom } from '../state'vi.mock('@/app/components/main-nav/components/account-section', () => ({default: ({ compact }: { compact?: boolean }) => (@@ -25,41 +31,57 @@ vi.mock('@/app/components/header/env-nav', () => ({default: () => <div>Environment tag</div>,}))+function InitialDetailSidebarMode({+ children,+ mode,+}: {+ children: ReactNode+ mode: DetailSidebarMode+}) {+ useHydrateAtoms([[detailSidebarModeAtom, mode]])+ return children+}+function renderDetailSidebarFrame(currentEnv: string | null = null,platform: 'mac' | 'windows' = 'mac',compact = false,+ mode: DetailSidebarMode = 'expand',) {return renderWithConsoleQuery(- <HotkeysProvider defaultOptions={{ hotkey: { platform } }}>- <DetailSidebarFrame- compact={compact}- renderTop={({ expand, onToggle }) => (- <div data-testid="detail-top" data-expand={expand}>- <button type="button" data-testid="detail-toggle" onClick={onToggle}>- Toggle- </button>+ <Provider>+ <InitialDetailSidebarMode mode={mode}>+ <HotkeysProvider defaultOptions={{ hotkey: { platform } }}>+ <DetailSidebarFrame+ compact={compact}+ renderTop={({ expand, onToggle }) => (+ <div data-testid="detail-top" data-expand={expand}>+ <button type="button" data-testid="detail-toggle" onClick={onToggle}>+ Toggle+ </button>+ </div>+ )}+ renderSection={({ expand }) => (+ <div data-testid="detail-section" data-expand={expand}>+ Section+ </div>+ )}+ />+ <div contentEditable suppressContentEditableWarning role="textbox" aria-label="Note">+ <span>Note text</span></div>- )}- renderSection={({ expand }) => (- <div data-testid="detail-section" data-expand={expand}>- Section- </div>- )}- />- <div contentEditable suppressContentEditableWarning role="textbox" aria-label="Note">- <span>Note text</span>- </div>- <input aria-label="Name" />- <textarea aria-label="Description" />- </HotkeysProvider>,+ <input aria-label="Name" />+ <textarea aria-label="Description" />+ </HotkeysProvider>+ </InitialDetailSidebarMode>+ </Provider>,{ accountProfileMeta: { currentEnv } },)}describe('DetailSidebarFrame', () => {beforeEach(() => {- localStorage.clear()+ Cookies.remove(DETAIL_SIDEBAR_COOKIE_NAME)})it('renders expanded detail content by default', () => {@@ -69,6 +91,13 @@ describe('DetailSidebarFrame', () => {expect(screen.getByTestId('detail-section')).toHaveAttribute('data-expand', 'true')})+ it('renders the server-provided collapsed preference on the first render', () => {+ renderDetailSidebarFrame(null, 'mac', false, 'collapse')++ expect(screen.getByTestId('detail-top')).toHaveAttribute('data-expand', 'false')+ expect(screen.getByTestId('detail-section')).toHaveAttribute('data-expand', 'false')+ })+it('starts compact navigation collapsed and toggles without changing the desktop preference', async () => {const user = userEvent.setup()renderDetailSidebarFrame(null, 'mac', true)@@ -76,11 +105,11 @@ describe('DetailSidebarFrame', () => {expect(screen.getByRole('button', { name: 'account' })).toHaveTextContent('Compact account')await user.click(screen.getByRole('button', { name: 'Toggle' }))expect(screen.getByRole('button', { name: 'account' })).toHaveTextContent('Expanded account')- expect(localStorage.getItem(DETAIL_SIDEBAR_STORAGE_KEY)).toBe('expand')+ expect(Cookies.get(DETAIL_SIDEBAR_COOKIE_NAME)).toBeUndefined()await user.click(screen.getByRole('button', { name: 'Toggle' }))expect(screen.getByRole('button', { name: 'account' })).toHaveTextContent('Compact account')- expect(localStorage.getItem(DETAIL_SIDEBAR_STORAGE_KEY)).toBe('expand')+ expect(Cookies.get(DETAIL_SIDEBAR_COOKIE_NAME)).toBeUndefined()})describe.each(['mac', 'windows'] as const)('%s shortcut', (platform) => {@@ -92,12 +121,12 @@ describe('DetailSidebarFrame', () => {fireEvent.keyDown(document.body, { key: 'b', ...modifiers })expect(screen.getByTestId('detail-top')).toHaveAttribute('data-expand', 'false')- expect(localStorage.getItem(DETAIL_SIDEBAR_STORAGE_KEY)).toBe('collapse')+ expect(Cookies.get(DETAIL_SIDEBAR_COOKIE_NAME)).toBe('collapse')fireEvent.keyDown(document.body, { key: 'b', ...modifiers })expect(screen.getByTestId('detail-top')).toHaveAttribute('data-expand', 'true')- expect(localStorage.getItem(DETAIL_SIDEBAR_STORAGE_KEY)).toBe('expand')+ expect(Cookies.get(DETAIL_SIDEBAR_COOKIE_NAME)).toBe('expand')})it.each(['Note', 'Note text', 'Name', 'Description'])(@@ -118,7 +147,7 @@ describe('DetailSidebarFrame', () => {expect(event.defaultPrevented).toBe(false)expect(screen.getByTestId('detail-top')).toHaveAttribute('data-expand', 'true')- expect(localStorage.getItem(DETAIL_SIDEBAR_STORAGE_KEY)).toBe('expand')+ expect(Cookies.get(DETAIL_SIDEBAR_COOKIE_NAME)).toBeUndefined()},)})@@ -130,7 +159,7 @@ describe('DetailSidebarFrame', () => {expect(screen.getByTestId('detail-top')).toHaveAttribute('data-expand', 'false')expect(screen.getByTestId('detail-section')).toHaveAttribute('data-expand', 'false')expect(screen.queryByText('Environment tag')).not.toBeInTheDocument()- expect(localStorage.getItem(DETAIL_SIDEBAR_STORAGE_KEY)).toBe('collapse')+ expect(Cookies.get(DETAIL_SIDEBAR_COOKIE_NAME)).toBe('collapse')})it('shows a floating preview on collapsed hover without changing persisted state', () => {@@ -140,7 +169,7 @@ describe('DetailSidebarFrame', () => {expect(screen.getByTestId('detail-top')).toHaveAttribute('data-expand', 'true')expect(screen.getByTestId('detail-section')).toHaveAttribute('data-expand', 'true')- expect(localStorage.getItem(DETAIL_SIDEBAR_STORAGE_KEY)).toBe('collapse')+ expect(Cookies.get(DETAIL_SIDEBAR_COOKIE_NAME)).toBe('collapse')})it('keeps collapsed bottom actions in place when they are hovered', () => {@@ -150,7 +179,7 @@ describe('DetailSidebarFrame', () => {expect(screen.getByTestId('detail-top')).toHaveAttribute('data-expand', 'false')expect(screen.getByRole('button', { name: 'account' })).toHaveTextContent('Compact account')- expect(localStorage.getItem(DETAIL_SIDEBAR_STORAGE_KEY)).toBe('collapse')+ expect(Cookies.get(DETAIL_SIDEBAR_COOKIE_NAME)).toBe('collapse')})it('persists expansion when the hovered preview toggle is clicked', () => {@@ -161,6 +190,6 @@ describe('DetailSidebarFrame', () => {expect(screen.getByTestId('detail-top')).toHaveAttribute('data-expand', 'true')expect(screen.getByTestId('detail-section')).toHaveAttribute('data-expand', 'true')- expect(localStorage.getItem(DETAIL_SIDEBAR_STORAGE_KEY)).toBe('expand')+ expect(Cookies.get(DETAIL_SIDEBAR_COOKIE_NAME)).toBe('expand')})})diff --git a/web/app/components/detail-sidebar/cookie.ts b/web/app/components/detail-sidebar/cookie.tsnew file mode 100644index 00000000000..517646b3496--- /dev/null+++ b/web/app/components/detail-sidebar/cookie.ts@@ -0,0 +1,7 @@+export type DetailSidebarMode = 'expand' | 'collapse'++export const DETAIL_SIDEBAR_COOKIE_NAME = 'console-detail-sidebar-mode'++export function parseDetailSidebarMode(value: string | undefined): DetailSidebarMode {+ return value === 'collapse' ? 'collapse' : 'expand'+}diff --git a/web/app/components/detail-sidebar/index.tsx b/web/app/components/detail-sidebar/index.tsxindex 194eccef015..0aaa8a67d43 100644--- a/web/app/components/detail-sidebar/index.tsx+++ b/web/app/components/detail-sidebar/index.tsx@@ -4,13 +4,14 @@ import type { ReactNode } from 'react'import { cn } from '@langgenius/dify-ui/cn'import { useHotkey } from '@tanstack/react-hotkeys'import { useSuspenseQuery } from '@tanstack/react-query'+import { useAtomValue, useSetAtom } from 'jotai'import { useEffect, useRef, useState } from 'react'import EnvNav from '@/app/components/header/env-nav'import AccountSection from '@/app/components/main-nav/components/account-section'import HelpMenu from '@/app/components/main-nav/components/help-menu'import { userProfileQueryOptions } from '@/features/account-profile/client'import { DETAIL_SIDEBAR_TOGGLE_HOTKEY } from './hotkeys'-import { useDetailSidebarMode } from './storage'+import { detailSidebarModeAtom, setDetailSidebarModeAtom } from './state'type DetailSidebarRenderProps = {expand: boolean@@ -48,7 +49,8 @@ export function DetailSidebarFrame({...userProfileQueryOptions(),select: (data) => data.meta.currentEnv,})- const [storedDetailSidebarExpand, setStoredDetailSidebarExpand] = useDetailSidebarMode()+ const storedDetailSidebarExpand = useAtomValue(detailSidebarModeAtom)+ const setStoredDetailSidebarExpand = useSetAtom(setDetailSidebarModeAtom)const [compactExpanded, setCompactExpanded] = useState(false)const detailNavigationMode = storedDetailSidebarExpand === 'collapse' ? 'collapse' : 'expand'const detailNavigationExpanded = compact ? compactExpanded : detailNavigationMode === 'expand'diff --git a/web/app/components/detail-sidebar/state.ts b/web/app/components/detail-sidebar/state.tsnew file mode 100644index 00000000000..83d178cb3bf--- /dev/null+++ b/web/app/components/detail-sidebar/state.ts@@ -0,0 +1,17 @@+'use client'++import type { DetailSidebarMode } from './cookie'+import { atom } from 'jotai'+import Cookies from 'js-cookie'+import { DETAIL_SIDEBAR_COOKIE_NAME } from './cookie'++export const detailSidebarModeAtom = atom<DetailSidebarMode>('expand')++export const setDetailSidebarModeAtom = atom(null, (_get, set, mode: DetailSidebarMode) => {+ set(detailSidebarModeAtom, mode)+ Cookies.set(DETAIL_SIDEBAR_COOKIE_NAME, mode, {+ expires: 365,+ path: '/',+ sameSite: 'lax',+ })+})diff --git a/web/app/components/detail-sidebar/storage.ts b/web/app/components/detail-sidebar/storage.tsdeleted file mode 100644index a572104b8e1..00000000000--- a/web/app/components/detail-sidebar/storage.ts+++ /dev/null@@ -1,10 +0,0 @@-import { createLocalStorageState } from 'foxact/create-local-storage-state'--type DetailSidebarMode = 'expand' | 'collapse'--export const DETAIL_SIDEBAR_STORAGE_KEY = 'app-detail-collapse-or-expand'--const [useDetailSidebarMode, _useDetailSidebarModeValue, useSetDetailSidebarMode] =- createLocalStorageState<DetailSidebarMode>(DETAIL_SIDEBAR_STORAGE_KEY, 'expand', { raw: true })--export { useDetailSidebarMode, useSetDetailSidebarMode }diff --git a/web/app/components/main-nav/__tests__/index.spec.tsx b/web/app/components/main-nav/__tests__/index.spec.tsxindex fdcdd7bf4b8..1797ee011d1 100644--- a/web/app/components/main-nav/__tests__/index.spec.tsx+++ b/web/app/components/main-nav/__tests__/index.spec.tsx@@ -18,8 +18,9 @@ import { act, fireEvent, screen, waitFor, within } from '@testing-library/react'import userEvent from '@testing-library/user-event'import { createStore, Provider as JotaiProvider } from 'jotai'import { queryClientAtom } from 'jotai-tanstack-query'+import Cookies from 'js-cookie'import { NuqsTestingAdapter } from 'nuqs/adapters/testing'-import { DETAIL_SIDEBAR_STORAGE_KEY } from '@/app/components/detail-sidebar/storage'+import { DETAIL_SIDEBAR_COOKIE_NAME } from '@/app/components/detail-sidebar/cookie'import { LEARN_DIFY_HIDDEN_STORAGE_KEY } from '@/app/components/explore/learn-dify/storage'import { gotoAnythingDialogHandle } from '@/app/components/goto-anything/dialog-handle'import { ACCOUNT_SETTING_TAB } from '@/app/components/header/account-setting/constants'@@ -610,6 +611,7 @@ describe('MainNav', () => {vi.clearAllMocks()gotoAnythingDialogHandle.close()localStorage.clear()+ Cookies.remove(DETAIL_SIDEBAR_COOKIE_NAME)mockPathname = '/apps'mockInstalledApps = []mockInstalledAppsPending = false@@ -794,7 +796,7 @@ describe('MainNav', () => {})it('keeps the global navigation account section expanded on home routes', () => {- localStorage.setItem(DETAIL_SIDEBAR_STORAGE_KEY, 'collapse')+ Cookies.set(DETAIL_SIDEBAR_COOKIE_NAME, 'collapse')mockPathname = '/'renderMainNav()diff --git a/web/app/components/main-nav/__tests__/layout.spec.tsx b/web/app/components/main-nav/__tests__/layout.spec.tsxindex a34559a0c36..d3b38c5bdba 100644--- a/web/app/components/main-nav/__tests__/layout.spec.tsx+++ b/web/app/components/main-nav/__tests__/layout.spec.tsx@@ -2,12 +2,30 @@ import type { ReactNode } from 'react'import type { Mock } from 'vite-plus/test'import { useSuspenseQuery } from '@tanstack/react-query'import { fireEvent, screen } from '@testing-library/react'+import { createStore, Provider, useAtomValue, useSetAtom } from 'jotai'+import { renderToString } from 'react-dom/server'import { useStore as useAppStore } from '@/app/components/app/store'+import {+ detailSidebarModeAtom,+ setDetailSidebarModeAtom,+} from '@/app/components/detail-sidebar/state'import { isAgentV2Enabled } from '@/features/agent-v2/feature-flag'import { usePathname } from '@/next/navigation'import { render } from '@/test/console/render'import MainNavLayout from '../layout'+function DetailSidebarModeProbe() {+ const mode = useAtomValue(detailSidebarModeAtom)+ const setMode = useSetAtom(setDetailSidebarModeAtom)+ return (+ <aside data-mode={mode}>+ <button type="button" onClick={() => setMode('collapse')}>+ Collapse sidebar+ </button>+ </aside>+ )+}+const mockConsoleState = vi.hoisted(() => ({current: {isCurrentWorkspaceDatasetOperator: false,@@ -73,9 +91,53 @@ describe('MainNavLayout', () => {;(isAgentV2Enabled as Mock).mockReturnValue(true)})+ it('uses the request preference in server-rendered sidebar markup', () => {+ ;(usePathname as Mock).mockReturnValue('/datasets/dataset-1/documents')++ const html = renderToString(+ <Provider store={createStore()}>+ <MainNavLayout+ initialDetailSidebarMode="collapse"+ detailSidebar={<DetailSidebarModeProbe />}+ >+ <div>dataset detail</div>+ </MainNavLayout>+ </Provider>,+ )++ expect(html).toContain('data-mode="collapse"')+ })++ it('keeps an interactive change when a cached layout supplies the earlier initial value', () => {+ ;(usePathname as Mock).mockReturnValue('/datasets/dataset-1/documents')++ const { rerender } = render(+ <MainNavLayout initialDetailSidebarMode="expand" detailSidebar={<DetailSidebarModeProbe />}>+ <div>dataset detail</div>+ </MainNavLayout>,+ )++ fireEvent.click(screen.getByRole('button', { name: 'Collapse sidebar' }))+ expect(screen.getByText('Collapse sidebar').parentElement).toHaveAttribute(+ 'data-mode',+ 'collapse',+ )++ rerender(+ <MainNavLayout initialDetailSidebarMode="expand" detailSidebar={<DetailSidebarModeProbe />}>+ <div>dataset detail</div>+ </MainNavLayout>,+ )++ expect(screen.getByText('Collapse sidebar').parentElement).toHaveAttribute(+ 'data-mode',+ 'collapse',+ )+ })+it('renders desktop main nav instead of the desktop header', () => {render(- <MainNavLayout>+ <MainNavLayout initialDetailSidebarMode="expand"><div>content</div></MainNavLayout>,)@@ -87,7 +149,7 @@ describe('MainNavLayout', () => {it('uses the main nav without the desktop header wrapper', () => {render(- <MainNavLayout>+ <MainNavLayout initialDetailSidebarMode="expand"><div>content</div></MainNavLayout>,)@@ -99,7 +161,7 @@ describe('MainNavLayout', () => {it('renders one main landmark as the skip navigation target', () => {render(- <MainNavLayout>+ <MainNavLayout initialDetailSidebarMode="expand"><div>content</div></MainNavLayout>,)@@ -119,7 +181,7 @@ describe('MainNavLayout', () => {it('renders skip navigation before the repeated main navigation', () => {const { container } = render(- <MainNavLayout>+ <MainNavLayout initialDetailSidebarMode="expand"><div>content</div></MainNavLayout>,)@@ -141,7 +203,7 @@ describe('MainNavLayout', () => {it('moves focus to the main content when skip navigation is activated', () => {render(- <MainNavLayout>+ <MainNavLayout initialDetailSidebarMode="expand"><div>content</div></MainNavLayout>,)@@ -160,7 +222,10 @@ describe('MainNavLayout', () => {;(usePathname as Mock).mockReturnValue(pathname)render(- <MainNavLayout detailSidebar={<aside aria-label="Detail sidebar">Detail sidebar</aside>}>+ <MainNavLayout+ initialDetailSidebarMode="expand"+ detailSidebar={<aside aria-label="Detail sidebar">Detail sidebar</aside>}+ ><div>dataset detail</div></MainNavLayout>,)@@ -181,6 +246,7 @@ describe('MainNavLayout', () => {render(<MainNavLayout+ initialDetailSidebarMode="expand"detailSidebar={<aside aria-label="Legacy dataset sidebar">Legacy dataset sidebar</aside>}><div>new knowledge detail</div>@@ -198,7 +264,7 @@ describe('MainNavLayout', () => {;(usePathname as Mock).mockReturnValue('/skills/skill-1')render(- <MainNavLayout>+ <MainNavLayout initialDetailSidebarMode="expand"><div>skill detail</div></MainNavLayout>,)@@ -211,7 +277,7 @@ describe('MainNavLayout', () => {;(usePathname as Mock).mockReturnValue('/skills')render(- <MainNavLayout>+ <MainNavLayout initialDetailSidebarMode="expand"><div>skills collection</div></MainNavLayout>,)@@ -228,7 +294,10 @@ describe('MainNavLayout', () => {;(usePathname as Mock).mockReturnValue(pathname)render(- <MainNavLayout detailSidebar={<aside aria-label="Detail sidebar">Detail sidebar</aside>}>+ <MainNavLayout+ initialDetailSidebarMode="expand"+ detailSidebar={<aside aria-label="Detail sidebar">Detail sidebar</aside>}+ ><div>content</div></MainNavLayout>,)@@ -276,7 +345,10 @@ describe('MainNavLayout', () => {})render(- <MainNavLayout detailSidebar={<aside aria-label="Detail sidebar">Detail sidebar</aside>}>+ <MainNavLayout+ initialDetailSidebarMode="expand"+ detailSidebar={<aside aria-label="Detail sidebar">Detail sidebar</aside>}+ ><div>detail route content</div></MainNavLayout>,)@@ -294,7 +366,7 @@ describe('MainNavLayout', () => {;(usePathname as Mock).mockReturnValue('/datasets')render(- <MainNavLayout>+ <MainNavLayout initialDetailSidebarMode="expand"><div>content</div></MainNavLayout>,)diff --git a/web/app/components/main-nav/layout.tsx b/web/app/components/main-nav/layout.tsxindex 584a515a2ac..00e3dd7bcc4 100644--- a/web/app/components/main-nav/layout.tsx+++ b/web/app/components/main-nav/layout.tsx@@ -2,12 +2,15 @@import type { ReactNode } from 'react'import type { MainNavProps } from './types'+import type { DetailSidebarMode } from '@/app/components/detail-sidebar/cookie'import { cn } from '@langgenius/dify-ui/cn'import { useAtomValue } from 'jotai'+import { useHydrateAtoms } from 'jotai/utils'import { useEffect } from 'react'import { useTranslation } from 'react-i18next'import { useShallow } from 'zustand/react/shallow'import { useStore as useAppStore } from '@/app/components/app/store'+import { detailSidebarModeAtom } from '@/app/components/detail-sidebar/state'import { isCurrentWorkspaceDatasetOperatorAtom } from '@/context/workspace-state'import { isAgentV2Enabled } from '@/features/agent-v2/feature-flag'import { usePathname } from '@/next/navigation'@@ -20,6 +23,7 @@ type MainNavLayoutProps = {children: ReactNodedetailSidebar?: ReactNodeinitialPlatform?: MainNavProps['initialPlatform']+ initialDetailSidebarMode: DetailSidebarMode}function AppDetailStoreCleanup() {@@ -40,7 +44,13 @@ function AppDetailStoreCleanup() {return null}-const MainNavLayout = ({ children, detailSidebar, initialPlatform }: MainNavLayoutProps) => {+const MainNavLayout = ({+ children,+ detailSidebar,+ initialPlatform,+ initialDetailSidebarMode,+}: MainNavLayoutProps) => {+ useHydrateAtoms([[detailSidebarModeAtom, initialDetailSidebarMode]])const { t } = useTranslation(['common'])const pathname = usePathname()const isCurrentWorkspaceDatasetOperator = useAtomValue(isCurrentWorkspaceDatasetOperatorAtom)diff --git a/web/app/components/main-nav/server.tsx b/web/app/components/main-nav/server.tsxindex 34fab45d7a0..8af1374a1a4 100644--- a/web/app/components/main-nav/server.tsx+++ b/web/app/components/main-nav/server.tsx@@ -1,5 +1,9 @@import type { ReactNode } from 'react'-import { headers } from '@/next/headers'+import {+ DETAIL_SIDEBAR_COOKIE_NAME,+ parseDetailSidebarMode,+} from '@/app/components/detail-sidebar/cookie'+import { cookies, headers } from '@/next/headers'import MainNavLayoutClient from './layout'import { getPlatformFromUserAgent } from './shortcut-platform'@@ -10,10 +14,18 @@ export default async function MainNavLayout({children: ReactNodedetailSidebar?: ReactNode}) {- const initialPlatform = getPlatformFromUserAgent((await headers()).get('user-agent'))+ const [requestHeaders, requestCookies] = await Promise.all([headers(), cookies()])+ const initialPlatform = getPlatformFromUserAgent(requestHeaders.get('user-agent'))+ const initialDetailSidebarMode = parseDetailSidebarMode(+ requestCookies.get(DETAIL_SIDEBAR_COOKIE_NAME)?.value,+ )return (- <MainNavLayoutClient detailSidebar={detailSidebar} initialPlatform={initialPlatform}>+ <MainNavLayoutClient+ detailSidebar={detailSidebar}+ initialPlatform={initialPlatform}+ initialDetailSidebarMode={initialDetailSidebarMode}+ >{children}</MainNavLayoutClient>)