Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevent redundant patching of History API methods #18

Merged
merged 2 commits into from
Feb 26, 2024

Conversation

tomcru
Copy link
Owner

@tomcru tomcru commented Feb 26, 2024

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: TheSGJ/nextjs-toploader#68

Furthermore, this increases support for router.push.

Reference: TheSGJ/nextjs-toploader#71

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: TheSGJ/nextjs-toploader#68
@tomcru tomcru merged commit 564d2fc into main Feb 26, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant