@@ -10,6 +10,7 @@ import { platform } from 'platforms'
10
10
import * as React from 'react'
11
11
import { IIFC } from 'react-iifc'
12
12
import { useWindowSize } from 'react-use'
13
+ import { Config } from 'utils/config/helper'
13
14
import { cx } from 'utils/cx'
14
15
import * as DOMHelper from 'utils/DOMHelper'
15
16
import * as features from 'utils/features'
@@ -179,15 +180,20 @@ function useUpdateBodyIndentOnStateUpdate(shouldExpand: boolean) {
179
180
} , [ sidebarToggleMode , shouldExpand ] )
180
181
}
181
182
183
+ const getDerivedExpansion = ( {
184
+ intelligentToggle,
185
+ sidebarToggleMode,
186
+ } : Pick < Config , 'intelligentToggle' | 'sidebarToggleMode' > ) =>
187
+ sidebarToggleMode === 'persistent'
188
+ ? intelligentToggle === null // auto-expand checked
189
+ ? platform . shouldExpandSideBar ( )
190
+ : intelligentToggle // read saved expand state
191
+ : false // do not expand in float mode
192
+
182
193
function useGetDerivedExpansion ( ) {
183
194
const { intelligentToggle, sidebarToggleMode } = useConfigs ( ) . value
184
195
return React . useCallback (
185
- ( ) =>
186
- sidebarToggleMode === 'persistent'
187
- ? intelligentToggle === null // auto-expand checked
188
- ? platform . shouldExpandSideBar ( )
189
- : intelligentToggle // read saved expand state
190
- : false , // do not expand in float mode
196
+ ( ) => getDerivedExpansion ( { intelligentToggle, sidebarToggleMode } ) ,
191
197
[ intelligentToggle , sidebarToggleMode ] ,
192
198
)
193
199
}
@@ -197,8 +203,12 @@ function useUpdateBodyIndentOnPJAXDone(update: (shouldExpand: boolean) => void)
197
203
useOnPJAXDone (
198
204
React . useCallback ( ( ) => {
199
205
// check and update expand state if pinned and auto-expand checked
200
- if ( sidebarToggleMode === 'persistent' && intelligentToggle === null )
201
- update ( platform . shouldExpandSideBar ( ) )
206
+ if ( sidebarToggleMode === 'persistent' ) {
207
+ const shouldExpand = getDerivedExpansion ( { intelligentToggle, sidebarToggleMode } )
208
+ update ( shouldExpand )
209
+ // Below DOM mutation cannot be omitted, if do, body indent may get lost when shouldExpand is true for both before & after redirecting
210
+ DOMHelper . setBodyIndent ( shouldExpand )
211
+ }
202
212
} , [ update , sidebarToggleMode , intelligentToggle ] ) ,
203
213
)
204
214
}
0 commit comments