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(next-app-router): hydration error breaks routing #6542

Merged
merged 1 commit into from
Jan 23, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,21 @@ export function useInstantSearchRouting<
const routingRef =
useRef<InstantSearchProps<TUiState, TRouteState>['routing']>(null);
const onUpdateRef = useRef<() => void>(null);
const isUnmounting = useRef(false);

useEffect(() => {
if (onUpdateRef.current) {
onUpdateRef.current();
}
}, [pathname, searchParams]);

useEffect(() => {
isUnmounting.current = false;
return () => {
isUnmounting.current = true;
};
});

const headers = useNextHeaders();

if (passedRouting && !routingRef.current) {
Expand All @@ -54,7 +63,7 @@ export function useInstantSearchRouting<
url
) {
// This is to skip the push with empty routeState on dispose as it would clear params set on a <Link>
if (this.isDisposed) {
if (this.isDisposed && isUnmounting.current) {
return;
}
history.pushState({}, '', url);
Expand Down
Loading