mirror of
https://github.com/stack-auth/stack.git
synced 2026-06-04 21:04:37 +08:00
Fix browser compatibility: guard requestIdleCallback and startViewTransition (#1464)
This commit is contained in:
parent
b8fc04bdbd
commit
3b2e991c78
@ -22,6 +22,11 @@ export default function ThemeToggle() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof document.startViewTransition !== "function") {
|
||||
setTheme(nextTheme);
|
||||
return;
|
||||
}
|
||||
|
||||
document.documentElement.classList.add("vt-disable-transitions");
|
||||
|
||||
const transition = document.startViewTransition(() => {
|
||||
|
||||
@ -5,10 +5,15 @@ export function useWaitForIdle(min = 0, max = 5000) {
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
setTimeout(() => {
|
||||
requestIdleCallback(() => {
|
||||
const cb = () => {
|
||||
if (cancelled) return;
|
||||
setHasWaited(true);
|
||||
}, { timeout: max - min });
|
||||
};
|
||||
if (typeof requestIdleCallback === "function") {
|
||||
requestIdleCallback(cb, { timeout: max - min });
|
||||
} else {
|
||||
setTimeout(cb, max - min);
|
||||
}
|
||||
}, min);
|
||||
return () => {
|
||||
cancelled = true;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user