mirror of
https://github.com/stack-auth/stack.git
synced 2026-06-04 21:04:37 +08:00
fix(dashboard-ui): guard Web APIs in animated pill/tab indicators
DesignPillToggle and DesignCategoryTabs called window.matchMedia and new ResizeObserver unconditionally, which throws in environments without those Web APIs (e.g. JSDOM tests, older browsers). Guard both before use; the one-shot updateSliderMetrics still runs so layout stays correct. (CodeRabbit)
This commit is contained in:
parent
9dfab510dc
commit
abd2e6a3b7
@ -94,6 +94,7 @@ export function DesignPillToggle({
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (typeof window === "undefined" || typeof window.matchMedia !== "function") return;
|
||||
const mediaQuery = window.matchMedia("(prefers-reduced-motion: reduce)");
|
||||
const updatePrefersReducedMotion = () => setPrefersReducedMotion(mediaQuery.matches);
|
||||
|
||||
@ -121,6 +122,7 @@ export function DesignPillToggle({
|
||||
|
||||
updateSliderMetrics();
|
||||
|
||||
if (typeof ResizeObserver === "undefined") return;
|
||||
const resizeObserver = new ResizeObserver(updateSliderMetrics);
|
||||
resizeObserver.observe(toggle);
|
||||
resizeObserver.observe(selectedButton);
|
||||
|
||||
@ -142,6 +142,7 @@ export function DesignCategoryTabs({
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (typeof window === "undefined" || typeof window.matchMedia !== "function") return;
|
||||
const mediaQuery = window.matchMedia("(prefers-reduced-motion: reduce)");
|
||||
const updatePrefersReducedMotion = () => setPrefersReducedMotion(mediaQuery.matches);
|
||||
|
||||
@ -169,6 +170,7 @@ export function DesignCategoryTabs({
|
||||
|
||||
updateSliderMetrics();
|
||||
|
||||
if (typeof ResizeObserver === "undefined") return;
|
||||
const resizeObserver = new ResizeObserver(updateSliderMetrics);
|
||||
resizeObserver.observe(tabList);
|
||||
resizeObserver.observe(selectedButton);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user