diff --git a/src/bug-issue-template.js b/src/bug-issue-template.js new file mode 100644 index 00000000..667b86d8 --- /dev/null +++ b/src/bug-issue-template.js @@ -0,0 +1,13 @@ +export default ` +### Stack strace + +\`\`\` +// paste stack trace here +\`\`\` + +### localStorage + +\`\`\` +// paste localStorage content here (if it doesn't contain sensitive data) +\`\`\` +`; diff --git a/src/index.tsx b/src/index.tsx index 3431cb31..f8bfd725 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1371,4 +1371,100 @@ export class App extends React.Component { const AppWithTrans = withTranslation()(App); const rootElement = document.getElementById("root"); -ReactDOM.render(, rootElement); + +class TopErrorBoundary extends React.Component { + state = { hasError: false, stack: "", localStorage: "" }; + + static getDerivedStateFromError(error: any) { + console.error(error); + return { + hasError: true, + localStorage: JSON.stringify({ ...localStorage }), + stack: error.stack + }; + } + + private selectTextArea(event: React.MouseEvent) { + (event.target as HTMLTextAreaElement).select(); + } + + private async createGithubIssue() { + let body = ""; + try { + const templateStr = (await import("./bug-issue-template")).default; + if (typeof templateStr === "string") { + body = encodeURIComponent(templateStr); + } + } catch {} + + window.open( + `https://github.com/excalidraw/excalidraw/issues/new?body=${body}` + ); + } + + render() { + if (this.state.hasError) { + return ( +
+
+
+ Encountered an error. Please{" "} + + . +
+
+ If reloading doesn't work. Try{" "} + + .
+
+ (This will unfortunately result in loss of work.) +
+
+
+
+ Before doing so, we'd appreciate if you opened an issue on our{" "} + . + Please include the following error stack trace & localStorage + content (provided it's not private): +
+
+
+ +