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(web): stabilize install footer and shortcut initial rendering (#42088)

Stephen Zhou5f02726207a2
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index d75b3d723fa..51edbca404c 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -350,6 +350,9 @@ catalogs:
ahooks:
specifier: 3.9.7
version: 3.9.7
+ bowser:
+ specifier: 2.14.1
+ version: 2.14.1
c12:
specifier: 4.0.0-beta.5
version: 4.0.0-beta.5
@@ -1387,6 +1390,9 @@ importers:
ahooks:
specifier: 'catalog:'
+ bowser:
+ specifier: 'catalog:'
+ version: 2.14.1
class-variance-authority:
specifier: 'catalog:'
version: 0.7.1
@@ -5504,6 +5510,9 @@ packages:
resolution: {integrity: sha512-JZOSA7Mo9sNGB8+UjSgzdLtokWAky1zbztM3WRLCbZ70/3cTANmQmOdR7y2g+J0e2WXywy1yS468tY+IruqEww==}
+ resolution: {integrity: sha512-tzPjzCxygAKWFOJP011oxFHs57HzIhOEracIgAePE4pqB3LikALKnSzUyU4MGs9/iCEUuHlAJTjTc5M+u7YEGg==}
+
resolution: {integrity: sha512-kLpxurY4Z4r9sgMsyG0Z9uzsBlgiU/EFKhj/h91/8yHu0edo7XuixOIH3VcJ8kkxs6/jPzoI6U9Vj3WqbMQ94g==}
engines: {node: 18 || 20 || >=22}
@@ -12881,6 +12890,8 @@ snapshots:
+
dependencies:
balanced-match: 4.0.4
@@ -17492,6 +17503,7 @@ time:
[email protected]: '2026-08-07T18:50:14.156Z'
[email protected]: '2026-03-25T16:24:19.682Z'
[email protected]: '2026-03-23T15:49:13.605Z'
+ [email protected]: '2026-02-08T22:04:35.837Z'
[email protected]: '2026-05-06T17:28:34.367Z'
[email protected]: '2025-11-25T23:28:06.854Z'
[email protected]: '2024-11-26T08:20:34.604Z'
diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml
index 02e54426222..e93446243a7 100644
--- a/pnpm-workspace.yaml
+++ b/pnpm-workspace.yaml
@@ -132,6 +132,7 @@ catalog:
abcjs: 6.7.0
agentation: 3.0.2
ahooks: 3.9.7
+ bowser: 2.14.1
c12: 4.0.0-beta.5
chokidar: 5.0.0
class-variance-authority: 0.7.1
diff --git a/web/app/(commonLayout)/layout.tsx b/web/app/(commonLayout)/layout.tsx
index c8388ad6282..b011b432ef8 100644
--- a/web/app/(commonLayout)/layout.tsx
+++ b/web/app/(commonLayout)/layout.tsx
@@ -1,7 +1,7 @@
import * as React from 'react'
import Zendesk from '@/app/components/base/zendesk'
import MaintenanceNotice from '@/app/components/header/maintenance-notice'
-import MainNavLayout from '@/app/components/main-nav/layout'
+import MainNavLayout from '@/app/components/main-nav/server'
import { CommonLayoutGlobalMounts } from './global-mounts'
import { ConsoleContextProviders, ConsoleRuntimeProviders } from './providers'
diff --git a/web/app/components/main-nav/__tests__/shortcut-platform.spec.ts b/web/app/components/main-nav/__tests__/shortcut-platform.spec.ts
new file mode 100644
index 00000000000..2b685b44fc0
--- /dev/null
+++ b/web/app/components/main-nav/__tests__/shortcut-platform.spec.ts
@@ -0,0 +1,19 @@
+import { getPlatformFromUserAgent } from '../shortcut-platform'
+
+describe('getPlatformFromUserAgent', () => {
+ it.each([
+ ['Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)', 'mac'],
+ ['Mozilla/5.0 (iPad; CPU OS 17_0 like Mac OS X)', 'mac'],
+ ['Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X)', 'mac'],
+ ['Mozilla/5.0 (Windows NT 10.0; Win64; x64)', 'windows'],
+ ['Mozilla/5.0 (X11; Linux x86_64)', 'linux'],
+ ['Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:130.0) Gecko/20100101 Firefox/130.0', 'linux'],
+ ['Mozilla/5.0 (Linux; Android 14)', 'linux'],
+ ['Mozilla/5.0 (X11; CrOS x86_64 14541.0.0)', 'linux'],
+ ['Unknown browser', null],
+ ['', null],
+ [null, null],
+ ])('detects %s as %s', (userAgent, expected) => {
+ expect(getPlatformFromUserAgent(userAgent)).toBe(expected)
+ })
+})
diff --git a/web/app/components/main-nav/components/__tests__/search-button.spec.tsx b/web/app/components/main-nav/components/__tests__/search-button.spec.tsx
index 0901d4c6811..19b3e089e1e 100644
--- a/web/app/components/main-nav/components/__tests__/search-button.spec.tsx
+++ b/web/app/components/main-nav/components/__tests__/search-button.spec.tsx
@@ -1,6 +1,7 @@
import { act, waitFor, within } from '@testing-library/react'
import { hydrateRoot } from 'react-dom/client'
import { renderToString } from 'react-dom/server'
+import { getPlatformFromUserAgent } from '../../shortcut-platform'
import { MainNavSearchButton } from '../search-button'
describe('MainNavSearchButton', () => {
@@ -8,30 +9,77 @@ describe('MainNavSearchButton', () => {
vi.restoreAllMocks()
})
- it('renders Ctrl during SSR and corrects it after Mac hydration without a mismatch', async () => {
- vi.spyOn(window.navigator, 'platform', 'get').mockReturnValue('MacIntel')
- const app = <MainNavSearchButton />
- const container = document.createElement('div')
- container.innerHTML = renderToString(app)
- const getSearchButton = () =>
- within(container).getByRole('button', { name: 'app.gotoAnything.searchTitle' })
+ it.each([
+ {
+ platform: 'MacIntel',
+ userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)',
+ initialLabel: '⌘K',
+ initialShortcut: 'Meta+K',
+ label: '⌘K',
+ shortcut: 'Meta+K',
+ },
+ {
+ platform: 'Win32',
+ userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)',
+ initialLabel: 'CtrlK',
+ initialShortcut: 'Control+K',
+ label: 'CtrlK',
+ shortcut: 'Control+K',
+ },
+ {
+ platform: 'MacIntel',
+ userAgent: null,
+ initialLabel: '',
+ initialShortcut: undefined,
+ label: '⌘K',
+ shortcut: 'Meta+K',
+ },
+ {
+ platform: 'Win32',
+ userAgent: null,
+ initialLabel: '',
+ initialShortcut: undefined,
+ label: 'CtrlK',
+ shortcut: 'Control+K',
+ },
+ {
+ platform: 'MacIntel',
+ userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)',
+ initialLabel: 'CtrlK',
+ initialShortcut: 'Control+K',
+ label: '⌘K',
+ shortcut: 'Meta+K',
+ },
+ ])(
+ 'hydrates $userAgent on $platform without a mismatch',
+ async ({ platform, userAgent, initialLabel, initialShortcut, label, shortcut }) => {
+ vi.spyOn(window.navigator, 'platform', 'get').mockReturnValue(platform)
+ const app = <MainNavSearchButton initialPlatform={getPlatformFromUserAgent(userAgent)} />
+ const container = document.createElement('div')
+ container.innerHTML = renderToString(app)
+ const getSearchButton = () =>
+ within(container).getByRole('button', { name: 'app.gotoAnything.searchTitle' })
- expect(getSearchButton()).toHaveTextContent('CtrlK')
- expect(getSearchButton()).not.toHaveTextContent('⌘')
- expect(getSearchButton()).toHaveAttribute('aria-keyshortcuts', 'Control+K')
- expect(container.querySelector('kbd')).toHaveAttribute('aria-hidden', 'true')
+ expect(getSearchButton().textContent).toBe(initialLabel)
+ if (initialShortcut)
+ expect(getSearchButton()).toHaveAttribute('aria-keyshortcuts', initialShortcut)
+ else expect(getSearchButton()).not.toHaveAttribute('aria-keyshortcuts')
+ expect(container.querySelector('kbd')).toHaveAttribute('aria-hidden', 'true')
- const onRecoverableError = vi.fn()
- const root = hydrateRoot(container, app, {
- onRecoverableError,
- })
+ const onRecoverableError = vi.fn()
+ const root = await act(async () =>
+ hydrateRoot(container, app, {
+ onRecoverableError,
+ }),
+ )
- try {
- await waitFor(() => expect(getSearchButton()).toHaveTextContent('⌘K'))
- expect(getSearchButton()).toHaveAttribute('aria-keyshortcuts', 'Meta+K')
- expect(onRecoverableError).not.toHaveBeenCalled()
- } finally {
- act(() => root.unmount())
- }
- })
+ try {
+ await waitFor(() => expect(getSearchButton()).toHaveTextContent(label))
+ expect(getSearchButton()).toHaveAttribute('aria-keyshortcuts', shortcut)
+ expect(onRecoverableError).not.toHaveBeenCalled()
+ } finally {
+ act(() => root.unmount())
+ }
+ },
+ )
})
diff --git a/web/app/components/main-nav/components/search-button.tsx b/web/app/components/main-nav/components/search-button.tsx
index dfac34437ee..bdf3d0bad89 100644
--- a/web/app/components/main-nav/components/search-button.tsx
+++ b/web/app/components/main-nav/components/search-button.tsx
@@ -1,5 +1,6 @@
'use client'
+import type { ShortcutPlatform } from '../shortcut-platform'
import { DialogTrigger } from '@langgenius/dify-ui/dialog'
import { Kbd } from '@langgenius/dify-ui/kbd'
import { detectPlatform, formatForDisplay } from '@tanstack/react-hotkeys'
@@ -16,21 +17,21 @@ function getPlatformSnapshot() {
return detectPlatform()
}
-function getServerPlatformSnapshot(): ReturnType<typeof detectPlatform> {
- return 'linux'
+function useDisplayPlatform(initialPlatform: ShortcutPlatform | null) {
+ return useSyncExternalStore(noopSubscribe, getPlatformSnapshot, () => initialPlatform)
}
-function useDisplayPlatform() {
- return useSyncExternalStore(noopSubscribe, getPlatformSnapshot, getServerPlatformSnapshot)
-}
-
-export function MainNavSearchButton() {
+export function MainNavSearchButton({
+ initialPlatform = null,
+}: {
+ initialPlatform?: ShortcutPlatform | null
+}) {
const { t } = useTranslation()
- const displayPlatform = useDisplayPlatform()
- const ariaKeyShortcuts = GOTO_ANYTHING_HOTKEY.replace(
- 'Mod',
- displayPlatform === 'mac' ? 'Meta' : 'Control',
- )
+ const displayPlatform = useDisplayPlatform(initialPlatform)
+ const ariaKeyShortcuts =
+ displayPlatform === null
+ ? undefined
+ : GOTO_ANYTHING_HOTKEY.replace('Mod', displayPlatform === 'mac' ? 'Meta' : 'Control')
return (
<DialogTrigger
@@ -47,11 +48,13 @@ export function MainNavSearchButton() {
<span aria-hidden className="i-custom-vender-main-nav-quick-search h-4 w-4" />
<Kbd
aria-hidden="true"
- className="h-4.5 min-w-0 rounded-[5px] border border-divider-deep bg-components-badge-bg-dimm px-1 py-0.5 system-2xs-medium-uppercase text-text-tertiary"
+ data-pending={displayPlatform === null ? '' : undefined}
+ className="h-4.5 w-9 min-w-0 shrink-0 rounded-[5px] border border-divider-deep bg-components-badge-bg-dimm px-1 py-0.5 system-2xs-medium-uppercase text-text-tertiary data-pending:invisible"
>
- {GOTO_ANYTHING_HOTKEY.split('+').map((key) => (
- <span key={key}>{formatForDisplay(key, { platform: displayPlatform })}</span>
- ))}
+ {displayPlatform !== null &&
+ GOTO_ANYTHING_HOTKEY.split('+').map((key) => (
+ <span key={key}>{formatForDisplay(key, { platform: displayPlatform })}</span>
+ ))}
</Kbd>
</DialogTrigger>
)
diff --git a/web/app/components/main-nav/index.tsx b/web/app/components/main-nav/index.tsx
index f191188c5f0..0eb7859d3aa 100644
--- a/web/app/components/main-nav/index.tsx
+++ b/web/app/components/main-nav/index.tsx
@@ -28,7 +28,7 @@ import { isMainNavRouteVisible, MAIN_NAV_ROUTES } from './routes'
const WebAppsSection = dynamic(() => import('./components/web-apps-section'), { ssr: false })
-export function MainNav({ className }: MainNavProps) {
+export function MainNav({ className, initialPlatform }: MainNavProps) {
const { t } = useTranslation()
const pathname = usePathname()
const isCurrentWorkspaceDatasetOperator = useAtomValue(isCurrentWorkspaceDatasetOperatorAtom)
@@ -109,7 +109,7 @@ export function MainNav({ className }: MainNavProps) {
<div className="flex min-h-0 w-60 flex-1 flex-col overflow-hidden">
<div className="flex items-center justify-between pt-3 pr-2 pb-2 pl-4">
{renderLogo()}
- <MainNavSearchButton />
+ <MainNavSearchButton initialPlatform={initialPlatform} />
</div>
<div className="p-2">
<WorkspaceCard />
diff --git a/web/app/components/main-nav/layout.tsx b/web/app/components/main-nav/layout.tsx
index 0c82a31fb57..641e45f4203 100644
--- a/web/app/components/main-nav/layout.tsx
+++ b/web/app/components/main-nav/layout.tsx
@@ -1,6 +1,7 @@
'use client'
import type { ReactNode } from 'react'
+import type { MainNavProps } from './types'
import { useAtomValue } from 'jotai'
import { useEffect } from 'react'
import { useTranslation } from 'react-i18next'
@@ -16,6 +17,7 @@ import { MAIN_CONTENT_ID, SkipNav } from './skip-nav'
type MainNavLayoutProps = {
children: ReactNode
detailSidebar?: ReactNode
+ initialPlatform?: MainNavProps['initialPlatform']
}
function AppDetailStoreCleanup() {
@@ -36,7 +38,7 @@ function AppDetailStoreCleanup() {
return null
}
-const MainNavLayout = ({ children, detailSidebar }: MainNavLayoutProps) => {
+const MainNavLayout = ({ children, detailSidebar, initialPlatform }: MainNavLayoutProps) => {
const { t } = useTranslation('common')
const pathname = usePathname()
const isCurrentWorkspaceDatasetOperator = useAtomValue(isCurrentWorkspaceDatasetOperatorAtom)
@@ -50,7 +52,11 @@ const MainNavLayout = ({ children, detailSidebar }: MainNavLayoutProps) => {
<div className="flex h-0 min-h-0 min-w-0 grow overflow-hidden bg-background-body">
<SkipNav>{t(($) => $['navigation.skipToMain'])}</SkipNav>
<AppDetailStoreCleanup />
- {hideMainNavigation ? null : useDetailSidebar ? detailSidebar : <MainNav />}
+ {hideMainNavigation ? null : useDetailSidebar ? (
+ detailSidebar
+ ) : (
+ <MainNav initialPlatform={initialPlatform} />
+ )}
<main
id={MAIN_CONTENT_ID}
tabIndex={-1}
diff --git a/web/app/components/main-nav/server.tsx b/web/app/components/main-nav/server.tsx
new file mode 100644
index 00000000000..34fab45d7a0
--- /dev/null
+++ b/web/app/components/main-nav/server.tsx
@@ -0,0 +1,20 @@
+import type { ReactNode } from 'react'
+import { headers } from '@/next/headers'
+import MainNavLayoutClient from './layout'
+import { getPlatformFromUserAgent } from './shortcut-platform'
+
+export default async function MainNavLayout({
+ children,
+ detailSidebar,
+}: {
+ children: ReactNode
+ detailSidebar?: ReactNode
+}) {
+ const initialPlatform = getPlatformFromUserAgent((await headers()).get('user-agent'))
+
+ return (
+ <MainNavLayoutClient detailSidebar={detailSidebar} initialPlatform={initialPlatform}>
+ {children}
+ </MainNavLayoutClient>
+ )
+}
diff --git a/web/app/components/main-nav/shortcut-platform.ts b/web/app/components/main-nav/shortcut-platform.ts
new file mode 100644
index 00000000000..f0d717196f2
--- /dev/null
+++ b/web/app/components/main-nav/shortcut-platform.ts
@@ -0,0 +1,13 @@
+import type { detectPlatform } from '@tanstack/react-hotkeys'
+import Bowser from 'bowser'
+
+export type ShortcutPlatform = ReturnType<typeof detectPlatform>
+
+export function getPlatformFromUserAgent(userAgent: string | null): ShortcutPlatform | null {
+ if (!userAgent) return null
+ const { name } = Bowser.getParser(userAgent).getOS()
+ if (name === 'macOS' || name === 'iOS') return 'mac'
+ if (name === 'Windows') return 'windows'
+ // Hotkeys uses the Linux modifier layout for other non-Apple platforms too.
+ return name ? 'linux' : null
+}
diff --git a/web/app/components/main-nav/types.ts b/web/app/components/main-nav/types.ts
index 4ac9937d321..773490fefc5 100644
--- a/web/app/components/main-nav/types.ts
+++ b/web/app/components/main-nav/types.ts
@@ -1,5 +1,8 @@
+import type { ShortcutPlatform } from './shortcut-platform'
+
export type MainNavProps = {
className?: string
+ initialPlatform?: ShortcutPlatform | null
}
export type MainNavItem = {
diff --git a/web/app/install/page.tsx b/web/app/install/page.tsx
index 978e593b459..510f8808836 100644
--- a/web/app/install/page.tsx
+++ b/web/app/install/page.tsx
@@ -18,7 +18,7 @@ const Install = () => {
<Header />
<InstallForm />
{!systemFeatures.branding.enabled && (
- <div className="px-8 py-6 text-sm font-normal text-text-tertiary">
+ <div className="mt-auto px-8 py-6 text-sm font-normal text-text-tertiary">
© {new Date().getFullYear()} LangGenius, Inc. All rights reserved.
</div>
)}
diff --git a/web/package.json b/web/package.json
index 9e38ab9dcc5..6fbe30d2da6 100644
--- a/web/package.json
+++ b/web/package.json
@@ -67,6 +67,7 @@
"@tanstack/react-virtual": "catalog:",
"abcjs": "catalog:",
"ahooks": "catalog:",
+ "bowser": "catalog:",
"class-variance-authority": "catalog:",
"copy-to-clipboard": "catalog:",
"cron-parser": "catalog:",