tomcru / holy-loader

Holy Loader is a lightweight, customizable top loading progress bar component for React / Next.js 13 & Next.js 14. #toploader #top-loader #nextjs-toploader #nprogress #nextjs-progressbar
https://www.npmjs.com/package/holy-loader
MIT License
74 stars 4 forks source link

fix: prevent redundant patching of History API methods #18

Closed tomcru closed 6 months ago

tomcru commented 6 months ago

The previous implementation of patching the History API methods (pushState and replaceState) was causing them to increasingly nest within patched versions of themselves.

To fix this, a new flag isHistoryPatched was introduced to prevent redundant patching. The stopProgressOnHistoryUpdate function now checks if the flag is already set before applying the patch. Additionally, the flag is set to true after the patching is done to ensure it is only applied once.

Reference: https://github.com/TheSGJ/nextjs-toploader/pull/68

Furthermore, this increases support for router.push.

Reference: https://github.com/TheSGJ/nextjs-toploader/issues/71