Skip to content
Merged
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
27 changes: 15 additions & 12 deletions src/AppProgressBar.tsx
Original file line number Diff line number Diff line change
@@ -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];

Expand Down Expand Up @@ -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;
Expand Down