From def3d600690712452a0cb26d86bd929ab206e69a Mon Sep 17 00:00:00 2001 From: afc163 Date: Sun, 17 Jul 2016 15:25:12 +0800 Subject: [PATCH] fix timeout error --- site/theme/template/Content/Article.jsx | 5 ++++- site/theme/template/utils.jsx | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/site/theme/template/Content/Article.jsx b/site/theme/template/Content/Article.jsx index 234862df15..8e0b215817 100644 --- a/site/theme/template/Content/Article.jsx +++ b/site/theme/template/Content/Article.jsx @@ -14,12 +14,15 @@ export default class Article extends React.Component { return; } const checkImgUrl = 'http://alipay-rmsdeploy-dev-image.oss-cn-hangzhou-zmf.aliyuncs.com/rmsportal/JdVaTbZzPxEldUi.png'; - utils.ping(checkImgUrl, status => { + this.pingTimer = utils.ping(checkImgUrl, status => { if (status === 'responded') { links.forEach(link => (link.style.display = 'block')); } }); } + componentWillUnmount() { + clearTimeout(this.pingTimer); + } getArticle(article) { const { content } = this.props; const { meta } = content; diff --git a/site/theme/template/utils.jsx b/site/theme/template/utils.jsx index d0c19aebab..e791d217d7 100644 --- a/site/theme/template/utils.jsx +++ b/site/theme/template/utils.jsx @@ -49,5 +49,5 @@ export function ping(url, callback) { img.onload = () => finish('responded'); img.onerror = () => finish('error'); img.src = url; - setTimeout(() => finish('timeout'), 1500); + return setTimeout(() => finish('timeout'), 1500); }