Skip to content

Commit 152076a

Browse files
Fix breakpoint mismatch and stabilize copyToClipboard reference
- Change BREAKPOINTS.md from 800 to 768 to match Tailwind CSS v4's default md breakpoint, fixing the 768-799px gap where the sidebar trigger was hidden but the sidebar was in mobile sheet mode. - Wrap copyToClipboard in useCallback with refs for onCopy/onError/timeout so the returned function identity is stable across renders, preventing unnecessary re-creation of downstream useCallback hooks. Co-authored-by: Julius Marminge <[email protected]>
1 parent bf7e673 commit 152076a

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

apps/web/src/hooks/useCopyToClipboard.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,15 @@ export function useCopyToClipboard<TContext = void>({
1111
} = {}): { copyToClipboard: (value: string, ctx: TContext) => void; isCopied: boolean } {
1212
const [isCopied, setIsCopied] = React.useState(false);
1313
const timeoutIdRef = React.useRef<NodeJS.Timeout | null>(null);
14+
const onCopyRef = React.useRef(onCopy);
15+
const onErrorRef = React.useRef(onError);
16+
const timeoutRef = React.useRef(timeout);
1417

15-
const copyToClipboard = (value: string, ctx: TContext): void => {
18+
onCopyRef.current = onCopy;
19+
onErrorRef.current = onError;
20+
timeoutRef.current = timeout;
21+
22+
const copyToClipboard = React.useCallback((value: string, ctx: TContext): void => {
1623
if (typeof window === "undefined" || !navigator.clipboard?.writeText) {
1724
return;
1825
}
@@ -26,26 +33,24 @@ export function useCopyToClipboard<TContext = void>({
2633
}
2734
setIsCopied(true);
2835

29-
if (onCopy) {
30-
onCopy(ctx);
31-
}
36+
onCopyRef.current?.(ctx);
3237

33-
if (timeout !== 0) {
38+
if (timeoutRef.current !== 0) {
3439
timeoutIdRef.current = setTimeout(() => {
3540
setIsCopied(false);
3641
timeoutIdRef.current = null;
37-
}, timeout);
42+
}, timeoutRef.current);
3843
}
3944
},
4045
(error) => {
41-
if (onError) {
42-
onError(error, ctx);
46+
if (onErrorRef.current) {
47+
onErrorRef.current(error, ctx);
4348
} else {
4449
console.error(error);
4550
}
4651
},
4752
);
48-
};
53+
}, []);
4954

5055
// Cleanup timeout on unmount
5156
React.useEffect(() => {

apps/web/src/hooks/useMediaQuery.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const BREAKPOINTS = {
55
"3xl": 1600,
66
"4xl": 2000,
77
lg: 1024,
8-
md: 800,
8+
md: 768,
99
sm: 640,
1010
xl: 1280,
1111
} as const;

0 commit comments

Comments
 (0)