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: prevent empty state flash and add skeleton loading for app list (#30616)

yyh44d7aaaf3374
diff --git a/web/app/components/apps/app-card-skeleton.tsx b/web/app/components/apps/app-card-skeleton.tsx
new file mode 100644
index 00000000000..806f19973a2
--- /dev/null
+++ b/web/app/components/apps/app-card-skeleton.tsx
@@ -0,0 +1,41 @@
+'use client'
+
+import * as React from 'react'
+import { SkeletonContainer, SkeletonRectangle, SkeletonRow } from '@/app/components/base/skeleton'
+
+type AppCardSkeletonProps = {
+ count?: number
+}
+
+/**
+ * Skeleton placeholder for App cards during loading states.
+ * Matches the visual layout of AppCard component.
+ */
+export const AppCardSkeleton = React.memo(({ count = 6 }: AppCardSkeletonProps) => {
+ return (
+ <>
+ {Array.from({ length: count }).map((_, index) => (
+ <div
+ key={index}
+ className="h-[160px] rounded-xl border-[0.5px] border-components-card-border bg-components-card-bg p-4"
+ >
+ <SkeletonContainer className="h-full">
+ <SkeletonRow>
+ <SkeletonRectangle className="h-10 w-10 rounded-lg" />
+ <div className="flex flex-1 flex-col gap-1">
+ <SkeletonRectangle className="h-4 w-2/3" />
+ <SkeletonRectangle className="h-3 w-1/3" />
+ </div>
+ </SkeletonRow>
+ <div className="mt-4 flex flex-col gap-2">
+ <SkeletonRectangle className="h-3 w-full" />
+ <SkeletonRectangle className="h-3 w-4/5" />
+ </div>
+ </SkeletonContainer>
+ </div>
+ ))}
+ </>
+ )
+})
+
+AppCardSkeleton.displayName = 'AppCardSkeleton'
diff --git a/web/app/components/apps/list.tsx b/web/app/components/apps/list.tsx
index 003b4635956..290a73fc7cf 100644
--- a/web/app/components/apps/list.tsx
+++ b/web/app/components/apps/list.tsx
@@ -27,7 +27,9 @@ import { useGlobalPublicStore } from '@/context/global-public-context'
import { CheckModal } from '@/hooks/use-pay'
import { useInfiniteAppList } from '@/service/use-apps'
import { AppModeEnum } from '@/types/app'
+import { cn } from '@/utils/classnames'
import AppCard from './app-card'
+import { AppCardSkeleton } from './app-card-skeleton'
import Empty from './empty'
import Footer from './footer'
import useAppsQueryState from './hooks/use-apps-query-state'
@@ -45,7 +47,7 @@ const List = () => {
const { t } = useTranslation()
const { systemFeatures } = useGlobalPublicStore()
const router = useRouter()
- const { isCurrentWorkspaceEditor, isCurrentWorkspaceDatasetOperator } = useAppContext()
+ const { isCurrentWorkspaceEditor, isCurrentWorkspaceDatasetOperator, isLoadingCurrentWorkspace } = useAppContext()
const showTagManagementModal = useTagStore(s => s.showTagManagementModal)
const [activeTab, setActiveTab] = useQueryState(
'category',
@@ -89,6 +91,7 @@ const List = () => {
const {
data,
isLoading,
+ isFetching,
isFetchingNextPage,
fetchNextPage,
hasNextPage,
@@ -172,6 +175,8 @@ const List = () => {
const pages = data?.pages ?? []
const hasAnyApp = (pages[0]?.total ?? 0) > 0
+ // Show skeleton during initial load or when refetching with no previous data
+ const showSkeleton = isLoading || (isFetching && pages.length === 0)
return (
<>
@@ -205,23 +210,34 @@ const List = () => {
/>
</div>
</div>
- {hasAnyApp
- ? (
- <div className="relative grid grow grid-cols-1 content-start gap-4 px-12 pt-2 sm:grid-cols-1 md:grid-cols-2 xl:grid-cols-4 2xl:grid-cols-5 2k:grid-cols-6">
- {isCurrentWorkspaceEditor
- && <NewAppCard ref={newAppCardRef} onSuccess={refetch} selectedAppType={activeTab} />}
- {pages.map(({ data: apps }) => apps.map(app => (
- <AppCard key={app.id} app={app} onRefresh={refetch} />
- )))}
- </div>
- )
- : (
- <div className="relative grid grow grid-cols-1 content-start gap-4 overflow-hidden px-12 pt-2 sm:grid-cols-1 md:grid-cols-2 xl:grid-cols-4 2xl:grid-cols-5 2k:grid-cols-6">
- {isCurrentWorkspaceEditor
- && <NewAppCard ref={newAppCardRef} className="z-10" onSuccess={refetch} selectedAppType={activeTab} />}
- <Empty />
- </div>
- )}
+ <div className={cn(
+ 'relative grid grow grid-cols-1 content-start gap-4 px-12 pt-2 sm:grid-cols-1 md:grid-cols-2 xl:grid-cols-4 2xl:grid-cols-5 2k:grid-cols-6',
+ !hasAnyApp && 'overflow-hidden',
+ )}
+ >
+ {(isCurrentWorkspaceEditor || isLoadingCurrentWorkspace) && (
+ <NewAppCard
+ ref={newAppCardRef}
+ isLoading={isLoadingCurrentWorkspace}
+ onSuccess={refetch}
+ selectedAppType={activeTab}
+ className={cn(!hasAnyApp && 'z-10')}
+ />
+ )}
+ {(() => {
+ if (showSkeleton)
+ return <AppCardSkeleton count={6} />
+
+ if (hasAnyApp) {
+ return pages.flatMap(({ data: apps }) => apps).map(app => (
+ <AppCard key={app.id} app={app} onRefresh={refetch} />
+ ))
+ }
+
+ // No apps - show empty state
+ return <Empty />
+ })()}
+ </div>
{isCurrentWorkspaceEditor && (
<div
diff --git a/web/app/components/apps/new-app-card.tsx b/web/app/components/apps/new-app-card.tsx
index 0c07b7327c0..bfa7af38929 100644
--- a/web/app/components/apps/new-app-card.tsx
+++ b/web/app/components/apps/new-app-card.tsx
@@ -25,6 +25,7 @@ const CreateFromDSLModal = dynamic(() => import('@/app/components/app/create-fro
export type CreateAppCardProps = {
className?: string
+ isLoading?: boolean
onSuccess?: () => void
ref: React.RefObject<HTMLDivElement | null>
selectedAppType?: string
@@ -33,6 +34,7 @@ export type CreateAppCardProps = {
const CreateAppCard = ({
ref,
className,
+ isLoading = false,
onSuccess,
selectedAppType,
}: CreateAppCardProps) => {
@@ -56,7 +58,11 @@ const CreateAppCard = ({
return (
<div
ref={ref}
- className={cn('relative col-span-1 inline-flex h-[160px] flex-col justify-between rounded-xl border-[0.5px] border-components-card-border bg-components-card-bg', className)}
+ className={cn(
+ 'relative col-span-1 inline-flex h-[160px] flex-col justify-between rounded-xl border-[0.5px] border-components-card-border bg-components-card-bg transition-opacity',
+ isLoading && 'pointer-events-none opacity-50',
+ className,
+ )}
>
<div className="grow rounded-t-xl p-2">
<div className="px-6 pb-1 pt-2 text-xs font-medium leading-[18px] text-text-tertiary">{t('createApp', { ns: 'app' })}</div>
diff --git a/web/service/use-apps.ts b/web/service/use-apps.ts
index 0f6c4a64ac7..d16d44af20f 100644
--- a/web/service/use-apps.ts
+++ b/web/service/use-apps.ts
@@ -12,6 +12,7 @@ import type {
} from '@/models/app'
import type { App, AppModeEnum } from '@/types/app'
import {
+ keepPreviousData,
useInfiniteQuery,
useQuery,
useQueryClient,
@@ -107,6 +108,7 @@ export const useInfiniteAppList = (params: AppListParams, options?: { enabled?:
queryFn: ({ pageParam = normalizedParams.page }) => get<AppListResponse>('/apps', { params: { ...normalizedParams, page: pageParam } }),
getNextPageParam: lastPage => lastPage.has_more ? lastPage.page + 1 : undefined,
initialPageParam: normalizedParams.page,
+ placeholderData: keepPreviousData,
...options,
})
}