Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: progress bar shown on back navigation through pathname check #1633

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions pages/_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { HasNewNotesProvider } from '@/components/use-has-new-notes'
import { WebLnProvider } from '@/wallets/webln/client'
import { AccountProvider } from '@/components/account'
import { WalletsProvider } from '@/wallets/index'
import { usePathname } from 'next/navigation'

const PWAPrompt = dynamic(() => import('react-ios-pwa-prompt'), { ssr: false })

Expand All @@ -42,13 +43,22 @@ function writeQuery (client, apollo, data) {
}
}

function shouldShowProgressBar (currentPathname, newPathname, shallow) {
return !shallow || (currentPathname !== newPathname)
}

export default function MyApp ({ Component, pageProps: { ...props } }) {
const client = getApolloClient()
const router = useRouter()
const pathname = usePathname()

useEffect(() => {
const nprogressStart = (_, { shallow }) => !shallow && NProgress.start()
const nprogressDone = (_, { shallow }) => !shallow && NProgress.done()
const nprogressStart = (newPathname, { shallow }) => {
shouldShowProgressBar(pathname, newPathname, shallow) && NProgress.start()
}
const nprogressDone = (newPathname, { shallow }) => {
shouldShowProgressBar(pathname, newPathname, shallow) && NProgress.done()
}

router.events.on('routeChangeStart', nprogressStart)
router.events.on('routeChangeComplete', nprogressDone)
Expand Down Expand Up @@ -77,7 +87,7 @@ export default function MyApp ({ Component, pageProps: { ...props } }) {
router.events.off('routeChangeComplete', nprogressDone)
router.events.off('routeChangeError', nprogressDone)
}
}, [router.asPath, props?.apollo])
}, [router.asPath, props?.apollo, pathname])

useEffect(() => {
// hack to disable ios pwa prompt for https://github.com/stackernews/stacker.news/issues/953
Expand Down
Loading