@@ -17,14 +17,20 @@ const windowSizes = {
17
17
18
18
type WindowSize = keyof typeof windowSizes ;
19
19
20
- function getWindowSize ( desktopThresholdWidth : number ) : WindowSize {
20
+ // Note: this value is also hardcoded in Infima
21
+ // Both JS and CSS must have the same value
22
+ // Updating this JS value alone is not enough
23
+ // See https://github.com/facebook/docusaurus/issues/9603
24
+ const DesktopBreakpoint = 996 ;
25
+
26
+ function getWindowSize ( desktopBreakpoint : number ) : WindowSize {
21
27
if ( ! ExecutionEnvironment . canUseDOM ) {
22
28
throw new Error (
23
29
'getWindowSize() should only be called after React hydration' ,
24
30
) ;
25
31
}
26
32
27
- return window . innerWidth > desktopThresholdWidth
33
+ return window . innerWidth > desktopBreakpoint
28
34
? windowSizes . desktop
29
35
: windowSizes . mobile ;
30
36
}
@@ -40,9 +46,9 @@ function getWindowSize(desktopThresholdWidth: number): WindowSize {
40
46
* explicit.
41
47
*/
42
48
export function useWindowSize ( {
43
- desktopThresholdWidth = 996 ,
49
+ desktopBreakpoint = DesktopBreakpoint ,
44
50
} : {
45
- desktopThresholdWidth ?: number ;
51
+ desktopBreakpoint ?: number ;
46
52
} = { } ) : WindowSize {
47
53
const [ windowSize , setWindowSize ] = useState < WindowSize > (
48
54
( ) =>
@@ -53,7 +59,7 @@ export function useWindowSize({
53
59
54
60
useEffect ( ( ) => {
55
61
function updateWindowSize ( ) {
56
- setWindowSize ( getWindowSize ( { desktopThresholdWidth } ) ) ;
62
+ setWindowSize ( getWindowSize ( desktopBreakpoint ) ) ;
57
63
}
58
64
59
65
updateWindowSize ( ) ;
@@ -63,7 +69,7 @@ export function useWindowSize({
63
69
return ( ) => {
64
70
window . removeEventListener ( 'resize' , updateWindowSize ) ;
65
71
} ;
66
- } , [ desktopThresholdWidth ] ) ;
72
+ } , [ desktopBreakpoint ] ) ;
67
73
68
74
return windowSize ;
69
75
}
0 commit comments