Skip to content

Commit ddfa20f

Browse files
committed
fix: stabilize SidebarMenuSkeleton random width across re-renders
Use useState initializer instead of plain expression for Math.random() to ensure the skeleton width remains stable for the component lifetime. The React Compiler does not memoize impure functions like Math.random(), causing visible flickering on re-renders.
1 parent 62559a1 commit ddfa20f

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

apps/web/src/components/ui/sidebar.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -889,8 +889,8 @@ function SidebarMenuSkeleton({
889889
}: React.ComponentProps<"div"> & {
890890
showIcon?: boolean;
891891
}) {
892-
// Random width between 50 to 90%.
893-
const width = `${Math.floor(Math.random() * 40) + 50}%`;
892+
// Random width between 50 to 90%, stable across re-renders.
893+
const [width] = React.useState(() => `${Math.floor(Math.random() * 40) + 50}%`);
894894

895895
return (
896896
<div

0 commit comments

Comments
 (0)