import { Transition } from '@headlessui/react' import { ExclamationTriangleIcon } from '@heroicons/react/24/outline' import { isRouteErrorResponse, useRouteError } from '@remix-run/react' import clsx from 'clsx' import { Fragment, useEffect, useState } from 'react' import Code from './Code' type Properties = { readonly type?: 'full' | 'embedded'; } export function ErrorPopup({ type = 'full' }: Properties) { const [isOpen, setIsOpen] = useState(false) const error = useRouteError() const routing = isRouteErrorResponse(error) const message = (error instanceof Error ? error.message : 'An unexpected error occurred') console.error(error) // Debounce the error modal so it doesn't show up for a split second // when the user navigates to a new page. useEffect(() => { setTimeout(() => { setIsOpen(true) }, 150) }, []) return (

{routing ? error.status : 'Error'}

{routing ? (

{error.statusText}

) : ( {message} )}
) }