From 56e9081b739d3faef953a6c9a294b7bd35c7641d Mon Sep 17 00:00:00 2001 From: Jori Lallo Date: Sun, 29 May 2016 15:25:38 -0700 Subject: [PATCH] Only scroll based on received props once --- src/scenes/DocumentScene/DocumentScene.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/scenes/DocumentScene/DocumentScene.js b/src/scenes/DocumentScene/DocumentScene.js index 1286ca23a..fad80e16a 100644 --- a/src/scenes/DocumentScene/DocumentScene.js +++ b/src/scenes/DocumentScene/DocumentScene.js @@ -12,18 +12,23 @@ import Document from 'components/Document'; import styles from './DocumentScene.scss'; class DocumentScene extends React.Component { + state = { + didScroll: false, + } + componentDidMount = () => { const documentId = this.props.routeParams.id; this.props.fetchDocumentAsync(documentId); } componentWillReceiveProps = (nextProps) => { - // Scroll to anchor after loading + // Scroll to anchor after loading, and only once const hash = this.props.location.hash; - if (nextProps.document && hash) { + if (nextProps.document && hash && !this.state.didScroll) { const name = hash.split('#')[1]; setTimeout(() => { + this.setState({ didScroll: true }); const element = document.getElementsByName(name)[0]; if (element) element.scrollIntoView() }, 0);