Skip to content

Commit

Permalink
perf(client): don't use setTimeout when the page number is 0
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroppy committed Jul 7, 2019
1 parent 97dddb1 commit 08e4ee2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 2 additions & 0 deletions packages/client/src/components/AppContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const AppContainer = ({ slides: originalSlides, hash }) => {
const isLive = params.get('isLive');
let index = parsedUrl.hash.match(/^#slide=(.+?)$/);
index = index !== null ? index[1] - 1 : 0;
const isJumpPage = index !== 0;

const setCommentsListComponent = async () => {
const { CommentsList } = await import(/* webpackChunkName: 'live' */ './CommentsList');
Expand Down Expand Up @@ -140,6 +141,7 @@ export const AppContainer = ({ slides: originalSlides, hash }) => {
<ContentComponent
hash={hash}
slides={slides}
isJumpPage={isJumpPage}
terminate={terminate}
currentIndex={currentIndex}
onChangeSlideIndex={onChangeSlideIndex}
Expand Down
9 changes: 7 additions & 2 deletions packages/client/src/components/ContentView/Base.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async function setupMermaid() {
}

export const Base = memo(
({ slides, onChangeSlideIndex, hash }) => {
({ slides, onChangeSlideIndex, hash, isJumpPage }) => {
// for SSR
if (process.env.NODE_ENV !== 'production') {
useEffect(() => {
Expand All @@ -36,7 +36,12 @@ export const Base = memo(
// delay Event Loop one round
// but on Node.js this line is an error, so put it in useEffect
if (!process.env.SSR) {
setTimeout(setupSlides, 0);
// 0 page
if (process.env.NODE_ENV === 'production' && !isJumpPage) {
setupSlides();
} else {
setTimeout(setupSlides, 0);
}
}

useEffect(() => {
Expand Down

0 comments on commit 08e4ee2

Please sign in to comment.