aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2021-02-28 01:01:34 +0100
committerGitHub <noreply@github.com>2021-02-28 01:01:34 +0100
commit0635c8760dfdfeb3d763f1d1ae6cf5a208b29b6c (patch)
tree65c2b71e2a8d430f659d6a5cd9f72f7bef57110f
parent73264e07167755f7c4ab7b06348531ba80daad26 (diff)
downloadmastodon-0635c8760dfdfeb3d763f1d1ae6cf5a208b29b6c.tar
mastodon-0635c8760dfdfeb3d763f1d1ae6cf5a208b29b6c.tar.gz
mastodon-0635c8760dfdfeb3d763f1d1ae6cf5a208b29b6c.tar.bz2
mastodon-0635c8760dfdfeb3d763f1d1ae6cf5a208b29b6c.zip
Fix WebUI crashing when SVG support is disabled (#15809)
Fixes #14910
-rw-r--r--app/javascript/mastodon/components/hashtag.js49
1 files changed, 38 insertions, 11 deletions
diff --git a/app/javascript/mastodon/components/hashtag.js b/app/javascript/mastodon/components/hashtag.js
index d766ca90d..75fcf20e3 100644
--- a/app/javascript/mastodon/components/hashtag.js
+++ b/app/javascript/mastodon/components/hashtag.js
@@ -2,10 +2,35 @@
import React from 'react';
import { Sparklines, SparklinesCurve } from 'react-sparklines';
import { FormattedMessage } from 'react-intl';
+import PropTypes from 'prop-types';
import ImmutablePropTypes from 'react-immutable-proptypes';
import Permalink from './permalink';
import ShortNumber from 'mastodon/components/short_number';
+class SilentErrorBoundary extends React.Component {
+
+ static propTypes = {
+ children: PropTypes.node,
+ };
+
+ state = {
+ error: false,
+ };
+
+ componentDidCatch () {
+ this.setState({ error: true });
+ }
+
+ render () {
+ if (this.state.error) {
+ return null;
+ }
+
+ return this.props.children;
+ }
+
+}
+
/**
* Used to render counter of how much people are talking about hashtag
*
@@ -51,17 +76,19 @@ const Hashtag = ({ hashtag }) => (
</div>
<div className='trends__item__sparkline'>
- <Sparklines
- width={50}
- height={28}
- data={hashtag
- .get('history')
- .reverse()
- .map((day) => day.get('uses'))
- .toArray()}
- >
- <SparklinesCurve style={{ fill: 'none' }} />
- </Sparklines>
+ <SilentErrorBoundary>
+ <Sparklines
+ width={50}
+ height={28}
+ data={hashtag
+ .get('history')
+ .reverse()
+ .map((day) => day.get('uses'))
+ .toArray()}
+ >
+ <SparklinesCurve style={{ fill: 'none' }} />
+ </Sparklines>
+ </SilentErrorBoundary>
</div>
</div>
);