import axios from "axios"; import * as stackTrace from "stacktrace-js"; import styled from "styled-components"; import { useEffect, useErrorBoundary } from "preact/hooks"; import { GIT_REVISION } from "../revision"; import { Children } from "../types/Preact"; const CrashContainer = styled.div` height: 100%; padding: 12px; background: black; color: white; h3 { margin: 0; margin-bottom: 12px; } `; interface Props { children: Children; section: "client" | "renderer"; } const ERROR_URL = "https://reporting.revolt.chat"; export default function ErrorBoundary({ children, section }: Props) { const [error, ignoreError] = useErrorBoundary(); useEffect(() => { if (error) { stackTrace.fromError(error).then((stackframes) => axios.post(ERROR_URL, { stackframes, rawStackTrace: error.stack, origin: window.origin, commitSHA: GIT_REVISION, userAgent: navigator.userAgent, section, }), ); } }, [error]); if (error) { return ( {section === "client" ? ( <>

Client Crash Report

) : ( <>

Component Error

)}
                    {error?.stack}
                
This error has been automatically reported.
); } return <>{children}; }