From 6256cee0342d7ebeda407c4644330c7c6bc31b84 Mon Sep 17 00:00:00 2001 From: Claire Date: Thu, 27 Jul 2023 19:25:07 +0200 Subject: [PATCH] Change error boundary to upstream's (#2323) --- .../glitch/components/error_boundary.jsx | 127 +++++++----------- .../flavours/glitch/styles/basics.scss | 1 + .../styles/components/error_boundary.scss | 30 ----- .../glitch/styles/components/index.scss | 1 - 4 files changed, 51 insertions(+), 108 deletions(-) delete mode 100644 app/javascript/flavours/glitch/styles/components/error_boundary.scss diff --git a/app/javascript/flavours/glitch/components/error_boundary.jsx b/app/javascript/flavours/glitch/components/error_boundary.jsx index 4a4dadf0a5..248b866475 100644 --- a/app/javascript/flavours/glitch/components/error_boundary.jsx +++ b/app/javascript/flavours/glitch/components/error_boundary.jsx @@ -7,8 +7,7 @@ import { Helmet } from 'react-helmet'; import StackTrace from 'stacktrace-js'; -import { source_url } from 'flavours/glitch/initial_state'; -import { preferencesLink } from 'flavours/glitch/utils/backend_links'; +import { version, source_url } from 'flavours/glitch/initial_state'; export default class ErrorBoundary extends PureComponent { @@ -24,7 +23,7 @@ export default class ErrorBoundary extends PureComponent { componentStack: undefined, }; - componentDidCatch(error, info) { + componentDidCatch (error, info) { this.setState({ hasError: true, errorMessage: error.toString(), @@ -44,88 +43,62 @@ export default class ErrorBoundary extends PureComponent { }); } - handleReload(e) { - e.preventDefault(); - window.location.reload(); - } + handleCopyStackTrace = () => { + const { errorMessage, stackTrace, mappedStackTrace } = this.state; + const textarea = document.createElement('textarea'); + + let contents = [errorMessage, stackTrace]; + if (mappedStackTrace) { + contents.push(mappedStackTrace); + } + + textarea.textContent = contents.join('\n\n\n'); + textarea.style.position = 'fixed'; + + document.body.appendChild(textarea); + + try { + textarea.select(); + document.execCommand('copy'); + } catch (e) { + + } finally { + document.body.removeChild(textarea); + } + + this.setState({ copied: true }); + setTimeout(() => this.setState({ copied: false }), 700); + }; render() { - const { hasError, errorMessage, stackTrace, mappedStackTrace, componentStack } = this.state; + const { hasError, copied, errorMessage } = this.state; - if (!hasError) return this.props.children; + if (!hasError) { + return this.props.children; + } const likelyBrowserAddonIssue = errorMessage && errorMessage.includes('NotFoundError'); - let debugInfo = ''; - if (stackTrace) { - debugInfo += 'Stack trace\n-----------\n\n```\n' + errorMessage + '\n' + stackTrace.toString() + '\n```'; - } - if (mappedStackTrace) { - debugInfo += 'Mapped stack trace\n-----------\n\n```\n' + errorMessage + '\n' + mappedStackTrace.toString() + '\n```'; - } - if (componentStack) { - if (debugInfo) { - debugInfo += '\n\n\n'; - } - debugInfo += 'React component stack\n---------------------\n\n```\n' + componentStack.toString() + '\n```'; - } - - let issueTracker = source_url; - if (source_url.match(/^https:\/\/github\.com\/[^/]+\/[^/]+\/?$/)) { - issueTracker = source_url + '/issues'; - } - return ( -
-
-

-

- -

-
    - { likelyBrowserAddonIssue && ( -
  • - -
  • - ) } -
  • - }} - /> - { debugInfo !== '' && ( -
    - -