fix(web): memoize useNavigateTo to prevent infinite view transition loop
Wrapping the returned function in useCallback prevents a new reference on every render, which was causing an infinite startViewTransition loop on the initial signup page (fresh install with no admin). Fixes #5626
This commit is contained in:
parent
6eaab52e48
commit
2ab476ef2e
1 changed files with 13 additions and 9 deletions
|
|
@ -1,18 +1,22 @@
|
||||||
|
import { useCallback } from "react";
|
||||||
import { NavigateOptions, useNavigate } from "react-router-dom";
|
import { NavigateOptions, useNavigate } from "react-router-dom";
|
||||||
|
|
||||||
const useNavigateTo = () => {
|
const useNavigateTo = () => {
|
||||||
const navigateTo = useNavigate();
|
const navigateTo = useNavigate();
|
||||||
|
|
||||||
const navigateToWithViewTransition = (to: string, options?: NavigateOptions) => {
|
const navigateToWithViewTransition = useCallback(
|
||||||
const doc = window.document as unknown as Document & { startViewTransition?: (callback: () => void) => void };
|
(to: string, options?: NavigateOptions) => {
|
||||||
if (!doc.startViewTransition) {
|
const doc = window.document as unknown as Document & { startViewTransition?: (callback: () => void) => void };
|
||||||
navigateTo(to, options);
|
if (!doc.startViewTransition) {
|
||||||
} else {
|
|
||||||
document.startViewTransition(() => {
|
|
||||||
navigateTo(to, options);
|
navigateTo(to, options);
|
||||||
});
|
} else {
|
||||||
}
|
document.startViewTransition(() => {
|
||||||
};
|
navigateTo(to, options);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[navigateTo],
|
||||||
|
);
|
||||||
|
|
||||||
return navigateToWithViewTransition;
|
return navigateToWithViewTransition;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue