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.

979 B
Raw Blame
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>
    )
  }
}