File tree Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -129,15 +129,22 @@ const HolyLoader = ({
129129 } ;
130130
131131 /**
132- * Overrides the history. pushState function to stop the progress bar
133- * when navigating to a new page without a full page reload.
132+ * Enhances browser history methods ( pushState and replaceState) to ensure that the
133+ * progress indicator is appropriately halted when navigating through single- page applications
134134 */
135- const overridePushState = ( ) : void => {
135+ const stopProgressOnHistoryUpdate = ( ) : void => {
136136 const originalPushState = history . pushState . bind ( history ) ;
137137 history . pushState = ( ...args ) => {
138138 stopProgress ( ) ;
139139 originalPushState ( ...args ) ;
140140 } ;
141+
142+ // This is crucial for Next.js Link components using the 'replace' prop.
143+ const originalReplaceState = history . replaceState . bind ( history ) ;
144+ history . replaceState = ( ...args ) => {
145+ stopProgress ( ) ;
146+ originalReplaceState ( ...args ) ;
147+ } ;
141148 } ;
142149
143150 /**
@@ -166,7 +173,7 @@ const HolyLoader = ({
166173 }
167174
168175 startProgress ( ) ;
169- overridePushState ( ) ;
176+ stopProgressOnHistoryUpdate ( ) ;
170177 } catch ( error ) {
171178 stopProgress ( ) ;
172179 }
You can’t perform that action at this time.
0 commit comments