feat: handle errors for message renderer separately

This commit is contained in:
Paul 2021-12-25 16:03:05 +00:00
parent c96b09bb81
commit 028a8660c1
3 changed files with 33 additions and 15 deletions

View file

@ -22,11 +22,12 @@ const CrashContainer = styled.div`
interface Props { interface Props {
children: Children; children: Children;
section: "client" | "renderer";
} }
const ERROR_URL = "https://reporting.revolt.chat"; const ERROR_URL = "https://reporting.revolt.chat";
export default function ErrorBoundary({ children }: Props) { export default function ErrorBoundary({ children, section }: Props) {
const [error, ignoreError] = useErrorBoundary(); const [error, ignoreError] = useErrorBoundary();
useEffect(() => { useEffect(() => {
@ -38,6 +39,7 @@ export default function ErrorBoundary({ children }: Props) {
origin: window.origin, origin: window.origin,
commitSHA: GIT_REVISION, commitSHA: GIT_REVISION,
userAgent: navigator.userAgent, userAgent: navigator.userAgent,
section,
}), }),
); );
} }
@ -46,11 +48,24 @@ export default function ErrorBoundary({ children }: Props) {
if (error) { if (error) {
return ( return (
<CrashContainer> <CrashContainer>
{section === "client" ? (
<>
<h3>Client Crash Report</h3> <h3>Client Crash Report</h3>
<button onClick={ignoreError}> <button onClick={ignoreError}>
Ignore error and try to reload app Ignore error and try to reload app
</button> </button>
<button onClick={() => location.reload()}>Refresh page</button> <button onClick={() => location.reload()}>
Refresh page
</button>
</>
) : (
<>
<h3>Component Error</h3>
<button onClick={ignoreError}>
Ignore error and try render again
</button>
</>
)}
<pre> <pre>
<code>{error?.stack}</code> <code>{error?.stack}</code>
</pre> </pre>

View file

@ -17,7 +17,7 @@ const RevoltApp = lazy(() => import("./RevoltApp"));
export function App() { export function App() {
return ( return (
<ErrorBoundary> <ErrorBoundary section="client">
<Context> <Context>
<Masks /> <Masks />
{/* {/*

View file

@ -9,6 +9,7 @@ import styled from "styled-components";
import { Text } from "preact-i18n"; import { Text } from "preact-i18n";
import { useEffect, useMemo } from "preact/hooks"; import { useEffect, useMemo } from "preact/hooks";
import ErrorBoundary from "../../lib/ErrorBoundary";
import { isTouchscreenDevice } from "../../lib/isTouchscreenDevice"; import { isTouchscreenDevice } from "../../lib/isTouchscreenDevice";
import { useApplicationState } from "../../mobx/State"; import { useApplicationState } from "../../mobx/State";
@ -159,6 +160,7 @@ const TextChannel = observer(({ channel }: { channel: ChannelI }) => {
}> }>
<ChannelHeader channel={channel} /> <ChannelHeader channel={channel} />
<ChannelMain> <ChannelMain>
<ErrorBoundary section="renderer">
<ChannelContent> <ChannelContent>
<VoiceHeader id={channel._id} /> <VoiceHeader id={channel._id} />
<NewMessages channel={channel} last_id={last_id} /> <NewMessages channel={channel} last_id={last_id} />
@ -167,6 +169,7 @@ const TextChannel = observer(({ channel }: { channel: ChannelI }) => {
<JumpToBottom channel={channel} /> <JumpToBottom channel={channel} />
<MessageBox channel={channel} /> <MessageBox channel={channel} />
</ChannelContent> </ChannelContent>
</ErrorBoundary>
{!isTouchscreenDevice && {!isTouchscreenDevice &&
layout.getSectionState(SIDEBAR_MEMBERS, true) && ( layout.getSectionState(SIDEBAR_MEMBERS, true) && (
<RightSidebar /> <RightSidebar />