Skip to content

Commit 8c92b79

Browse files
committed
fix: #14
1 parent af730a0 commit 8c92b79

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/index.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)