Added some error boundaries to keep the ui functional even if elements may throw and error for a connection instance

canary
WolverinDEV 2020-12-18 19:25:27 +01:00
parent 5da2877c8b
commit a5afa5cce3
4 changed files with 38 additions and 5 deletions

View File

@ -53,7 +53,6 @@ const ContentRendererClientInfo = () => {
const contentData = useContentData("client-info"); const contentData = useContentData("client-info");
if(!contentData) { return null; } if(!contentData) { return null; }
throw "XX";
return ( return (
<ClientInfoRenderer <ClientInfoRenderer
events={contentData.events} events={contentData.events}
@ -138,7 +137,9 @@ export const SideBarRenderer = (props: {
return ( return (
<EventContent.Provider value={props.events}> <EventContent.Provider value={props.events}>
<div className={cssStyle.container}> <div className={cssStyle.container}>
<ErrorBoundary>
<SideBarHeader eventsHeader={props.eventsHeader} type={content} /> <SideBarHeader eventsHeader={props.eventsHeader} type={content} />
</ErrorBoundary>
<div className={cssStyle.frameContainer}> <div className={cssStyle.frameContainer}>
<SideBarFrame type={content} /> <SideBarFrame type={content} />
</div> </div>

View File

@ -6,6 +6,7 @@ import {findLogEventRenderer} from "./RendererEvent";
import {LogMessage} from "tc-shared/connectionlog/Definitions"; import {LogMessage} from "tc-shared/connectionlog/Definitions";
import {ServerEventLogUiEvents} from "tc-shared/ui/frames/log/Definitions"; import {ServerEventLogUiEvents} from "tc-shared/ui/frames/log/Definitions";
import {useDependentState} from "tc-shared/ui/react-elements/Helper"; import {useDependentState} from "tc-shared/ui/react-elements/Helper";
import {ErrorBoundary} from "tc-shared/ui/react-elements/ErrorBoundary";
const cssStyle = require("./Renderer.scss"); const cssStyle = require("./Renderer.scss");
@ -111,7 +112,9 @@ export const ServerLogFrame = (props: { events: Registry<ServerEventLogUiEvents>
return ( return (
<EventsContext.Provider value={props.events}> <EventsContext.Provider value={props.events}>
<HandlerIdContext.Provider value={handlerId}> <HandlerIdContext.Provider value={handlerId}>
<ErrorBoundary>
<ServerLogRenderer /> <ServerLogRenderer />
</ErrorBoundary>
</HandlerIdContext.Provider> </HandlerIdContext.Provider>
</EventsContext.Provider> </EventsContext.Provider>
); );

View File

@ -0,0 +1,18 @@
.container {
display: flex;
flex-direction: column;
justify-content: center;
background-color: red;
height: 100%;
width: 100%;
.text {
align-items: center;
text-align: center;
font-weight: bold;
color: white;
}
}

View File

@ -1,20 +1,31 @@
import * as React from "react"; import * as React from "react";
const cssStyle = require("./ErrorBoundary.scss");
interface ErrorBoundaryState { interface ErrorBoundaryState {
errorOccurred: boolean errorOccurred: boolean
} }
export class ErrorBoundary extends React.Component<{}, ErrorBoundaryState> { export class ErrorBoundary extends React.Component<{}, ErrorBoundaryState> {
constructor(props) {
super(props);
this.state = { errorOccurred: false };
}
render() { render() {
if(this.state.errorOccurred) { if(this.state.errorOccurred) {
return (
<div className={cssStyle.container}>
<div className={cssStyle.text}>A rendering error has occurred</div>
</div>
);
} else { } else {
return this.props.children; return this.props.children;
} }
} }
componentDidCatch(error: Error, errorInfo: React.ErrorInfo) { componentDidCatch(error: Error, errorInfo: React.ErrorInfo) {
console.error("Did catch: %o - %o", error, errorInfo); /* TODO: Some kind of logging? */
} }
static getDerivedStateFromError() : Partial<ErrorBoundaryState> { static getDerivedStateFromError() : Partial<ErrorBoundaryState> {