From 8f7c8fb9c0981c674632828dbea4bdf9aaabebbd Mon Sep 17 00:00:00 2001 From: Benjy Cui Date: Tue, 19 Apr 2016 17:06:15 +0800 Subject: [PATCH] site: improve performance --- site/component/MainContent/index.jsx | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/site/component/MainContent/index.jsx b/site/component/MainContent/index.jsx index 656d7483eb..352b4c21c0 100644 --- a/site/component/MainContent/index.jsx +++ b/site/component/MainContent/index.jsx @@ -7,11 +7,19 @@ const SubMenu = Menu.SubMenu; export default class MainContent extends React.Component { componentDidMount() { - this.componentDidUpdate(); + this.scrollToAnchor(this.props); } - componentDidUpdate() { - const scrollTo = this.props.location.query.scrollTo; + shouldComponentUpdate(nextProps) { + this.scrollToAnchor(nextProps); + + const pathname = this.props.location.pathname; + return pathname !== nextProps.location.pathname || + /^\/components\//i.test(pathname); + } + + scrollToAnchor(props) { + const scrollTo = props.location.query.scrollTo; if (scrollTo !== undefined) { const target = document.getElementById(scrollTo);