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.

827 B
Raw Blame
type PageLeaveGuard = {
  message: string
  shouldBlock: () => boolean
}

// Keep confirmation guards separate from beforeunload listeners that save drafts
// or release locks. Probing them by dispatching beforeunload would run those effects.
const guards = new Map<PageLeaveGuard, () => void>()

export function confirmPageLeave() {
  const messages = [
    ...new Set(
      [...guards.keys()].filter((guard) => guard.shouldBlock()).map((guard) => guard.message),
    ),
  ]
  // oxlint-disable-next-line eslint/no-alert -- Ask the browser's unsaved-changes confirmation before logout; beforeunload itself runs too late to cancel the server request.
  return messages.length === 0 || window.confirm(messages.join('\n\n'))
}

export function clearPageLeaveGuards() {
  for (const unregister of guards.values()) unregister()
}