Files
gsfdc/demo-dify/dify/web/app/components/workflow/nodes/lazy-panel.tsx
T
wuzilongandCursor 6519682885 chore: 纳入本地 Dify 1.19.0 源码及品牌与免登改动
演示目录只保留可重建的源码。运行密钥、数据卷、依赖和带口令的本地配置不进入仓库。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-18 13:59:25 +08:00

29 lines
979 B
TypeScript

import type { ComponentType } from 'react'
import { createElement, lazy, Suspense, useState } from 'react'
import ErrorBoundary from '@/app/components/base/error-boundary'
import PanelLoading from './panel-loading'
// Keep the component identity stable while BasePanel injects updated node data
// and run parameters. Share explicit retries with future mounts so reopening a
// recovered panel does not reuse the original lazy component's cached rejection.
export function lazyPanel<Props extends object>(
load: () => Promise<{ default: ComponentType<Props> }>,
) {
let CurrentPanel = lazy(load)
return function LazyPanel(props: Props) {
const [Panel, setPanel] = useState(() => CurrentPanel)
const retry = () => {
CurrentPanel = lazy(load)
setPanel(() => CurrentPanel)
}
return (
<ErrorBoundary onReset={retry}>
<Suspense fallback={<PanelLoading />}>{createElement(Panel, props)}</Suspense>
</ErrorBoundary>
)
}
}