diff --git a/src/AppProgressBar.tsx b/src/AppProgressBar.tsx index 0496af5..9c782ae 100644 --- a/src/AppProgressBar.tsx +++ b/src/AppProgressBar.tsx @@ -1,8 +1,8 @@ -import React, { useEffect } from 'react'; +import { NavigateOptions } from 'next/dist/shared/lib/app-router-context.shared-runtime'; +import { useRouter as useNextRouter, usePathname, useSearchParams } from 'next/navigation'; import NProgress from 'nprogress'; -import { usePathname, useSearchParams, useRouter as useNextRouter } from 'next/navigation'; +import React, { useEffect } from 'react'; import { Next13ProgressProps } from '.'; -import { NavigateOptions } from 'next/dist/shared/lib/app-router-context.shared-runtime'; type PushStateInput = [data: any, unused: string, url?: string | URL | null | undefined]; @@ -150,16 +150,19 @@ export const Next13ProgressBar = React.memo( const mutationObserver = new MutationObserver(handleMutation); mutationObserver.observe(document, { childList: true, subtree: true }); - const proxyStateChange = new Proxy(window.history.pushState, { - apply: (target, thisArg, argArray: PushStateInput) => { - stopProgress(); - return target.apply(thisArg, argArray); - }, - }); + const makeStopProxy = (proxyTarget: any) => { + return new Proxy(proxyTarget, { + apply: (target, thisArg, argArray: PushStateInput) => { + stopProgress(); + return target.apply(thisArg, argArray); + }, + }); + }; + + window.history.pushState = makeStopProxy(window.history.pushState); + + window.history.replaceState = makeStopProxy(window.history.replaceState); - window.history.pushState = proxyStateChange; - window.history.replaceState = proxyStateChange; - }, []); return styles;