Skip to content

Commit

Permalink
fix(theme): show progress bar after delay (#1278)
Browse files Browse the repository at this point in the history
  • Loading branch information
brc-dd committed Sep 3, 2022
1 parent ee37eaa commit 496bd34
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
17 changes: 15 additions & 2 deletions src/client/theme-default/index.ts
Expand Up @@ -28,11 +28,24 @@ const theme: Theme = {
NotFound,
enhanceApp: ({ router }) => {
if (inBrowser) {
let timeoutId: NodeJS.Timeout
let called = false

router.onBeforeRouteChange = () => {
nprogress.start()
timeoutId = setTimeout(() => {
nprogress.start()
called = true
}, 500)
}

router.onAfterRouteChanged = () => {
nprogress.done(true)
if (timeoutId) {
clearTimeout(timeoutId)
}
if (called) {
nprogress.done(true)
called = false
}
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/client/theme-default/support/utils.ts
Expand Up @@ -13,12 +13,12 @@ export function isExternal(path: string): boolean {
}

export function throttleAndDebounce(fn: () => void, delay: number): () => void {
let timeout: any
let timeoutId: NodeJS.Timeout
let called = false

return () => {
if (timeout) {
clearTimeout(timeout)
if (timeoutId) {
clearTimeout(timeoutId)
}

if (!called) {
Expand All @@ -28,7 +28,7 @@ export function throttleAndDebounce(fn: () => void, delay: number): () => void {
called = false
}, delay)
} else {
timeout = setTimeout(fn, delay)
timeoutId = setTimeout(fn, delay)
}
}
}
Expand Down

0 comments on commit 496bd34

Please sign in to comment.